From 1fe580e450f6bc15816703565396c014dfb34667 Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 11:05:49 +0100 Subject: [PATCH 1/6] Testing inspect command for cube and code-list end-to-end. Fixing issue introduced in previous release where code-list inspect would fail. --- src/csvcubed/cli/inspect/inspect.py | 2 ++ tests/behaviour/cli.feature | 23 +++++++++++++++++++++-- tests/behaviour/steps/cli.py | 9 +++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/csvcubed/cli/inspect/inspect.py b/src/csvcubed/cli/inspect/inspect.py index c5af5fe15..df9c28cf9 100644 --- a/src/csvcubed/cli/inspect/inspect.py +++ b/src/csvcubed/cli/inspect/inspect.py @@ -92,6 +92,8 @@ def _generate_printables( catalog_metadata_printable: str = metadata_printer.catalog_metadata_printable column_component_info_printable: str = ( metadata_printer.column_component_info_printable + if csvw_type == CSVWType.QbDataSet + else "" ) codelist_info_printable: str = ( metadata_printer.codelist_info_printable diff --git a/tests/behaviour/cli.feature b/tests/behaviour/cli.feature index 9690b5a32..8fd4f4b91 100644 --- a/tests/behaviour/cli.feature +++ b/tests/behaviour/cli.feature @@ -17,7 +17,7 @@ Feature: Test the csvcubed Command Line Interface. And the file at "out/title-of-the-code-list.csv-metadata.json" should exist And the file at "out/title-of-the-code-list.table.json" should exist And the file at "out/validation-errors.json" should exist - And the csvcubed CLI should succeed + And the csvcubed build CLI should succeed And the validation-errors.json file should contain """ "offending_value": "http://purl.org/dc/aboutdcmi#DCMI" @@ -63,7 +63,7 @@ Feature: Test the csvcubed Command Line Interface. Then the file at "testout/title-of-the-code-list.csv" should exist And the file at "testout/title-of-the-code-list.csv-metadata.json" should exist And the file at "testout/title-of-the-code-list.table.json" should exist - And the csvcubed CLI should succeed + And the csvcubed build CLI should succeed Then remove test log files Scenario: The csvcubed code-list build command will fail when there is a validation error. @@ -71,3 +71,22 @@ Feature: Test the csvcubed Command Line Interface. When the csvcubed CLI is run with "code-list build readers/code-list-config/v1.0/code_list_config_produces_error.json --fail-when-validation-error" Then the csvcubed CLI should fail with status code 1 Then remove test log files + + Scenario: Test csvcubed inspect cube end-to-end + Given the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-bulletin.csv-metadata.json" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-bulletin.csv" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-content.table.json" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-sub-type.table.json" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/clearance-origin.table.json" + When the csvcubed CLI is run with "inspect cli/inspect/multi-unit_multi-measure/alcohol-bulletin.csv-metadata.json" + Then the csvcubed CLI should succeed + Then remove test log files + + + Scenario: Test csvcubed inspect code list end-to-end + Given the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-content.csv-metadata.json" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-content.table.json" + And the existing test-case file "cli/inspect/multi-unit_multi-measure/alcohol-content.csv" + When the csvcubed CLI is run with "inspect cli/inspect/multi-unit_multi-measure/alcohol-content.csv-metadata.json" + Then the csvcubed CLI should succeed + Then remove test log files diff --git a/tests/behaviour/steps/cli.py b/tests/behaviour/steps/cli.py index dee66bcc8..266cba4e4 100644 --- a/tests/behaviour/steps/cli.py +++ b/tests/behaviour/steps/cli.py @@ -23,13 +23,19 @@ def step_impl(context, arguments: str): context.csvcubed_log_location = Path(dirs.user_log_dir) -@then("the csvcubed CLI should succeed") +@then("the csvcubed build CLI should succeed") def step_impl(context): (status_code, response) = context.csvcubed_cli_result assert status_code == 0, (status_code, response) assert "Build Complete" in response, response +@then("the csvcubed CLI should succeed") +def step_impl(context): + (status_code, response) = context.csvcubed_cli_result + assert status_code == 0, (status_code, response) + + @then("the csvcubed CLI should fail with status code {status_code}") def step_impl(context, status_code: str): (status_code, _) = context.csvcubed_cli_result @@ -116,7 +122,6 @@ def run_command_in_temp_dir(context, command: str) -> Tuple[int, str]: stderr_path = Path(tmp_dir_path / "buffer" / "stderr") with open(stdout_path, "w") as stdout_file, open(stderr_path, "w") as stderr_file: - process = subprocess.Popen( command, shell=True, From 21eb78f6bddfeee984d48b2d526cc259a6c198c1 Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 11:37:47 +0100 Subject: [PATCH 2/6] Let's try and get some useful debug information back from test failures again. --- .github/workflows/reusable-test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/reusable-test.yaml b/.github/workflows/reusable-test.yaml index 912c4c16e..fae80b771 100644 --- a/.github/workflows/reusable-test.yaml +++ b/.github/workflows/reusable-test.yaml @@ -95,6 +95,7 @@ jobs: publish_test_results: needs: [test_in_environments] runs-on: ubuntu-latest + if: always() steps: - uses: actions/download-artifact@v3 with: From 5219111f8f5619a74edb1b825527f25fc0c0239a Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 12:09:37 +0100 Subject: [PATCH 3/6] Let's see whether this fixes our inspect CLI encoding problems on Windows. --- tests/behaviour/steps/cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/behaviour/steps/cli.py b/tests/behaviour/steps/cli.py index 266cba4e4..78103164e 100644 --- a/tests/behaviour/steps/cli.py +++ b/tests/behaviour/steps/cli.py @@ -6,6 +6,7 @@ import json import shutil import subprocess +import sys from pathlib import Path from typing import Tuple @@ -128,6 +129,8 @@ def run_command_in_temp_dir(context, command: str) -> Tuple[int, str]: cwd=tmp_dir_path.resolve(), stdout=stdout_file, stderr=stderr_file, + # Attempting to ensure that we get consistently formatted outputs on windows. + encoding="utf-8", ) status_code = process.wait() From 6501613fd6643feae51f0cbfa5053398bafe7ee9 Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 12:10:26 +0100 Subject: [PATCH 4/6] Removing unnecessary import. --- tests/behaviour/steps/cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/behaviour/steps/cli.py b/tests/behaviour/steps/cli.py index 78103164e..ea2135ea9 100644 --- a/tests/behaviour/steps/cli.py +++ b/tests/behaviour/steps/cli.py @@ -6,7 +6,6 @@ import json import shutil import subprocess -import sys from pathlib import Path from typing import Tuple From ef2f94970e0e5c1c4691da84df0aba85c5d226ff Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 12:31:11 +0100 Subject: [PATCH 5/6] Let's try UTF-16 then. --- tests/behaviour/steps/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/behaviour/steps/cli.py b/tests/behaviour/steps/cli.py index ea2135ea9..8bcb9d36b 100644 --- a/tests/behaviour/steps/cli.py +++ b/tests/behaviour/steps/cli.py @@ -114,7 +114,7 @@ def run_command_in_temp_dir(context, command: str) -> Tuple[int, str]: tmp_dir_path = get_context_temp_dir_path(context) # Use temp files not a PIPE, a PIPE has a tiny buffer than - # can deadlock or result in eroneous resource exhaustion behaviour + # can deadlock or result in erroneous resource exhaustion behaviour # where encountering some of our larger outputs (jsonSchemaErrors result # in large writes to stdout) Path(tmp_dir_path / "buffer").mkdir() @@ -129,7 +129,7 @@ def run_command_in_temp_dir(context, command: str) -> Tuple[int, str]: stdout=stdout_file, stderr=stderr_file, # Attempting to ensure that we get consistently formatted outputs on windows. - encoding="utf-8", + encoding="utf-16", ) status_code = process.wait() From 7fdbe58530e23ccc948b9b833e174c489d69d5ca Mon Sep 17 00:00:00 2001 From: Rob Barry Date: Mon, 3 Apr 2023 12:43:35 +0100 Subject: [PATCH 6/6] Let's see if we can tell the sub-process to use UTF-8. --- tests/behaviour/steps/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/behaviour/steps/cli.py b/tests/behaviour/steps/cli.py index 8bcb9d36b..b786616f2 100644 --- a/tests/behaviour/steps/cli.py +++ b/tests/behaviour/steps/cli.py @@ -4,6 +4,7 @@ The *Command Line Interface* containing the stepdefinitions for the behave tests. """ import json +import os import shutil import subprocess from pathlib import Path @@ -129,7 +130,11 @@ def run_command_in_temp_dir(context, command: str) -> Tuple[int, str]: stdout=stdout_file, stderr=stderr_file, # Attempting to ensure that we get consistently formatted outputs on windows. - encoding="utf-16", + env={ + **os.environ, + "PYTHONUTF8": "1", + }, + encoding="utf_8", ) status_code = process.wait()