From ba12932e3d30fb4e1cb451eee146c6616a921671 Mon Sep 17 00:00:00 2001 From: Simon Harrer Date: Fri, 14 Jun 2024 09:43:49 +0200 Subject: [PATCH] Fix build --- datacontract/data_contract.py | 2 +- datacontract/imports/bigquery_importer.py | 6 ++++-- tests/test_import_bigquery.py | 1 + tests/test_roundtrip_jsonschema.py | 20 ++++++-------------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/datacontract/data_contract.py b/datacontract/data_contract.py index c22e8da8..95877466 100644 --- a/datacontract/data_contract.py +++ b/datacontract/data_contract.py @@ -208,7 +208,7 @@ def test(self) -> Run: if self._examples: server_name = "examples" server = self._get_examples_server(data_contract, run, tmp_dir) - if self._server: + elif self._server: server_name = self._server server = data_contract.servers.get(server_name) else: diff --git a/datacontract/imports/bigquery_importer.py b/datacontract/imports/bigquery_importer.py index 51634209..4aafdf98 100644 --- a/datacontract/imports/bigquery_importer.py +++ b/datacontract/imports/bigquery_importer.py @@ -95,7 +95,9 @@ def convert_bigquery_schema( # what exactly leads to friendlyName being set table_id = bigquery_schema.get("tableReference").get("tableId") - data_contract_specification.models[table_id] = Model(fields=fields, type=map_bigquery_type(bigquery_schema.get("type"))) + data_contract_specification.models[table_id] = Model( + fields=fields, type=map_bigquery_type(bigquery_schema.get("type")) + ) # Copy the description, if it exists if bigquery_schema.get("description") is not None: @@ -188,6 +190,7 @@ def map_type_from_bigquery(bigquery_type_str: str): engine="datacontract", ) + def map_bigquery_type(bigquery_type: str) -> str: if bigquery_type == "TABLE" or bigquery_type == "EXTERNAL" or bigquery_type == "SNAPSHOT": return "table" @@ -199,4 +202,3 @@ def map_bigquery_type(bigquery_type: str) -> str: f"Can't properly map bigquery table type '{bigquery_type}' to datacontracts model types. Mapping it to table." ) return "table" - \ No newline at end of file diff --git a/tests/test_import_bigquery.py b/tests/test_import_bigquery.py index 8e317106..da27a3cb 100644 --- a/tests/test_import_bigquery.py +++ b/tests/test_import_bigquery.py @@ -34,6 +34,7 @@ def test_import_bigquery_schema(): assert yaml.safe_load(result.to_yaml()) == yaml.safe_load(expected) assert DataContract(data_contract_str=expected).lint(enabled_linters="none").has_passed() + def test_import_multiple_bigquery_schemas_with_different_types(): result = DataContract().import_from_source("bigquery", "fixtures/bigquery/import/multi_import_table.json") diff --git a/tests/test_roundtrip_jsonschema.py b/tests/test_roundtrip_jsonschema.py index 9d9b9c79..7cf3f8a5 100644 --- a/tests/test_roundtrip_jsonschema.py +++ b/tests/test_roundtrip_jsonschema.py @@ -7,6 +7,7 @@ logging.basicConfig(level=logging.DEBUG, force=True) + def test_import_cli(): runner = CliRunner() result = runner.invoke( @@ -21,29 +22,20 @@ def test_import_cli(): ) assert result.exit_code == 0 + def test_export_cli(): runner = CliRunner() - result = runner.invoke( - app, - [ - "export", - "./fixtures/local-json/datacontract.yaml", - "--format", - "jsonschema" - ] - ) + result = runner.invoke(app, ["export", "./fixtures/local-json/datacontract.yaml", "--format", "jsonschema"]) assert result.exit_code == 0 + def test_roundtrip_json_schema_orders(): # Import the data contract from the JSON schema source - result_import = DataContract().import_from_source( - "jsonschema", "fixtures/import/orders.json" - ) + result_import = DataContract().import_from_source("jsonschema", "fixtures/import/orders.json") # Create a data contract specification with inline definitions data_contract = DataContract( - data_contract_str=result_import.to_yaml(), - inline_definitions=True + data_contract_str=result_import.to_yaml(), inline_definitions=True ).get_data_contract_specification() # Load the expected result from the JSON file