diff --git a/tests/conftest.py b/tests/conftest.py index 98c7e494..d1a17f16 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,7 @@ from unittest.mock import Mock, patch import pytest from PySide6.QtWidgets import QScrollArea +from pytestqt.qtbot import QtBot from tagstudio.core.library.alchemy.fields import TextField @@ -146,6 +147,12 @@ def entry_full(library: Library): yield next(library.all_entries(with_joins=True)) +@pytest.fixture(autouse=True) +def _init_qtbot(qtbot: QtBot): # pyright: ignore[reportUnusedFunction] + """Ensures that a QtBot is initialized for all subsequent tests, regardless of order.""" + return qtbot + + @pytest.fixture def qt_driver(library: Library, library_dir: Path): class Args: diff --git a/tests/test_json_migration.py b/tests/core/library/test_json_migration.py similarity index 93% rename from tests/test_json_migration.py rename to tests/core/library/test_json_migration.py index 003eb08f..517769b9 100644 --- a/tests/test_json_migration.py +++ b/tests/core/library/test_json_migration.py @@ -10,7 +10,7 @@ CWD = Path(__file__) def test_json_migration(): - modal = JsonMigrationModal(CWD.parent / "fixtures" / "json_library") + modal = JsonMigrationModal(CWD.parents[2] / "fixtures" / "json_library") modal.migrate(skip_ui=True) # Entries ================================================================== diff --git a/tests/test_library.py b/tests/core/library/test_library.py similarity index 100% rename from tests/test_library.py rename to tests/core/library/test_library.py diff --git a/tests/test_db_migrations.py b/tests/core/library/test_migrations.py similarity index 55% rename from tests/test_db_migrations.py rename to tests/core/library/test_migrations.py index 87ef3574..4f6c77b9 100644 --- a/tests/test_db_migrations.py +++ b/tests/core/library/test_migrations.py @@ -21,16 +21,16 @@ EMPTY_LIBRARIES = "empty_libraries" @pytest.mark.parametrize( "path", [ - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_6")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_7")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_8")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_9")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_100")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_101")), - # str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_102")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_103")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_200")), - str(Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_201")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_6")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_7")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_8")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_9")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_100")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_101")), + # str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_102")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_103")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_200")), + str(Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_201")), ], ) def test_library_migrations(path: str): @@ -38,7 +38,7 @@ def test_library_migrations(path: str): # Copy libraries to temp dir so modifications don't show up in version control original_path = Path(path) - temp_path = Path(CWD.parent / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_TEMP") + temp_path = Path(CWD.parents[2] / FIXTURES / EMPTY_LIBRARIES / "DB_VERSION_TEMP") temp_path.mkdir(exist_ok=True) temp_path_ts = temp_path / TS_FOLDER_NAME temp_path_ts.mkdir(exist_ok=True) diff --git a/tests/macros/test_refresh_dir.py b/tests/core/library/test_refresh.py similarity index 100% rename from tests/macros/test_refresh_dir.py rename to tests/core/library/test_refresh.py diff --git a/tests/test_search.py b/tests/core/library/test_search.py similarity index 100% rename from tests/test_search.py rename to tests/core/library/test_search.py diff --git a/tests/macros/test_missing_files.py b/tests/core/library/test_unlinked_entries.py similarity index 96% rename from tests/macros/test_missing_files.py rename to tests/core/library/test_unlinked_entries.py index 3ea463a6..4d20590c 100644 --- a/tests/macros/test_missing_files.py +++ b/tests/core/library/test_unlinked_entries.py @@ -17,7 +17,7 @@ CWD = Path(__file__).parent # NOTE: Does this test actually work? @pytest.mark.parametrize("library", [TemporaryDirectory()], indirect=True) -def test_refresh_missing_files(library: Library): +def test_refresh_unlinked_entries(library: Library): registry = UnlinkedRegistry(lib=library) # touch the file `one/two/bar.md` but in wrong location to simulate a moved file diff --git a/tests/macros/test_folders_tags.py b/tests/core/macros/test_folders_tags.py similarity index 100% rename from tests/macros/test_folders_tags.py rename to tests/core/macros/test_folders_tags.py diff --git a/tests/test_driver.py b/tests/core/test_base_driver.py similarity index 84% rename from tests/test_driver.py rename to tests/core/test_base_driver.py index 6201f18a..fbacb7c9 100644 --- a/tests/test_driver.py +++ b/tests/core/test_base_driver.py @@ -12,7 +12,8 @@ from tagstudio.core.library.alchemy.library import LibraryStatus from tagstudio.qt.app_settings import AppSettings -class TestDriver(DriverMixin): +# TODO: Remove Qt-specific things from this base driver text +class TestBaseDriver(DriverMixin): def __init__(self, settings: AppSettings, cache: QSettings): self.settings = settings self.cached_values = cache @@ -20,7 +21,7 @@ class TestDriver(DriverMixin): def test_evaluate_path_empty(): # Given - driver = TestDriver(AppSettings(), QSettings()) + driver = TestBaseDriver(AppSettings(), QSettings()) # When result = driver.evaluate_path(None) @@ -31,7 +32,7 @@ def test_evaluate_path_empty(): def test_evaluate_path_missing(): # Given - driver = TestDriver(AppSettings(), QSettings()) + driver = TestBaseDriver(AppSettings(), QSettings()) # When result = driver.evaluate_path("/0/4/5/1/") @@ -44,7 +45,7 @@ def test_evaluate_path_last_lib_not_exists(): # Given cache = QSettings() cache.setValue(AppCacheItems.LAST_LIBRARY, "/0/4/5/1/") - driver = TestDriver(AppSettings(), cache) + driver = TestBaseDriver(AppSettings(), cache) # When result = driver.evaluate_path(None) @@ -63,7 +64,7 @@ def test_evaluate_path_last_lib_present(library_dir: Path): settings = AppSettings() settings.open_last_loaded_on_startup = True - driver = TestDriver(settings, cache) + driver = TestBaseDriver(settings, cache) # When result = driver.evaluate_path(None) diff --git a/tests/macros/test_dupe_files.py b/tests/core/test_dupe_files.py similarity index 100% rename from tests/macros/test_dupe_files.py rename to tests/core/test_dupe_files.py diff --git a/tests/test_translations.py b/tests/i18n/test_translations.py similarity index 98% rename from tests/test_translations.py rename to tests/i18n/test_translations.py index 5a699de5..8c77f22b 100644 --- a/tests/test_translations.py +++ b/tests/i18n/test_translations.py @@ -9,7 +9,7 @@ from pathlib import Path import pytest import ujson as json -CWD = Path(__file__).parent +CWD = Path(__file__).parents[1] TRANSLATION_DIR = CWD / ".." / "src" / "tagstudio" / "resources" / "translations"