From 252d94599633d705887ac84ee46d52cd52e7e0e0 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Thu, 21 May 2020 03:56:58 +0530 Subject: [PATCH] Some tests for spotdl.util --- spotdl/tests/test_util.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spotdl/tests/test_util.py b/spotdl/tests/test_util.py index b1bd3a0..e30af28 100644 --- a/spotdl/tests/test_util.py +++ b/spotdl/tests/test_util.py @@ -13,6 +13,36 @@ def directory_fixture(tmpdir_factory): return dir_path +@pytest.mark.parametrize("value", [ + 5, + "string", + {"a": 1, "b": 2}, + (10, 20, 30, "string"), + [2, 4, "sample"] +]) +def test_thread_with_return_value(value): + returner = lambda x: x + thread = spotdl.util.ThreadWithReturnValue( + target=returner, + args=(value,) + ) + thread.start() + assert value == thread.join() + + +@pytest.mark.parametrize("track, track_type", [ + ("https://open.spotify.com/track/3SipFlNddvL0XNZRLXvdZD", "spotify"), + ("spotify:track:3SipFlNddvL0XNZRLXvdZD", "spotify"), + ("3SipFlNddvL0XNZRLXvdZD", "spotify"), + ("https://www.youtube.com/watch?v=oMiNsd176NM", "youtube"), + ("oMiNsd176NM", "youtube"), + ("kodaline - saving grace", "query"), + ("or anything else", "query"), +]) +def test_track_type(track, track_type): + assert spotdl.util.track_type(track) == track_type + + @pytest.mark.parametrize("str_duration, sec_duration", [ ("0:23", 23), ("0:45", 45),