mirror of
				https://github.com/KevinMidboe/spotify-downloader.git
				synced 2025-10-29 18:00:15 +00:00 
			
		
		
		
	Add tests
This commit is contained in:
		@@ -292,9 +292,6 @@ def get_arguments(raw_args=None, to_group=True, to_merge=True):
 | 
				
			|||||||
    if parsed.avconv and parsed.trim_silence:
 | 
					    if parsed.avconv and parsed.trim_silence:
 | 
				
			||||||
        parser.error("--trim-silence can only be used with FFmpeg")
 | 
					        parser.error("--trim-silence can only be used with FFmpeg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if parsed.no_metadata and parsed.no_fallback_metadata:
 | 
					 | 
				
			||||||
        parser.error('--no-metadata and --no-fallback-metadata cannot be used together')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    parsed.log_level = log_leveller(parsed.log_level)
 | 
					    parsed.log_level = log_leveller(parsed.log_level)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return parsed
 | 
					    return parsed
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ def _getbestthumb(self):
 | 
				
			|||||||
    if url:
 | 
					    if url:
 | 
				
			||||||
        return url
 | 
					        return url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    part_url = "http://i.ytimg.com/vi/%s/" % self.videoid
 | 
					    part_url = "https://i.ytimg.com/vi/%s/" % self.videoid
 | 
				
			||||||
    # Thumbnail resolution sorted in descending order
 | 
					    # Thumbnail resolution sorted in descending order
 | 
				
			||||||
    thumbs = ("maxresdefault.jpg",
 | 
					    thumbs = ("maxresdefault.jpg",
 | 
				
			||||||
              "sddefault.jpg",
 | 
					              "sddefault.jpg",
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										35
									
								
								test/test_patcher.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								test/test_patcher.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					from spotdl import patcher
 | 
				
			||||||
 | 
					import pafy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					patcher.patch_pafy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestPafyContentAvailable:
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestMethodAssignment:
 | 
				
			||||||
 | 
					    def test_pafy_getbestthumb(self):
 | 
				
			||||||
 | 
					        pafy.backend_shared.BasePafy.getbestthumb == patcher._getbestthumb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestMethodCalls:
 | 
				
			||||||
 | 
					    @pytest.fixture(scope="module")
 | 
				
			||||||
 | 
					    def content_fixture(self):
 | 
				
			||||||
 | 
					        content = pafy.new("http://youtube.com/watch?v=3nQNiWdeH2Q")
 | 
				
			||||||
 | 
					        return content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_pafy_getbestthumb(self, content_fixture):
 | 
				
			||||||
 | 
					        thumbnail = patcher._getbestthumb(content_fixture)
 | 
				
			||||||
 | 
					        assert thumbnail == "https://i.ytimg.com/vi/3nQNiWdeH2Q/maxresdefault.jpg"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_pafy_getbestthumb_without_ytdl(self, content_fixture):
 | 
				
			||||||
 | 
					        content_fixture._ydl_info["thumbnails"][0]["url"] = None
 | 
				
			||||||
 | 
					        thumbnail = patcher._getbestthumb(content_fixture)
 | 
				
			||||||
 | 
					        assert thumbnail == "https://i.ytimg.com/vi/3nQNiWdeH2Q/maxresdefault.jpg"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_pafy_content_available(self):
 | 
				
			||||||
 | 
					        TestPafyContentAvailable._content_available = patcher._content_available
 | 
				
			||||||
 | 
					        assert TestPafyContentAvailable()._content_available("https://youtube.com/")
 | 
				
			||||||
@@ -99,6 +99,56 @@ def content_fixture(metadata_fixture):
 | 
				
			|||||||
    return content
 | 
					    return content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# True = Metadata must be fetched from Spotify
 | 
				
			||||||
 | 
					# False = Metadata must be fetched from YouTube
 | 
				
			||||||
 | 
					# None = Metadata must be `None`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MATCH_METADATA_NO_FALLBACK_TEST_TABLE = [
 | 
				
			||||||
 | 
					    ("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", True),
 | 
				
			||||||
 | 
					    ("http://youtube.com/watch?v=3nQNiWdeH2Q", None),
 | 
				
			||||||
 | 
					    ("Linux Talk | Working with Drives and Filesystems", None)
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MATCH_METADATA_FALLBACK_TEST_TABLE = [
 | 
				
			||||||
 | 
					    ("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", True),
 | 
				
			||||||
 | 
					    ("http://youtube.com/watch?v=3nQNiWdeH2Q", False),
 | 
				
			||||||
 | 
					    ("Linux Talk | Working with Drives and Filesystems", False)
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MATCH_METADATA_NO_METADATA_TEST_TABLE = [
 | 
				
			||||||
 | 
					    ("https://open.spotify.com/track/5nWduGwBGBn1PSqYTJUDbS", None),
 | 
				
			||||||
 | 
					    ("http://youtube.com/watch?v=3nQNiWdeH2Q", None),
 | 
				
			||||||
 | 
					    ("Linux Talk | Working with Drives and Filesystems", None)
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestMetadataOrigin:
 | 
				
			||||||
 | 
					    def match_metadata(self, track, metadata_type):
 | 
				
			||||||
 | 
					        _, metadata = youtube_tools.match_video_and_metadata(track)
 | 
				
			||||||
 | 
					        if metadata_type is None:
 | 
				
			||||||
 | 
					            assert metadata == metadata_type
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            assert metadata["spotify_metadata"] == metadata_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_FALLBACK_TEST_TABLE)
 | 
				
			||||||
 | 
					    def test_match_metadata_with_no_fallback(self, track, metadata_type, monkeypatch, content_fixture):
 | 
				
			||||||
 | 
					        monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
 | 
				
			||||||
 | 
					        const.args.no_fallback_metadata = True
 | 
				
			||||||
 | 
					        self.match_metadata(track, metadata_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_FALLBACK_TEST_TABLE)
 | 
				
			||||||
 | 
					    def test_match_metadata_with_fallback(self, track, metadata_type, monkeypatch, content_fixture):
 | 
				
			||||||
 | 
					        monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
 | 
				
			||||||
 | 
					        const.args.no_fallback_metadata = False
 | 
				
			||||||
 | 
					        self.match_metadata(track, metadata_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @pytest.mark.parametrize("track, metadata_type", MATCH_METADATA_NO_METADATA_TEST_TABLE)
 | 
				
			||||||
 | 
					    def test_match_metadata_with_no_metadata(self, track, metadata_type, monkeypatch, content_fixture):
 | 
				
			||||||
 | 
					        monkeypatch.setattr(youtube_tools, "go_pafy", lambda track, meta_tags: content_fixture)
 | 
				
			||||||
 | 
					        const.args.no_metadata = True
 | 
				
			||||||
 | 
					        self.match_metadata(track, metadata_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.fixture(scope="module")
 | 
					@pytest.fixture(scope="module")
 | 
				
			||||||
def title_fixture(content_fixture):
 | 
					def title_fixture(content_fixture):
 | 
				
			||||||
    title = youtube_tools.get_youtube_title(content_fixture)
 | 
					    title = youtube_tools.get_youtube_title(content_fixture)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user