refactor!: organize project layout (#1483)

* refactor!: organize project layout

* refactor: organize tests

* fix: change main.py with __main__.py in tagstudio.spec

* refactor: rename renderer.py to file_renderer.py
This commit is contained in:
Travis Abendshien
2026-08-18 13:56:35 -07:00
committed by GitHub
parent f89f0a6c7f
commit c32f500f3c
139 changed files with 545 additions and 514 deletions
+11 -3
View File
@@ -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
@@ -20,8 +21,8 @@ sys.path.insert(0, str(CWD.parent))
from tagstudio.core.constants import THUMB_CACHE_NAME, TS_FOLDER_NAME
from tagstudio.core.library.alchemy.library import Library
from tagstudio.core.library.alchemy.models import Entry, Tag
from tagstudio.qt.thumb_grid_layout import ThumbGridLayout
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.qt_driver import QtDriver
from tagstudio.qt.views.layouts.thumb_grid_layout import ThumbGridLayout
@pytest.fixture
@@ -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:
@@ -154,7 +161,8 @@ def qt_driver(library: Library, library_dir: Path):
open = library_dir
ci = True
with patch("tagstudio.qt.ts_qt.Consumer"), patch("tagstudio.qt.ts_qt.CustomRunnable"):
# NOTE: What the heck is this
with patch("tagstudio.qt.qt_driver.Consumer"), patch("tagstudio.qt.qt_driver.CustomRunnable"):
driver = QtDriver(Args()) # pyright: ignore[reportArgumentType]
driver.app = Mock()
@@ -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
@@ -9,18 +9,19 @@ from PySide6.QtCore import QSettings
from tagstudio.core.driver import DriverMixin
from tagstudio.core.enums import AppCacheItems
from tagstudio.core.library.alchemy.library import LibraryStatus
from tagstudio.qt.global_settings import GlobalSettings
from tagstudio.qt.app_settings import AppSettings
class TestDriver(DriverMixin):
def __init__(self, settings: GlobalSettings, cache: QSettings):
# 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
def test_evaluate_path_empty():
# Given
driver = TestDriver(GlobalSettings(), 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(GlobalSettings(), 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(GlobalSettings(), cache)
driver = TestBaseDriver(AppSettings(), cache)
# When
result = driver.evaluate_path(None)
@@ -60,10 +61,10 @@ def test_evaluate_path_last_lib_present(library_dir: Path):
cache.setValue(AppCacheItems.LAST_LIBRARY, library_dir)
cache.sync()
settings = GlobalSettings()
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"
@@ -4,7 +4,7 @@
from pathlib import Path
from tagstudio.qt.global_settings import GlobalSettings, Theme
from tagstudio.qt.app_settings import AppSettings, Theme
def test_read_settings(library_dir: Path):
@@ -23,7 +23,7 @@ def test_read_settings(library_dir: Path):
zero_padding = true
""")
settings = GlobalSettings.read_settings(settings_path)
settings = AppSettings.read_settings(settings_path)
assert settings.language == "de"
assert settings.open_last_loaded_on_startup
assert settings.autoplay
@@ -34,3 +34,21 @@ def test_read_settings(library_dir: Path):
assert settings.date_format == "%x"
assert settings.hour_format
assert settings.zero_padding
# NOTE: Other tests are affected by the settings made in this test, so as a temporary measure
# this just reverts the language back to English for subsequent tests.
with open(settings_path, "w") as settings_file:
settings_file.write("""
language = "en"
open_last_loaded_on_startup = true
autoplay = true
show_filenames_in_grid = true
page_size = 1337
show_filepath = 0
dark_mode = 2
date_format = "%x"
hour_format = true
zero_padding = true
""")
settings = AppSettings.read_settings(settings_path)
assert settings.language == "en"
+1 -1
View File
@@ -12,9 +12,9 @@ from pytestqt.qtbot import QtBot
from tagstudio.core.library.alchemy.library import Library
from tagstudio.core.library.alchemy.models import Tag, TagAlias
from tagstudio.core.utils.types import unwrap
from tagstudio.i18n.translations import Translations
from tagstudio.qt.mixed.build_tag import BuildTagPanel, CustomTableItem
from tagstudio.qt.mixed.tag_widget import TagWidget
from tagstudio.qt.translations import Translations
def test_build_tag_panel_add_sub_tag_callback(
+11 -11
View File
@@ -8,12 +8,12 @@ from tagstudio.core.library.alchemy.library import Library
# pyright: reportPrivateUsage=false
from tagstudio.core.library.alchemy.models import Entry, Tag
from tagstudio.core.utils.types import unwrap
from tagstudio.qt.controllers.preview_panel_controller import PreviewPanel
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.controllers.inspector import Inspector
from tagstudio.qt.qt_driver import QtDriver
def test_update_selection_empty(qt_driver: QtDriver):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Clear the library selection (selecting 1 then unselecting 1)
qt_driver.toggle_item_selection(1, append=False, bridge=False)
@@ -26,7 +26,7 @@ def test_update_selection_empty(qt_driver: QtDriver):
def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Select the single entry
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
@@ -40,7 +40,7 @@ def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
def test_update_selection_multiple(qt_driver: QtDriver):
# TODO: Implement mixed field editing. Currently these containers will be hidden,
# same as the empty selection behavior.
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Select the multiple entries
qt_driver.toggle_item_selection(1, append=False, bridge=False)
@@ -53,7 +53,7 @@ def test_update_selection_multiple(qt_driver: QtDriver):
def test_add_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
assert {t.id for t in entry_full.tags} == {1000}
@@ -70,7 +70,7 @@ def test_add_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
def test_add_same_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
assert {t.id for t in entry_full.tags} == {1000}
@@ -87,7 +87,7 @@ def test_add_same_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry
def test_add_tag_to_selection_multiple(qt_driver: QtDriver):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
all_entries = qt_driver.lib.all_entries(with_joins=True)
# We want to verify that tag 1000 is on some, but not all entries already.
@@ -127,7 +127,7 @@ def test_add_tag_to_selection_multiple(qt_driver: QtDriver):
def test_meta_tag_category(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Ensure the Favorite tag is on entry_full
qt_driver.lib.add_tags_to_entries(1, entry_full.id)
@@ -155,7 +155,7 @@ def test_meta_tag_category(qt_driver: QtDriver, entry_full: Entry):
def test_custom_tag_category(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Set tag 1000 (foo) as a category
tag: Tag = unwrap(qt_driver.lib.get_tag(1000))
@@ -190,7 +190,7 @@ def test_custom_tag_category(qt_driver: QtDriver, entry_full: Entry):
def test_exclude_tag_category(
qt_driver: QtDriver, library: Library, generate_tag: Callable[..., Tag]
):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
category_parent = unwrap(generate_tag("category_parent", id=123, is_category=True))
library.add_tag(category_parent)
+3 -3
View File
@@ -17,9 +17,9 @@ from tagstudio.core.enums import ShowFilepathOption
from tagstudio.core.library.alchemy.library import Library, LibraryStatus
from tagstudio.core.library.alchemy.models import Entry
from tagstudio.core.utils.types import unwrap
from tagstudio.qt.controllers.preview_panel_controller import PreviewPanel
from tagstudio.qt.controllers.inspector import Inspector
from tagstudio.qt.mixed.settings_panel import SettingsPanel
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.qt_driver import QtDriver
# Tests to see if the file path setting is applied correctly
@@ -62,7 +62,7 @@ def test_file_path_display(
filepath_option: ShowFilepathOption,
expected_path: Callable[[Library], Path],
):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Select 2
qt_driver.toggle_item_selection(2, append=False, bridge=False)
@@ -4,12 +4,12 @@
# pyright: reportPrivateUsage=false
from tagstudio.core.library.alchemy.models import Entry
from tagstudio.qt.controllers.preview_panel_controller import PreviewPanel
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.controllers.inspector import Inspector
from tagstudio.qt.qt_driver import QtDriver
def test_update_selection_empty(qt_driver: QtDriver):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Clear the library selection (selecting 1 then unselecting 1)
qt_driver.toggle_item_selection(1, append=False, bridge=False)
@@ -25,7 +25,7 @@ def test_update_selection_empty(qt_driver: QtDriver):
def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Select the single entry
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
@@ -37,7 +37,7 @@ def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
def test_update_selection_multiple(qt_driver: QtDriver):
panel = PreviewPanel(qt_driver)
panel = Inspector(qt_driver)
# Select the multiple entries
qt_driver.toggle_item_selection(1, append=False, bridge=False)
+1 -1
View File
@@ -6,7 +6,7 @@ import pytest
from tagstudio.core.library.alchemy.enums import ItemType
from tagstudio.qt.mixed.item_thumb import BadgeType, ItemThumb
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.qt_driver import QtDriver
@pytest.mark.parametrize("new_value", (True, False))
+1 -1
View File
@@ -4,7 +4,7 @@
from tagstudio.core.library.alchemy.enums import BrowsingState
from tagstudio.core.utils.types import unwrap
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.qt_driver import QtDriver
def test_browsing_state_update(qt_driver: QtDriver):
+1 -1
View File
@@ -7,7 +7,7 @@ from pytestqt.qtbot import QtBot
from tagstudio.core.library.alchemy.library import Library
from tagstudio.core.library.alchemy.models import Tag
from tagstudio.qt.mixed.build_tag import BuildTagPanel
from tagstudio.qt.ts_qt import QtDriver
from tagstudio.qt.qt_driver import QtDriver
def test_tag_panel(qtbot: QtBot, library: Library):
+1 -1
View File
@@ -6,7 +6,7 @@ from PySide6.QtCore import SIGNAL
from pytestqt.qtbot import QtBot
from tagstudio.core.library.alchemy.library import Library
from tagstudio.qt.controllers.tag_search_panel_controller import TagSearchPanel
from tagstudio.qt.controllers.tag_search_panel import TagSearchPanel
from tagstudio.qt.mixed.tag_widget import TagWidget
from tagstudio.qt.views.search_panel_view import SearchPanelView
+1 -1
View File
@@ -9,7 +9,7 @@ from unittest.mock import Mock
import pytest
from PySide6.QtCore import Qt
from tagstudio.qt.global_settings import Theme
from tagstudio.qt.app_settings import Theme
@pytest.mark.parametrize(