Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Jun 14, 2024
1 parent 881779a commit ba12932
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion datacontract/data_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions datacontract/imports/bigquery_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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"

1 change: 1 addition & 0 deletions tests/test_import_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
20 changes: 6 additions & 14 deletions tests/test_roundtrip_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

logging.basicConfig(level=logging.DEBUG, force=True)


def test_import_cli():
runner = CliRunner()
result = runner.invoke(
Expand All @@ -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
Expand Down

0 comments on commit ba12932

Please sign in to comment.