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