diff --git a/tests/test_targets.py b/tests/test_targets.py index 1e07c1cc..5412b91c 100644 --- a/tests/test_targets.py +++ b/tests/test_targets.py @@ -13,8 +13,10 @@ # limitations under the License. from typing import Optional +from unittest.mock import Mock import pytest +import taosws from storey.dtypes import TDEngineValueError from storey.targets import TDEngineTarget @@ -63,3 +65,42 @@ def test_invalid_names( table=table, supertable=supertable, ) + + @staticmethod + @pytest.fixture + def tdengine_target() -> TDEngineTarget: + target = TDEngineTarget( + url="taosws://root:taosdata@localhost:6041", + time_col="ts", + columns=["value"], + database="test", + table="d6241", + ) + + target._connection = Mock() + # The following test schema is obtained from the `taosBenchmark` data: + # https://docs.tdengine.com/get-started/docker/#test-data-insert-performance + # list(conn.query("describe test.d6241;")) + target._connection.query = Mock( + return_value=[ + ("ts", "TIMESTAMP", 8, "", "delta-i", "lz4", "medium"), + ("current", "FLOAT", 4, "", "delta-d", "lz4", "medium"), + ("voltage", "INT", 4, "", "simple8b", "lz4", "medium"), + ("phase", "FLOAT", 4, "", "delta-d", "lz4", "medium"), + ("groupid", "INT", 4, "TAG", "disabled", "disabled", "disabled"), + ("location", "VARCHAR", 24, "TAG", "disabled", "disabled", "disabled"), + ], + ) + return target + + @staticmethod + def test_get_table_schema(tdengine_target: TDEngineTarget) -> None: + """Test that the parsing works""" + tags_schema, reg_cols_schema = tdengine_target._get_table_schema("d6241") + assert tags_schema == [("groupid", taosws.int_to_tag), ("location", taosws.varchar_to_tag)] + assert reg_cols_schema == [ + ("ts", taosws.millis_timestamps_to_column), + ("current", taosws.floats_to_column), + ("voltage", taosws.ints_to_column), + ("phase", taosws.floats_to_column), + ] diff --git a/tests/test_types.py b/tests/test_types.py index b994bcf5..9248edba 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -21,7 +21,6 @@ EmitAfterWindow, EmitEveryEvent, _dict_to_emit_policy, - _TDEngineField, ) @@ -77,21 +76,3 @@ def test_emit_policy_period(): policy = _dict_to_emit_policy(policy_dict) assert type(policy) == EmitAfterPeriod assert policy.delay_in_seconds == 8 - - -@pytest.mark.parametrize( - "description", - [ - # taosBenchmark - # list(conn.query("describe test.d6241;")) - ("ts", "TIMESTAMP", 8, "", "delta-i", "lz4", "medium"), - ("current", "FLOAT", 4, "", "delta-d", "lz4", "medium"), - ("voltage", "INT", 4, "", "simple8b", "lz4", "medium"), - ("phase", "FLOAT", 4, "", "delta-d", "lz4", "medium"), - ("groupid", "INT", 4, "TAG", "disabled", "disabled", "disabled"), - ("location", "VARCHAR", 24, "TAG", "disabled", "disabled", "disabled"), - ], -) -def test_description_parsing_to_tdengine_field(description: tuple) -> None: - """Test that the parsing works""" - _TDEngineField(*description)