-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
887 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
; [flake8] | ||
; max-line-length = 88 # Black standard | ||
; exclude = .git,__pycache__,build,dist # Ignore folders and files | ||
; max-complexity = 10 # Set the maximum complexity allowed | ||
; ignore = | ||
; ; E203, # space before ':' | ||
; ; W503, # line break before binary operator | ||
; ; W191, # indentation contains tabs | ||
; ; E101, # indentation contains mixed spaces and tabs | ||
[flake8] | ||
max-line-length = 88 # Black standard | ||
exclude = .git,__pycache__,build,dist # Ignore folders and files | ||
max-complexity = 10 # Set the maximum complexity allowed | ||
ignore = | ||
; E203, # space before ':' | ||
; W503, # line break before binary operator | ||
; W191, # indentation contains tabs | ||
; E101, # indentation contains mixed spaces and tabs | ||
|
||
; ; be more restrictive after the refactor code | ||
; be more restrictive after the refactor code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
from loki.loki_db import Database | ||
|
||
""" | ||
Using a Memory Database for Testing | ||
======================================= | ||
1. Realism: You are testing with an actual database, ensuring that SQL | ||
operations are executed just as they would in production, potentially | ||
catching errors that mocks might miss. | ||
2. Safety: Since the database is temporary and stored in memory, there's no | ||
risk of corrupting real data or accidentally persisting test data. | ||
3. Performance: In-memory databases typically have very fast performance, | ||
making them ideal for unit tests. | ||
4. Isolation: Each test can create its own temporary database, which | ||
disappears automatically after the test finishes, ensuring that tests are | ||
independent of one another. | ||
How It Works: | ||
------------- | ||
- `temp_db` Fixture: | ||
- The `pytest.fixture` creates a temporary instance of the `Database` class | ||
connected to an in-memory database. | ||
- The temporary database is automatically cleaned up after the test. | ||
- Database Creation and Operation: | ||
- During the test, you can create tables, insert, and retrieve data using | ||
a real connection to the temporary database. | ||
- This database only exists for the duration of the test and is | ||
automatically deleted afterward, ensuring that the test remains | ||
isolated and has no impact on the real environment. | ||
""" | ||
|
||
|
||
# Fixture for a clean in-memory database (no schema applied) | ||
@pytest.fixture | ||
def clean_memory_db(): | ||
temp_db = Database(tempMem=True) | ||
yield temp_db | ||
temp_db._db.close() # Close the connection after the test | ||
|
||
|
||
# Fixture for an in-memory database with the schema loaded | ||
@pytest.fixture | ||
def schema_memory_db(): | ||
temp_db = Database(tempMem=True) | ||
temp_db.createDatabaseObjects( | ||
temp_db._schema["db"], "temp", list(temp_db._schema["db"].keys()) | ||
) | ||
# setting test parameters | ||
temp_db._dbFile = "temp" | ||
temp_db._is_test = True | ||
yield temp_db | ||
temp_db._db.close() | ||
|
||
|
||
# Fixture for a file-based database | ||
@pytest.fixture | ||
def file_based_db(): | ||
temp_db = Database(dbFile="tests/loki_test.db") | ||
yield temp_db | ||
temp_db._db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.