Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add test fixtures #356

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/fixtures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- assets/fixtures.sql

-- Insert sample recordings
INSERT INTO recording (timestamp, monitor_width, monitor_height, double_click_interval_seconds, double_click_distance_pixels, platform, task_description)
VALUES
('2023-06-28 10:15:00', 1920, 1080, 0.5, 10, 'Windows', 'Task 1'),
('2023-06-29 14:30:00', 1366, 768, 0.3, 8, 'Mac', 'Task 2'),
('2023-06-30 09:45:00', 2560, 1440, 0.7, 12, 'Linux', 'Task 3');
42 changes: 42 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import pytest

from sqlalchemy import create_engine, text

from openadapt.config import ROOT_DIRPATH
from openadapt.models import db

@pytest.fixture(scope="session")
def setup_database(request):
# Create a new database or connect to an existing one
db_url = ROOT_DIRPATH / "temp.db"
engine = create_engine(
f"sqlite:///{db_url}"
)

# Create the database tables (if necessary)
db.Base.metadata.create_all(bind=engine)

# Read the SQL file and execute the statements to seed the database
with open(ROOT_DIRPATH / 'assets/fixtures.sql', 'r') as file:
statements = file.read()

with engine.connect() as connection:
connection.execute(text(statements))

# Define the teardown function
def teardown():
# Add code here to drop tables, clean up resources, etc.
# This code will be executed after the tests complete (whether or not they pass)
# Replace it with the appropriate cleanup operations for your project
# Example: db.Base.metadata.drop_all(bind=engine)

# Close the database connection (if necessary)
engine.dispose()
os.remove(db_url)

# Register the teardown function to be called after the tests complete
request.addfinalizer(teardown)

# Return the database connection object or engine for the tests to use
return engine
1 change: 1 addition & 0 deletions tests/openadapt/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ def test_summary_sentence():
she very soon finished it off."
actual = REPLAY.get_summary(story, 1)
assert fuzz.WRatio(actual, story) > 50