From 4727497025d64aa084ebaef6bfc42786d9f9e129 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 11 Jul 2020 09:50:30 -0600 Subject: [PATCH] Address TODOs in tests and make TODO check verify in test dir --- cicd/custom_style_check.py | 3 +++ sublime/config.py | 6 ++---- tests/adapter_tests/adapter_manager_tests.py | 8 ++++---- tests/adapter_tests/filesystem_adapter_tests.py | 8 ++++---- tests/config_test.py | 11 +++-------- tests/player_tests/mpv_tests.py | 17 ++++++++++++++--- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cicd/custom_style_check.py b/cicd/custom_style_check.py index c20e0ee..2499a17 100755 --- a/cicd/custom_style_check.py +++ b/cicd/custom_style_check.py @@ -50,6 +50,9 @@ valid = True for path in Path("sublime").glob("**/*.py"): valid &= check_file(path) +for path in Path("tests").glob("**/*.py"): + valid &= check_file(path) + """ Checks that the version in the CHANGELOG is the same as the version in ``__init__.py``. """ diff --git a/sublime/config.py b/sublime/config.py index 2ac3a27..e601378 100644 --- a/sublime/config.py +++ b/sublime/config.py @@ -206,10 +206,8 @@ class AppConfiguration(DataClassJsonMixin): if not (provider := self.provider): return None - state_filename = Path(os.environ.get("XDG_DATA_HOME") or "~/.local/share") - return state_filename.expanduser().joinpath( - "sublime-music", provider.id, "state.pickle" - ) + assert self.cache_location + return self.cache_location.joinpath(provider.id, "state.pickle") def save(self): # Save the config as YAML. diff --git a/tests/adapter_tests/adapter_manager_tests.py b/tests/adapter_tests/adapter_manager_tests.py index 61ba402..afc6f35 100644 --- a/tests/adapter_tests/adapter_manager_tests.py +++ b/tests/adapter_tests/adapter_manager_tests.py @@ -127,7 +127,7 @@ def test_get_song_details(adapter_manager: AdapterManager): # song = AdapterManager.get_song_details("1") # print(song) # assert 0 - # TODO + # TODO (#180) pass @@ -178,18 +178,18 @@ def test_search_result_update(): def test_search(adapter_manager: AdapterManager): - # TODO + # TODO (#180) return results = [] - # TODO ingest data + # TODO (#180) ingest data def search_callback(result: SearchResult): results.append((result.artists, result.albums, result.songs, result.playlists)) AdapterManager.search("ohea", search_callback=search_callback).result() - # TODO test getting results from the server and updating using that + # TODO (#180) test getting results from the server and updating using that while len(results) < 1: sleep(0.1) diff --git a/tests/adapter_tests/filesystem_adapter_tests.py b/tests/adapter_tests/filesystem_adapter_tests.py index dee213b..48d773a 100644 --- a/tests/adapter_tests/filesystem_adapter_tests.py +++ b/tests/adapter_tests/filesystem_adapter_tests.py @@ -178,12 +178,12 @@ def test_caching_get_playlists(cache_adapter: FilesystemAdapter): def test_no_caching_get_playlists(adapter: FilesystemAdapter): adapter.get_playlists() - # TODO: Create a playlist (that should be allowed only if this is acting as + # TODO (#188): Create a playlist (that should be allowed only if this is acting as # a ground truth adapter) # cache_adapter.create_playlist() adapter.get_playlists() - # TODO: verify playlist + # TODO (#188): verify playlist def test_caching_get_playlist_details(cache_adapter: FilesystemAdapter): @@ -244,12 +244,12 @@ def test_no_caching_get_playlist_details(adapter: FilesystemAdapter): with pytest.raises(Exception): adapter.get_playlist_details("1") - # TODO: Create a playlist (that should be allowed only if this is acting as + # TODO (#188): Create a playlist (that should be allowed only if this is acting as # a ground truth adapter) # cache_adapter.create_playlist() # adapter.get_playlist_details('1') - # TODO: verify playlist details + # TODO (#188): verify playlist details def test_caching_get_playlist_then_details(cache_adapter: FilesystemAdapter): diff --git a/tests/config_test.py b/tests/config_test.py index 6c490db..eb36f4c 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -24,10 +24,9 @@ def test_config_default_cache_location(): assert config.cache_location == Path("~/.local/share/sublime-music").expanduser() -def test_server_property(): - # TODO change the cache location so it doesn't clutter the - # ~/.local/share/sublime-music directory +def test_server_property(tmp_path: Path): config = AppConfiguration() + config.cache_location = tmp_path provider = ProviderConfiguration( id="1", name="foo", @@ -39,11 +38,7 @@ def test_server_property(): config.current_provider_id = "1" assert config.provider == provider - expected_state_file_location = Path("~/.local/share").expanduser() - expected_state_file_location = expected_state_file_location.joinpath( - "sublime-music", "1", "state.pickle", - ) - assert config._state_file_location == expected_state_file_location + assert config._state_file_location == tmp_path.joinpath("1", "state.pickle",) def test_json_load_unload(config_filename: Path): diff --git a/tests/player_tests/mpv_tests.py b/tests/player_tests/mpv_tests.py index 38f5ed8..3bb1539 100644 --- a/tests/player_tests/mpv_tests.py +++ b/tests/player_tests/mpv_tests.py @@ -13,6 +13,7 @@ def test_init(): def is_close(expected: float, value: float, delta: float = 0.5) -> bool: + print(f"EXPECTED: {expected}, VALUE: {value}") # noqa: T001 return abs(value - expected) < delta @@ -59,10 +60,20 @@ def test_play(): assert mpv_player.playing # Test seek - sleep(0.1) - assert is_close(10, mpv_player.mpv.time_pos) + for _ in range(5): + sleep(0.1) + if is_close(10, mpv_player.mpv.time_pos): + break + else: + raise Exception("Never was close") mpv_player.seek(timedelta(seconds=20)) - assert is_close(20, mpv_player.mpv.time_pos) + + for _ in range(5): + sleep(0.1) + if is_close(20, mpv_player.mpv.time_pos): + break + else: + raise Exception("Never was close") # Pause so that it doesn't keep playing while testing mpv_player.pause()