mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-08-26 22:04:56 +02:00
refactor: organize tests
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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 ==================================================================
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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)
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user