]> jfr.im git - yt-dlp.git/blame - test/test_overwrites.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / test / test_overwrites.py
CommitLineData
0c3d0f51 1#!/usr/bin/env python
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
11from test.helper import try_rm
12
13
14root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15download_file = join(root_dir, 'test.webm')
16
17
18class 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 [
7a5c1cfe 26 sys.executable, 'yt_dlp/__main__.py',
0c3d0f51 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 [
7a5c1cfe 38 sys.executable, 'yt_dlp/__main__.py', '--yes-overwrites',
0c3d0f51 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
51if __name__ == '__main__':
52 unittest.main()