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