Skip to content

Commit

Permalink
what is the point of those unit tests again ?
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>
  • Loading branch information
lukapeschke committed Sep 7, 2023
1 parent 84d9c03 commit a8e9b6a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, TypeVar

from pypika import functions
from pypika.dialects import QueryBuilder, SnowflakeQueryBuilder
from pypika.enums import Dialects
from pypika.queries import Query, Selectable
Expand Down Expand Up @@ -67,5 +68,9 @@ def _add_date(
date_part=unit.removesuffix("s"), interval=duration, term=target_column
)

@classmethod
def _interval_to_seconds(cls, value: Selectable) -> functions.Function:
raise NotImplementedError


SQLTranslator.register(SnowflakeTranslator)
4 changes: 4 additions & 0 deletions server/tests/backends/sql_translator_unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def _id(self) -> str:
DummyTranslator.known_instances[id(self)] = id_
return id_

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""

return DummyTranslator(
tables_columns={
"beers_tiny": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class BaseTranslator(SQLTranslator):
timestamp="TIMESTAMP",
)

@classmethod
def _interval_to_seconds(cls, value):
raise NotImplementedError


ALL_TABLES = {
"users": ["name", "pseudonyme", "age", "id", "project_id"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class DateFormatTranslator(SQLTranslator):
year="%Y",
)

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


ALL_TABLES = {"users": ["name", "pseudonyme", "age"]}
DB_SCHEMA = "test_schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class FilterTranslator(SQLTranslator):
DIALECT = "Filter"
QUERY_CLS = Query

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


ALL_TABLES = {"users": ["name", "pseudonyme", "age"]}
DB_SCHEMA = "test_schema"
Expand Down Expand Up @@ -148,6 +152,10 @@ class REGEXPTranslator(SQLTranslator):
REGEXP_OP = RegexOp.REGEXP
DATA_TYPE_MAPPING = _DATA_TYPE_MAPPING

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


@pytest.fixture
def regexp_translator():
Expand Down Expand Up @@ -208,6 +216,10 @@ class SimilarToTranslator(SQLTranslator):
REGEXP_OP = RegexOp.SIMILAR_TO
DATA_TYPE_MAPPING = _DATA_TYPE_MAPPING

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


@pytest.fixture
def similar_to_translator():
Expand Down Expand Up @@ -280,6 +292,10 @@ class ContainsTranslator(SQLTranslator):
REGEXP_OP = RegexOp.CONTAINS
DATA_TYPE_MAPPING = _DATA_TYPE_MAPPING

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


@pytest.fixture
def contains_translator():
Expand Down Expand Up @@ -351,6 +367,10 @@ class REGEXP_LIKE_Translator(SQLTranslator):
QUERY_CLS = Query
REGEXP_OP = RegexOp.REGEXP_LIKE

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


@pytest.fixture
def regexp_like_translator():
Expand Down Expand Up @@ -410,6 +430,10 @@ class REGEXP_CONTAINS_Translator(SQLTranslator):
QUERY_CLS = Query
REGEXP_OP = RegexOp.REGEXP_CONTAINS

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


@pytest.fixture
def regexp_contains_translator():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ class RowNumberEnabledTranslator(SQLTranslator):
QUERY_CLS = Query
SUPPORT_ROW_NUMBER = True

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


class RowNumberDisabledTranslator(SQLTranslator):
DIALECT = "Base"
QUERY_CLS = Query
SUPPORT_ROW_NUMBER = False

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


ALL_TABLES = {"users": ["name", "pseudonyme", "age"]}
DB_SCHEMA = "test_schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ class SplitEnabledTranslator(SQLTranslator):
QUERY_CLS = Query
SUPPORT_SPLIT_PART = True

@classmethod
def _interval_to_seconds(cls, value):
raise NotImplementedError


class SplitDisabledTranslator(SQLTranslator):
DIALECT = "Base"
QUERY_CLS = Query
SUPPORT_SPLIT_PART = False

@classmethod
def _interval_to_seconds(cls, value):
raise NotImplementedError


ALL_TABLES = {"users": ["name", "pseudonyme", "age"]}
DB_SCHEMA = "test_schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class MappingEnabledTranslator(SQLTranslator):
timestamp="TIMESTAMP",
)

@classmethod
def _interval_to_seconds(cls, value):
"""Converts an INTERVAL SQL type to a duration in seconds"""


ALL_TABLES = {"users": ["name", "pseudonyme", "age"]}
DB_SCHEMA = "test_schema"
Expand Down

0 comments on commit a8e9b6a

Please sign in to comment.