mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Adding new tests using unit test module
This commit is contained in:
59
Tests/TestsDownload.py
Normal file
59
Tests/TestsDownload.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import asyncio
|
||||
from typing import List
|
||||
import unittest
|
||||
from Music.Downloader import Downloader
|
||||
from Music.Playlist import Playlist
|
||||
from Music.Song import Song
|
||||
from Tests.TestsHelper import TestsConstants
|
||||
|
||||
|
||||
def myAsyncTest(coro):
|
||||
def wrapper(*args, **kwargs):
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(None)
|
||||
try:
|
||||
return loop.run_until_complete(coro(*args, **kwargs))
|
||||
finally:
|
||||
loop.close()
|
||||
return wrapper
|
||||
|
||||
|
||||
class TestDownloader(unittest.IsolatedAsyncioTestCase):
|
||||
def __init__(self, methodName: str = ...) -> None:
|
||||
self.downloader = Downloader()
|
||||
self.constants = TestsConstants()
|
||||
super().__init__(methodName)
|
||||
|
||||
@myAsyncTest
|
||||
async def test_emptyString(self):
|
||||
musicsList = await self.downloader.extract_info('')
|
||||
|
||||
self.assertEqual(musicsList, [], self.constants.EMPTY_STRING_ERROR_MSG)
|
||||
|
||||
@myAsyncTest
|
||||
async def test_YoutubeMusicUrl(self) -> None:
|
||||
musicInfo = await self.downloader.extract_info(self.constants.YOUTUBE_MUSIC_URL)
|
||||
|
||||
self.assertTrue(self.__infoExtractedSuccessfully(musicInfo))
|
||||
|
||||
def test_musicTitle(self):
|
||||
playlist = Playlist()
|
||||
song = Song(self.constants.MUSIC_TITLE_STRING, playlist, '')
|
||||
playlist.add_song(song)
|
||||
|
||||
self.downloader.finish_one_song(song)
|
||||
self.assertFalse(song.problematic)
|
||||
|
||||
def __downloadSucceeded(self, downloadReturn: List[dict]) -> bool:
|
||||
# print(downloadReturn)
|
||||
return True
|
||||
|
||||
def __infoExtractedSuccessfully(self, info: List[dict]) -> bool:
|
||||
if len(info) > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == 'main':
|
||||
unittest.main()
|
||||
10
Tests/TestsHelper.py
Normal file
10
Tests/TestsHelper.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from Config.Configs import Singleton
|
||||
|
||||
|
||||
class TestsConstants(Singleton):
|
||||
def __init__(self) -> None:
|
||||
if not super().created:
|
||||
self.EMPTY_STRING_ERROR_MSG = 'Downloader with Empty String should be empty list.'
|
||||
self.SPOTIFY_TRACK_URL = 'https://open.spotify.com/track/7wpnz7hje4FbnjZuWQtJHP'
|
||||
self.MUSIC_TITLE_STRING = 'Experience || AMV || Anime Mix'
|
||||
self.YOUTUBE_MUSIC_URL = 'https://www.youtube.com/watch?v=MvJoiv842mk'
|
||||
0
Tests/__init__.py
Normal file
0
Tests/__init__.py
Normal file
Reference in New Issue
Block a user