74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
"""Round 115: Preferences › DJ shows how much disk the saved vocal splits
|
||
take, in a group of their own that says what they are."""
|
||
import pytest
|
||
from PyQt6.QtWidgets import QGroupBox
|
||
|
||
from lintunes.dj import stems
|
||
|
||
|
||
@pytest.fixture
|
||
def cache(tmp_path, monkeypatch):
|
||
monkeypatch.setenv("XDG_CACHE_HOME", str(tmp_path / "cache"))
|
||
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "config"))
|
||
return tmp_path
|
||
|
||
|
||
def _split(name, size):
|
||
folder = stems.cache_root() / name / "htdemucs"
|
||
folder.mkdir(parents=True)
|
||
(folder / "vocals.opus").write_bytes(b"x" * size)
|
||
|
||
|
||
def _dialog(cache):
|
||
from lintunes.gui.preferences_dialog import PreferencesDialog
|
||
from lintunes.preferences import Preferences
|
||
from tests.test_round40 import _FakeLastFm
|
||
return PreferencesDialog(Preferences(cache), _FakeLastFm())
|
||
|
||
|
||
def _wait_for(qapp, condition):
|
||
import time
|
||
for _ in range(200):
|
||
qapp.processEvents()
|
||
if condition():
|
||
return
|
||
time.sleep(0.01)
|
||
raise AssertionError("timed out")
|
||
|
||
|
||
def test_cache_size_counts_every_split_and_an_empty_cache_is_zero(cache):
|
||
assert stems.cache_size() == 0
|
||
_split("a", 1000)
|
||
_split("b", 500)
|
||
assert stems.cache_size() == 1500
|
||
|
||
|
||
def test_the_dialog_shows_the_space_used(qapp, cache):
|
||
_split("a", 3 * 1024 ** 2)
|
||
dialog = _dialog(cache)
|
||
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "3 MB")
|
||
dialog.deleteLater()
|
||
|
||
|
||
def test_lowering_the_limit_prunes_then_remeasures(qapp, cache):
|
||
_split("a", 2 * 1024 ** 2)
|
||
dialog = _dialog(cache)
|
||
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "2 MB")
|
||
dialog._dj_cache_edit.setText("0")
|
||
dialog._save_stem_cache_limit()
|
||
_wait_for(qapp, lambda: dialog._dj_cache_used.text() == "0 MB")
|
||
dialog.deleteLater()
|
||
|
||
|
||
def test_the_limit_lives_in_its_own_explained_group(qapp, cache):
|
||
dialog = _dialog(cache)
|
||
from PyQt6.QtWidgets import QLabel
|
||
group = dialog._dj_cache_edit.parentWidget()
|
||
while not isinstance(group, QGroupBox):
|
||
group = group.parentWidget()
|
||
column = group.parentWidget().layout()
|
||
heading = column.itemAt(column.indexOf(group) - 1).widget()
|
||
assert isinstance(heading, QLabel)
|
||
assert heading.text() == "Saved vocal splits"
|
||
dialog.deleteLater()
|