Skip to content

Commit

Permalink
test: tempfile not working on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Dec 30, 2023
1 parent 74885ce commit 3f450d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ yarn-error.log*

# local testing sql files
test*.sql

# sqlite database generated by test cases
*.db
34 changes: 16 additions & 18 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
import tempfile
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -111,23 +112,20 @@ def generate_metadata_providers(test_schemas):

sqlite3_sqlalchemy_provider = SQLAlchemyMetaDataProvider("sqlite:///:memory:")
metadata = MetaData()
with tempfile.TemporaryDirectory() as tmpdirname:
for full_table_name, columns_names in test_schemas.items():
schema, table = full_table_name.split(".")
if schema not in ("main", "temp") and not inspect(
sqlite3_sqlalchemy_provider.engine
).has_schema(schema):
db_file_path = Path(tmpdirname).joinpath(f"{schema}.db")
with sqlite3_sqlalchemy_provider.engine.connect() as conn:
conn.execute(
text(f"ATTACH DATABASE '{db_file_path}' AS '{schema}'")
)
SQLAlchemyTable(
table,
metadata,
*[SQLAlchemyColumn(c, Integer) for c in columns_names],
schema=schema,
)
metadata.create_all(bind=sqlite3_sqlalchemy_provider.engine)
for full_table_name, columns_names in test_schemas.items():
schema, table = full_table_name.split(".")
if schema not in ("main", "temp") and not inspect(
sqlite3_sqlalchemy_provider.engine
).has_schema(schema):
db_file_path = Path(os.path.dirname(__file__)).parent.joinpath(f"{schema}.db")
with sqlite3_sqlalchemy_provider.engine.connect() as conn:
conn.execute(text(f"ATTACH DATABASE '{db_file_path}' AS '{schema}'"))
SQLAlchemyTable(
table,
metadata,
*[SQLAlchemyColumn(c, Integer) for c in columns_names],
schema=schema,
)
metadata.create_all(bind=sqlite3_sqlalchemy_provider.engine)

return [dummy_provider, sqlite3_sqlalchemy_provider]

0 comments on commit 3f450d6

Please sign in to comment.