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