Skip to content

Commit

Permalink
Rewrite the test into test_get_table_schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jond01 committed Sep 17, 2024
1 parent dfce184 commit a4d55d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
41 changes: 41 additions & 0 deletions tests/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
]
19 changes: 0 additions & 19 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
EmitAfterWindow,
EmitEveryEvent,
_dict_to_emit_policy,
_TDEngineField,
)


Expand Down Expand Up @@ -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)

0 comments on commit a4d55d2

Please sign in to comment.