2021-06-03 03:43:42 -06:00
|
|
|
#!/usr/bin/env python3
|
2022-06-24 05:06:16 -06:00
|
|
|
|
|
|
|
# Allow direct execution
|
2019-10-13 10:00:48 -06:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
2022-04-11 16:32:57 -06:00
|
|
|
|
2019-10-13 10:00:48 -06:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2022-06-24 05:06:16 -06:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
2021-08-07 05:20:46 -06:00
|
|
|
from test.helper import is_download_test, try_rm
|
2019-10-13 10:00:48 -06:00
|
|
|
|
|
|
|
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
2022-04-11 18:01:54 -06:00
|
|
|
download_file = os.path.join(root_dir, 'test.webm')
|
2019-10-13 10:00:48 -06:00
|
|
|
|
|
|
|
|
2021-08-07 05:20:46 -06:00
|
|
|
@is_download_test
|
2019-10-13 10:00:48 -06:00
|
|
|
class TestOverwrites(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
# create an empty file
|
|
|
|
open(download_file, 'a').close()
|
|
|
|
|
|
|
|
def test_default_overwrites(self):
|
|
|
|
outp = subprocess.Popen(
|
|
|
|
[
|
2021-02-24 11:45:56 -07:00
|
|
|
sys.executable, 'yt_dlp/__main__.py',
|
2019-10-13 10:00:48 -06:00
|
|
|
'-o', 'test.webm',
|
2024-06-11 17:09:58 -06:00
|
|
|
'https://www.youtube.com/watch?v=jNQXAC9IVRw',
|
2019-10-13 10:00:48 -06:00
|
|
|
], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
sout, serr = outp.communicate()
|
|
|
|
self.assertTrue(b'has already been downloaded' in sout)
|
|
|
|
# if the file has no content, it has not been redownloaded
|
|
|
|
self.assertTrue(os.path.getsize(download_file) < 1)
|
|
|
|
|
|
|
|
def test_yes_overwrites(self):
|
|
|
|
outp = subprocess.Popen(
|
|
|
|
[
|
2021-02-24 11:45:56 -07:00
|
|
|
sys.executable, 'yt_dlp/__main__.py', '--yes-overwrites',
|
2019-10-13 10:00:48 -06:00
|
|
|
'-o', 'test.webm',
|
2024-06-11 17:09:58 -06:00
|
|
|
'https://www.youtube.com/watch?v=jNQXAC9IVRw',
|
2019-10-13 10:00:48 -06:00
|
|
|
], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
sout, serr = outp.communicate()
|
|
|
|
self.assertTrue(b'has already been downloaded' not in sout)
|
|
|
|
# if the file has no content, it has not been redownloaded
|
|
|
|
self.assertTrue(os.path.getsize(download_file) > 1)
|
|
|
|
|
|
|
|
def tearDown(self):
|
2022-04-11 18:01:54 -06:00
|
|
|
try_rm(os.path.join(root_dir, 'test.webm'))
|
2019-10-13 10:00:48 -06:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|