musicmuster/tests/test_misc.py
2024-04-05 10:41:14 +01:00

51 lines
1.4 KiB
Python

# Standard library imports
import os
import unittest
# PyQt imports
# Third party imports
import pytest
# App imports
# Set up test database before importing db
# Mark subsequent lines to ignore E402, imports not at top of file
# Set up test database before importing db
# Mark subsequent lines to ignore E402, imports not at top of file
DB_FILE = "/tmp/mm.db"
if os.path.exists(DB_FILE):
os.unlink(DB_FILE)
os.environ["ALCHEMICAL_DATABASE_URI"] = "sqlite:///" + DB_FILE
from models import db, Settings # noqa: E402
class TestMMMisc(unittest.TestCase):
def setUp(self):
db.create_all()
def tearDown(self):
db.drop_all()
def test_log_exception(self):
"""Test deliberate exception"""
with pytest.raises(Exception):
1 / 0
def test_create_settings(self):
SETTING_NAME = "wombat"
NO_SUCH_SETTING = "abc"
VALUE = 3
with db.Session() as session:
setting = Settings(session, SETTING_NAME)
# test repr
_ = str(setting)
setting.update(session, dict(f_int=VALUE))
_ = Settings.all_as_dict(session)
test = Settings.get_int_settings(session, SETTING_NAME)
assert test.name == SETTING_NAME
assert test.f_int == VALUE
test_new = Settings.get_int_settings(session, NO_SUCH_SETTING)
assert test_new.name == NO_SUCH_SETTING