Skip to content

Commit

Permalink
Remove unnecessary print statement leading to test failures
Browse files Browse the repository at this point in the history
Closes #53
  • Loading branch information
smoothml committed Apr 17, 2024
1 parent 9e6c1ef commit 799dca4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* Remove unnecessary `print` statement leading to test failures

## [0.6.1]

**Full Changelog**: <https://github.com/DeepLcom/sql-mock/compare/v0.6.0...v0.6.1>
Expand Down
1 change: 0 additions & 1 deletion src/sql_mock/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def replace_original_table_references(
query_ast = _replace_table_ref_in_columns(
query_ast=query_ast, table_ref=table_ref, new_ref=sql_mock_cte_name, dialect=dialect
)
print(query_ast.sql(pretty=True))
return replace_tables(expression=query_ast, mapping={table_ref: sql_mock_cte_name}, dialect=dialect)


Expand Down
74 changes: 74 additions & 0 deletions tests/sql_mock/clickhouse/test_query_execution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from datetime import datetime

import pytest

Expand Down Expand Up @@ -55,3 +56,76 @@ class ResultMock(ClickHouseTableMock):
]

result.assert_equal(expected)


def test_argmaxif():
query = """SELECT
user_id,
count() AS num_sessions,
countIf(valid = 1) AS num_valid_sessions,
argMaxIf(in_trial, dt, isNotNull(in_trial)) AS in_trial
FROM sessions
GROUP BY user_id
"""

@table_meta(table_ref="sessions")
class SessionsMock(ClickHouseTableMock):
dt = col.Datetime(default=datetime(2024, 1, 1, 10, 30))
valid = col.Boolean(default=True)
user_id = col.String(default="foo")
in_trial = col.Int(default=0, nullable=True)

@table_meta(query=query)
class ResultMock(ClickHouseTableMock):
user_id = col.String(default="foo")
num_sessions = col.Int(default=0)
num_valid_sessions = col.Int(default=0)
in_trial = col.Int(default=0)

sessions_mock = SessionsMock.from_dicts(
[
dict(
dt=datetime(2024, 1, 1, 10),
valid=1,
user_id="foo",
in_trial=1,
),
dict(
dt=datetime(2024, 1, 2, 10),
valid=0,
user_id="foo",
in_trial=1,
),
dict(
dt=datetime(2024, 1, 3, 10),
valid=1,
user_id="foo",
in_trial=1,
),
dict(
dt=datetime(2024, 1, 4, 10),
valid=1,
user_id="foo",
in_trial=None,
),
dict(
dt=datetime(2024, 1, 5, 10),
valid=1,
user_id="foo",
in_trial=0,
),
]
)

result = ResultMock.from_mocks(input_data=[sessions_mock])

expected = [
dict(
user_id="foo",
num_sessions=5,
num_valid_sessions=4,
in_trial=0,
)
]

result.assert_equal(expected)

0 comments on commit 799dca4

Please sign in to comment.