You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6 KiB

import unittest
from random import choice
from os import chdir
from os.path import join
from tempfile import TemporaryDirectory
from copy import deepcopy
from hashlib import sha256
from coub_dl import coub_dl, File
class TestCoubDl(unittest.TestCase):
def setUp(self):
self.tmpdir = TemporaryDirectory() =
self.files = deepcopy(coub_dl.default_files)
for key in {key: self.files[key] for key in self.files if key not in coub_dl.output_files}:
self.files[key] = join(, self.files[key])
self.files[File.OUTPUT] = 'coub.mp4'
def tearDown(self):
def test_checksums(self):
urls = {'': 'b5e1a4b3376a08d5e0bd833c0f5a0e82fbc09100b829b43c176396d4f26e08e4',
'': '82895d364290f88a1ccca1ca03d1a96344501a5556d23c7193ce6107823ddbe9',
'': 'f70b98cf28837d58e083d523933bcca20c2de344b7f13a322c771f0a284113d7'}
test_url = choice(list(urls.keys()))
coub_dl(test_url, self.files)()
self.assertEqual(TestCoubDl.hash_file(self.files[File.OUTPUT], sha256), urls[test_url])
def hash_file(file, hasher, read_buffer=65536):
with open(file, 'rb') as ifile:
hasher = hasher()
while True:
chunk =
if not chunk: break
return hasher.hexdigest()
if __name__ == '__main__':