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