Skip to content

Commit

Permalink
Add tests for running multiple calculated values and fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
baluyotraf committed May 21, 2024
1 parent 383b7a7 commit bf2af93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/altqq/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
QUERY_ATTRIB = "__query__"


class Calculated:
class _Calculated:
"""Marker class for calculated values."""


# Typehint the class marker to Any to avoid conflict with the type checkers
Calculated: Any = _Calculated


@dataclass_transform()
class QueryMeta(type):
"""Metaclass for generating Query objects that the library supports.
Expand Down
29 changes: 29 additions & 0 deletions tests/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ def mysql(self) -> altqq.MySQLQuery:
)


class SelectWithCalculated(altqq.Query):
"""Tests queries that uses multiple calculated values."""

__query__ = """
SELECT * FROM Table WHERE A = {param} AND B = {calc1} AND C = {calc2}
"""

param: int
calc1: int = altqq.Calculated
calc2: int = altqq.Calculated

def __post_init__(self):
"""Initialize calculated parameters."""
self.calc1 = 20
self.calc2 = 30


class SelectTableByFilter(altqq.Query):
"""Test query that selects and filters a table."""

Expand Down Expand Up @@ -63,6 +80,18 @@ class UnionAllQuery(altqq.Query):


TEST_DATA = [
SampleQuery(
SelectWithCalculated(10),
pyodbc=altqq.PyODBCQuery(
query="""SELECT * FROM Table WHERE A = ? AND B = ? AND C = ?""",
parameters=[10, 20, 30],
),
psycopg=altqq.PsycopgQuery(
query="""SELECT * FROM Table WHERE A = %s AND B = %s AND C = %s""",
parameters=(10, 20, 30),
),
plain_text="""SELECT * FROM Table WHERE A = 10 AND B = 20 AND C = 30""",
),
SampleQuery(
SelectTableByFilter("Users", "age", 25),
pyodbc=altqq.PyODBCQuery(
Expand Down

0 comments on commit bf2af93

Please sign in to comment.