You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.7 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. """Contains test cases for the parsers module."""
  4. from __future__ import unicode_literals
  5. import sys
  6. import os.path
  7. import unittest
  8. PATH = os.path.realpath(os.path.abspath(__file__))
  9. sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))
  10. try:
  11. from youtube_dl_gui.parsers import OptionsParser
  12. except ImportError as error:
  13. print error
  14. sys.exit(1)
  15. class TestParse(unittest.TestCase):
  16. """Test case for OptionsParser parse method."""
  17. def test_parse_to_audio_requirement_bug(self):
  18. """Test case for the 'to_audio' requirement."""
  19. options_dict = { # Extracted from youtube-dlG settings.json
  20. 'keep_video': False,
  21. 'opts_win_size': (640, 490),
  22. 'open_dl_dir': False,
  23. 'second_video_format': '0',
  24. 'native_hls': False,
  25. 'write_subs': False,
  26. 'workers_number': 3,
  27. 'max_downloads': 0,
  28. 'max_filesize': 0,
  29. 'youtube_dl_debug': False,
  30. 'shutdown': False,
  31. 'selected_format': 'mp3',
  32. 'write_all_subs': False,
  33. 'enable_log': True,
  34. 'embed_thumbnail': True,
  35. 'audio_quality': '9',
  36. 'subs_lang': 'en',
  37. 'audio_format': 'mp3',
  38. 'restrict_filenames': False,
  39. 'min_filesize_unit': '',
  40. 'selected_audio_formats': ['mp3', 'm4a', 'vorbis'],
  41. 'selected_video_formats': ['webm', 'mp4'],
  42. 'save_path': '/home/user/Workplace/test/youtube',
  43. 'output_template': '%(uploader)s/%(title)s.%(ext)s',
  44. 'show_completion_popup': True,
  45. 'locale_name': 'en_US',
  46. 'to_audio': False,
  47. 'confirm_deletion': True,
  48. 'min_filesize': 0,
  49. 'save_path_dirs': ['/home/user/Downloads', '/home/user/Desktop', '/home/user/Videos', '/home/user/Music', '/home/user/Workplace/test/youtube'],
  50. 'sudo_password': '',
  51. 'video_password': '',
  52. 'output_format': 1,
  53. 'embed_subs': False,
  54. 'write_auto_subs': False,
  55. 'video_format': '0',
  56. 'confirm_exit': False,
  57. 'referer': '',
  58. 'proxy': '',
  59. 'add_metadata': False,
  60. 'ignore_errors': False,
  61. 'log_time': True,
  62. 'password': '',
  63. 'playlist_end': 0,
  64. 'write_description': False,
  65. 'retries': 10,
  66. 'cmd_args': '',
  67. 'write_thumbnail': False,
  68. 'playlist_start': 1,
  69. 'nomtime': False,
  70. 'write_info': False,
  71. 'username': '',
  72. 'main_win_size': (930, 560),
  73. 'user_agent': '',
  74. 'max_filesize_unit': '',
  75. 'ignore_config': False,
  76. 'youtubedl_path': '/home/user/.config/youtube-dlg'
  77. }
  78. expected_cmd_list = ["--newline",
  79. "-x",
  80. "--audio-format",
  81. "mp3",
  82. "--embed-thumbnail",
  83. "--audio-quality",
  84. "9",
  85. "-o",
  86. "/home/user/Workplace/test/youtube/%(title)s.%(ext)s"]
  87. options_parser = OptionsParser()
  88. self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
  89. # Setting 'to_audio' to True should return the same results
  90. # since the '-x' flag is already set on audio extraction
  91. options_dict["to_audio"] = True
  92. self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
  93. def main():
  94. unittest.main()
  95. if __name__ == '__main__':
  96. main()