Skip to content

Commit

Permalink
Do use vanilly query without numpy types
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schmidt committed Jan 24, 2024
1 parent 8baa425 commit a143135
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 58 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
Expand All @@ -17,6 +16,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.5.4]
**Full Changelog**: https://github.com/DeepLcom/sql-mock/compare/v0.5.3...v0.5.4

### Added

### Changed

* Clickhouse: Remove numpy dependency

### Fixed

## [0.5.3]
**Full Changelog**: https://github.com/DeepLcom/sql-mock/compare/v0.5.2...v0.5.3

Expand Down Expand Up @@ -114,7 +124,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.1.2] - 2023-10-26
Initial version.

[Unreleased]: https://github.com/DeepLcom/sql-mock/compare/v0.5.3...HEAD
[Unreleased]: https://github.com/DeepLcom/sql-mock/compare/v0.5.4...HEAD
[0.5.4]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.5.4
[0.5.3]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.5.3
[0.5.2]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.5.2
[0.5.1]: https://github.com/DeepLcom/sql-mock/releases/tag/v0.5.1
Expand Down
49 changes: 2 additions & 47 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "sql-mock"
version = "0.5.3"
version = "0.5.4"
description = "Simplify the testing of SQL data models and queries by allowing users to mock input data and create tests for various scenarios. It provides a consistent and convenient way to test the execution of your query without the need to process a massive amount of data."
repository = "https://github.com/DeepLcom/sql-mock"
readme = "README.md"
Expand Down Expand Up @@ -44,7 +44,6 @@ sqlglot = "^20.5.0"

# Clickhouse specific
clickhouse-connect = {version = "^0.7.0", optional = true}
numpy = {version = "^1.26.3", optional = true}

# Google Bigquery specific
google-cloud-bigquery = {version ="^3.11.4", optional = true}
Expand All @@ -58,7 +57,7 @@ snowflake-connector-python = "^3.6.0"

[tool.poetry.extras]
bigquery = ["google-cloud-bigquery"]
clickhouse = ["clickhouse-connect", "numpy"]
clickhouse = ["clickhouse-connect"]
redshift = ["redshift-connector", "boto3"]
snowflake = ["snowflake-connector-python"]

Expand Down
4 changes: 2 additions & 2 deletions src/sql_mock/clickhouse/table_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def _get_results(self, query: str) -> list[dict]:
password=self.settings.password,
port=self.settings.port,
) as client:
res = client.query_df(query)
return res.to_dict("records")
res = client.query(query, use_none=True)
return [dict(zip(res.column_names, row)) for row in res.result_rows]
9 changes: 5 additions & 4 deletions tests/sql_mock/clickhouse/test_table_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ def test_get_results(mocker):
mock_query_result = [{"column1": "value1", "column2": 42}]
query = "SELECT 1, 2"

mock_dataframe = mocker.MagicMock()
mock_dataframe.to_dict.return_value = mock_query_result
mock_client.return_value.__enter__.return_value.query_df.return_value = mock_dataframe
mock_result = mocker.MagicMock()
mock_result.result_rows = [("value1", 42)]
mock_result.column_names = ("column1", "column2")
mock_client.return_value.__enter__.return_value.query.return_value = mock_result

instance = ClickHouseTableMock()
result = instance._get_results(query=query)

assert result == mock_query_result
mock_client.return_value.__enter__.return_value.query_df.assert_called_once_with(query)
mock_client.return_value.__enter__.return_value.query.assert_called_once_with(query)

0 comments on commit a143135

Please sign in to comment.