test_overwrites.py 1.7 KB

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