Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated tests - removed old ones and created the structure for the ne…
…w ones
- Loading branch information
1 parent
1496c40
commit b234aee
Showing
12 changed files
with
80 additions
and
426 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import unittest | ||
import logging | ||
|
||
from YouTubeMDBot.downloader import YouTubeDownloader | ||
from YouTubeMDBot.downloader import M4AYouTubeDownloader | ||
from YouTubeMDBot.downloader import MultipleYouTubeDownloader | ||
|
||
from YouTubeMDBot.utils import CBarrier | ||
|
||
log = logging.basicConfig() | ||
|
||
|
||
class DownloadTest(unittest.TestCase): | ||
lock = Lock() | ||
|
||
@property | ||
def finished(self): | ||
with self.lock: | ||
return self.__finished | ||
|
||
@finished.setter | ||
def finished(self, value): | ||
with self.lock: | ||
self.__finished = value | ||
|
||
def test_single_download(self): | ||
downloader = YouTubeDownloader( | ||
url="https://www.youtube.com/watch?v=Inm-N5rLUSI" | ||
) | ||
self._test_download(downloader) | ||
|
||
def test_single_download_to_m4a(self): | ||
downloader = M4AYouTubeDownloader( | ||
url="https://www.youtube.com/watch?v=Inm-N5rLUSI" | ||
) | ||
self._test_download(downloader) | ||
|
||
def test_multiple_downloader(self): | ||
downloader = MultipleYouTubeDownloader() | ||
self.finished = 0 | ||
urls = { | ||
"https://www.youtube.com/watch?v=Inm-N5rLUSI", | ||
"https://www.youtube.com/watch?v=-_ZwpOdXXcA", | ||
"https://www.youtube.com/watch?v=WOGWZD5iT10", | ||
"https://www.youtube.com/watch?v=GfKV9KaNJXc", | ||
"https://www.youtube.com/watch?v=DiItGE3eAyQ", | ||
"https://www.youtube.com/watch?v=GuZzuQvv7uc" | ||
} | ||
for url in urls: | ||
yt_downloader = YouTubeDownloader(url) | ||
downloader.download_async(yt_downloader, | ||
callback=self._download_finished_callback, | ||
error_callback=self._download_failed_callback) | ||
while self.finished != 6: | ||
sleep(1) | ||
|
||
def _test_download(self, downloader: YouTubeDownloader): | ||
io, data = downloader.download() | ||
self.assertEqual(io.read(), data) | ||
|
||
def _download_finished_callback(self, data): | ||
print("Video download finished") | ||
print(type(data)) | ||
self.finished += 1 | ||
|
||
def _download_failed_callback(self, err): | ||
print(f"Captured error: {err}") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.