Continuing the player refactor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -5,7 +6,7 @@ import pytest
|
||||
from sublime.adapters import ConfigurationStore
|
||||
from sublime.adapters.filesystem import FilesystemAdapter
|
||||
from sublime.adapters.subsonic import SubsonicAdapter
|
||||
from sublime.config import AppConfiguration, ProviderConfiguration, ReplayGainType
|
||||
from sublime.config import AppConfiguration, ProviderConfiguration
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -13,6 +14,11 @@ def config_filename(tmp_path: Path):
|
||||
yield tmp_path.joinpath("config.json")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cwd():
|
||||
yield Path(__file__).parent
|
||||
|
||||
|
||||
def test_config_default_cache_location():
|
||||
config = AppConfiguration()
|
||||
assert config.cache_location == Path("~/.local/share/sublime-music").expanduser()
|
||||
@@ -66,24 +72,19 @@ def test_json_load_unload(config_filename: Path):
|
||||
assert original_config.provider == loaded_config.provider
|
||||
|
||||
|
||||
def test_config_migrate(config_filename: Path):
|
||||
config = AppConfiguration(
|
||||
providers={
|
||||
"1": ProviderConfiguration(
|
||||
id="1",
|
||||
name="foo",
|
||||
ground_truth_adapter_type=SubsonicAdapter,
|
||||
ground_truth_adapter_config=ConfigurationStore(),
|
||||
)
|
||||
def test_config_migrate_v5_to_v6(config_filename: Path, cwd: Path):
|
||||
shutil.copyfile(str(cwd.joinpath("mock_data/config-v5.json")), str(config_filename))
|
||||
app_config = AppConfiguration.load_from_file(config_filename)
|
||||
app_config.migrate()
|
||||
|
||||
assert app_config.version == 6
|
||||
assert app_config.player_config == {
|
||||
"Local Playback": {"Replay Gain": "track"},
|
||||
"Chromecast": {
|
||||
"Serve Local Files to Chromecasts on the LAN": True,
|
||||
"LAN Server Port Number": 6969,
|
||||
},
|
||||
current_provider_id="1",
|
||||
filename=config_filename,
|
||||
)
|
||||
config.migrate()
|
||||
|
||||
assert config.version == 5
|
||||
|
||||
|
||||
def test_replay_gain_enum():
|
||||
for rg in (ReplayGainType.NO, ReplayGainType.TRACK, ReplayGainType.ALBUM):
|
||||
assert rg == ReplayGainType.from_string(rg.as_string())
|
||||
}
|
||||
app_config.save()
|
||||
app_config2 = AppConfiguration.load_from_file(config_filename)
|
||||
assert app_config == app_config2
|
||||
|
17
tests/mock_data/config-v5.json
Normal file
17
tests/mock_data/config-v5.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"allow_song_downloads": true,
|
||||
"always_stream": false,
|
||||
"cache_location": "/home/sumner/.local/share/sublime-music",
|
||||
"concurrent_download_limit": 5,
|
||||
"current_provider_id": null,
|
||||
"download_on_stream": true,
|
||||
"filename": "/home/sumner/.config/sublime-music/config.json",
|
||||
"offline_mode": false,
|
||||
"port_number": 6969,
|
||||
"prefetch_amount": 3,
|
||||
"providers": {},
|
||||
"replay_gain": 1,
|
||||
"serve_over_lan": true,
|
||||
"song_play_notification": true,
|
||||
"version": 5
|
||||
}
|
14
tests/player_tests/chromecast_tests.py
Normal file
14
tests/player_tests/chromecast_tests.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from sublime.players.chromecast import ChromecastPlayer
|
||||
|
||||
|
||||
def test_init():
|
||||
empty_fn = lambda *a, **k: None
|
||||
ChromecastPlayer(
|
||||
empty_fn,
|
||||
empty_fn,
|
||||
empty_fn,
|
||||
{
|
||||
"Serve Local Files to Chromecasts on the LAN": True,
|
||||
"LAN Server Port Number": 6969,
|
||||
},
|
||||
)
|
6
tests/player_tests/mpv_tests.py
Normal file
6
tests/player_tests/mpv_tests.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from sublime.players.mpv import MPVPlayer
|
||||
|
||||
|
||||
def test_init():
|
||||
empty_fn = lambda *a, **k: None
|
||||
MPVPlayer(empty_fn, empty_fn, empty_fn, {"Replay Gain": "no"})
|
Reference in New Issue
Block a user