fakesnow 0.9.17__tar.gz → 0.9.18__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fakesnow-0.9.17 → fakesnow-0.9.18}/PKG-INFO +1 -1
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/fakes.py +1 -1
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/transforms.py +3 -1
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/PKG-INFO +1 -1
- {fakesnow-0.9.17 → fakesnow-0.9.18}/pyproject.toml +1 -1
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_fakes.py +19 -4
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_transforms.py +7 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/LICENSE +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/README.md +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/__init__.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/__main__.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/checks.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/cli.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/expr.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/fixtures.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/global_database.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/info_schema.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/macros.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow/py.typed +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/SOURCES.txt +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/dependency_links.txt +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/entry_points.txt +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/requires.txt +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/fakesnow.egg-info/top_level.txt +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/setup.cfg +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_checks.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_cli.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_expr.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_info_schema.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_patch.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_sqlalchemy.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_users.py +0 -0
- {fakesnow-0.9.17 → fakesnow-0.9.18}/tests/test_write_pandas.py +0 -0
@@ -611,7 +611,7 @@ class FakeSnowflakeConnection:
|
|
611
611
|
cursors = [
|
612
612
|
self.cursor(cursor_class).execute(e.sql(dialect="snowflake"))
|
613
613
|
for e in sqlglot.parse(sql_text, read="snowflake")
|
614
|
-
if e
|
614
|
+
if e and not isinstance(e, exp.Semicolon) # ignore comments
|
615
615
|
]
|
616
616
|
return cursors if return_cursors else []
|
617
617
|
|
@@ -119,9 +119,11 @@ def create_database(expression: exp.Expression, db_path: Path | None = None) ->
|
|
119
119
|
db_name = ident.this
|
120
120
|
db_file = f"{db_path/db_name}.db" if db_path else ":memory:"
|
121
121
|
|
122
|
+
if_not_exists = "IF NOT EXISTS " if expression.args.get("exists") else ""
|
123
|
+
|
122
124
|
return exp.Command(
|
123
125
|
this="ATTACH",
|
124
|
-
expression=exp.Literal(this=f"DATABASE '{db_file}' AS {db_name}", is_string=True),
|
126
|
+
expression=exp.Literal(this=f"{if_not_exists}DATABASE '{db_file}' AS {db_name}", is_string=True),
|
125
127
|
create_db_name=db_name,
|
126
128
|
)
|
127
129
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fakesnow"
|
3
3
|
description = "Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally."
|
4
|
-
version = "0.9.
|
4
|
+
version = "0.9.18"
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
7
7
|
classifiers = ["License :: OSI Approved :: MIT License"]
|
@@ -15,6 +15,7 @@ import snowflake.connector.cursor
|
|
15
15
|
import snowflake.connector.pandas_tools
|
16
16
|
from pandas.testing import assert_frame_equal
|
17
17
|
from snowflake.connector.cursor import ResultMetadata
|
18
|
+
from snowflake.connector.errors import ProgrammingError
|
18
19
|
|
19
20
|
import fakesnow
|
20
21
|
from tests.utils import dindent, indent
|
@@ -342,6 +343,17 @@ def test_connect_with_non_existent_db_or_schema(_fakesnow_no_auto_create: None):
|
|
342
343
|
assert conn.schema == "JAFFLES"
|
343
344
|
|
344
345
|
|
346
|
+
def test_create_database_respects_if_not_exists() -> None:
|
347
|
+
with tempfile.TemporaryDirectory(prefix="fakesnow-test") as db_path, fakesnow.patch(db_path=db_path):
|
348
|
+
cursor = snowflake.connector.connect().cursor()
|
349
|
+
cursor.execute("CREATE DATABASE db2")
|
350
|
+
|
351
|
+
with pytest.raises(ProgrammingError, match='Database "DB2" is already attached with path'):
|
352
|
+
cursor.execute("CREATE DATABASE db2") # Fails as db already exists.
|
353
|
+
|
354
|
+
cursor.execute("CREATE DATABASE IF NOT EXISTS db2")
|
355
|
+
|
356
|
+
|
345
357
|
def test_dateadd_date_cast(dcur: snowflake.connector.DictCursor):
|
346
358
|
q = """
|
347
359
|
SELECT
|
@@ -696,11 +708,14 @@ def test_executemany(cur: snowflake.connector.cursor.SnowflakeCursor):
|
|
696
708
|
|
697
709
|
|
698
710
|
def test_execute_string(conn: snowflake.connector.SnowflakeConnection):
|
699
|
-
|
700
|
-
"""
|
701
|
-
|
711
|
+
*_, cur = conn.execute_string(
|
712
|
+
"""
|
713
|
+
create table customers (ID int, FIRST_NAME varchar, LAST_NAME varchar);
|
714
|
+
-- test comments are ignored
|
715
|
+
select count(*) customers
|
716
|
+
"""
|
702
717
|
)
|
703
|
-
assert
|
718
|
+
assert cur.fetchall() == [(1,)]
|
704
719
|
|
705
720
|
|
706
721
|
def test_fetchall(conn: snowflake.connector.SnowflakeConnection):
|
@@ -144,6 +144,13 @@ def test_create_database() -> None:
|
|
144
144
|
== "ATTACH DATABASE '.databases/foobar.db' AS foobar"
|
145
145
|
)
|
146
146
|
|
147
|
+
assert (
|
148
|
+
sqlglot.parse_one("create database if not exists foobar")
|
149
|
+
.transform(create_database, db_path=Path(".databases/"))
|
150
|
+
.sql()
|
151
|
+
== "ATTACH IF NOT EXISTS DATABASE '.databases/foobar.db' AS foobar"
|
152
|
+
)
|
153
|
+
|
147
154
|
|
148
155
|
def test_describe_table() -> None:
|
149
156
|
assert "SELECT" in sqlglot.parse_one("describe table db1.schema1.table1").transform(describe_table).sql()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|