From 381ae3a3274df0ea9c3329db5dc52cd805f7d626 Mon Sep 17 00:00:00 2001 From: Dave Date: Sat, 13 Jan 2024 17:40:15 +0100 Subject: [PATCH] add missing tests and fix linting --- dlt/common/data_types/type_helpers.py | 2 +- tests/cases.py | 2 +- tests/common/schema/test_coercion.py | 10 ++++++++++ tests/load/weaviate/utils.py | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dlt/common/data_types/type_helpers.py b/dlt/common/data_types/type_helpers.py index d84821b217..9b26207cf1 100644 --- a/dlt/common/data_types/type_helpers.py +++ b/dlt/common/data_types/type_helpers.py @@ -110,7 +110,7 @@ def coerce_value(to_type: TDataType, from_type: TDataType, value: Any) -> Any: if from_type == "text": try: return json.loads(value) - except Exception as e: + except Exception: pass if to_type == "text": diff --git a/tests/cases.py b/tests/cases.py index a52d68b230..85caec4b8d 100644 --- a/tests/cases.py +++ b/tests/cases.py @@ -234,7 +234,7 @@ def assert_all_data_types_row( if expect_filtered_null_columns: for key, expected in expected_rows.items(): if expected is None: - assert db_mapping.get(key, None) == None + assert db_mapping.get(key, None) is None db_mapping[key] = None for key, expected in expected_rows.items(): diff --git a/tests/common/schema/test_coercion.py b/tests/common/schema/test_coercion.py index 922024a89b..34b62f9564 100644 --- a/tests/common/schema/test_coercion.py +++ b/tests/common/schema/test_coercion.py @@ -377,10 +377,16 @@ def test_coerce_type_complex() -> None: assert coerce_value("complex", "complex", v_list) == v_list assert coerce_value("text", "complex", v_dict) == json.dumps(v_dict) assert coerce_value("text", "complex", v_list) == json.dumps(v_list) + assert coerce_value("complex", "text", json.dumps(v_dict)) == v_dict + assert coerce_value("complex", "text", json.dumps(v_list)) == v_list + # all other coercions fail with pytest.raises(ValueError): coerce_value("binary", "complex", v_list) + with pytest.raises(ValueError): + coerce_value("complex", "text", "not a json string") + def test_coerce_type_complex_with_pua() -> None: v_dict = { @@ -395,6 +401,10 @@ def test_coerce_type_complex_with_pua() -> None: } assert coerce_value("complex", "complex", copy(v_dict)) == exp_v assert coerce_value("text", "complex", copy(v_dict)) == json.dumps(exp_v) + + # TODO: what to test for this case if at all? + # assert coerce_value("complex", "text", json.dumps(v_dict)) == exp_v + # also decode recursively custom_pua_decode_nested(v_dict) # restores datetime type diff --git a/tests/load/weaviate/utils.py b/tests/load/weaviate/utils.py index ed378191e6..1b2a74fcb8 100644 --- a/tests/load/weaviate/utils.py +++ b/tests/load/weaviate/utils.py @@ -79,6 +79,8 @@ def delete_classes(p, class_list): def drop_active_pipeline_data() -> None: def schema_has_classes(client): + if not hasattr(client, "db_client"): + return None schema = client.db_client.schema.get() return schema["classes"]