]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
0c3d0f51 | 2 | import os |
3 | from os.path import join | |
4 | import subprocess | |
5 | import sys | |
6 | import unittest | |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
b868936c | 9 | from test.helper import is_download_test, try_rm |
0c3d0f51 | 10 | |
11 | ||
12 | root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
13 | download_file = join(root_dir, 'test.webm') | |
14 | ||
15 | ||
b868936c | 16 | @is_download_test |
0c3d0f51 | 17 | class TestOverwrites(unittest.TestCase): |
18 | def setUp(self): | |
19 | # create an empty file | |
20 | open(download_file, 'a').close() | |
21 | ||
22 | def test_default_overwrites(self): | |
23 | outp = subprocess.Popen( | |
24 | [ | |
7a5c1cfe | 25 | sys.executable, 'yt_dlp/__main__.py', |
0c3d0f51 | 26 | '-o', 'test.webm', |
27 | 'https://www.youtube.com/watch?v=jNQXAC9IVRw' | |
28 | ], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
29 | sout, serr = outp.communicate() | |
30 | self.assertTrue(b'has already been downloaded' in sout) | |
31 | # if the file has no content, it has not been redownloaded | |
32 | self.assertTrue(os.path.getsize(download_file) < 1) | |
33 | ||
34 | def test_yes_overwrites(self): | |
35 | outp = subprocess.Popen( | |
36 | [ | |
7a5c1cfe | 37 | sys.executable, 'yt_dlp/__main__.py', '--yes-overwrites', |
0c3d0f51 | 38 | '-o', 'test.webm', |
39 | 'https://www.youtube.com/watch?v=jNQXAC9IVRw' | |
40 | ], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
41 | sout, serr = outp.communicate() | |
42 | self.assertTrue(b'has already been downloaded' not in sout) | |
43 | # if the file has no content, it has not been redownloaded | |
44 | self.assertTrue(os.path.getsize(download_file) > 1) | |
45 | ||
46 | def tearDown(self): | |
47 | try_rm(join(root_dir, 'test.webm')) | |
48 | ||
49 | ||
50 | if __name__ == '__main__': | |
51 | unittest.main() |