tekumara / fakesnow

Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally.
Apache License 2.0
83 stars 7 forks source link

fix: CREATE DATABASE when using db_path #103

Closed jsibbison-square closed 2 weeks ago

jsibbison-square commented 2 weeks ago

When patching in a test specifying a db_path and attempting to create a database:

with fakesnow.patch(db_path="databases"):
    cursor = snowflake.connector.connect().cursor()
    cursor.execute(f"CREATE DATABASE TEST32cs3s3")

the following error is thrown

>           db_file = f"{db_path/db_name}.db" if db_path else ":memory:"
E           TypeError: unsupported operand type(s) for /: 'str' and 'str'

This PR fixes the string interpolation.

Note that I expect there is a similar bug in fakes.py#538 but I couldn't figure out how to trigger it via a test.

PS: Thanks for making this project

tekumara commented 2 weeks ago

Good catch thank you! The / operator will work with Path but not str which is why fakes.py#538 works.

I've refactored your solution to use Path as this is the type expected by transforms.create_database.