Browse Source

Test the 'cmd_args' option parsing when quotes are presented

doc-issue-template
MrS0m30n3 7 years ago
parent
commit
4a01626f9b
1 changed files with 137 additions and 0 deletions
  1. 137
      tests/test_parsers.py

137
tests/test_parsers.py

@ -106,6 +106,143 @@ class TestParse(unittest.TestCase):
self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
def test_parse_cmd_args_with_quotes(self):
"""Test the youtube-dl cmd line args parsing when quotes are presented.
See: https://github.com/MrS0m30n3/youtube-dl-gui/issues/54
"""
options_dict = {
"keep_video": False,
"opts_win_size": (640, 490),
"open_dl_dir": False,
"second_video_format": "0",
"native_hls": False,
"write_subs": False,
"sudo_password": "",
"workers_number": 3,
"max_filesize": 0,
"youtube_dl_debug": False,
"shutdown": False,
"selected_format": "mp4",
"write_all_subs": False,
"enable_log": True,
"embed_thumbnail": False,
"audio_quality": "5",
"main_win_size": (930, 560),
"restrict_filenames": False,
"min_filesize_unit": "",
"video_password": "",
"selected_audio_formats": [
"mp3",
"m4a",
"vorbis"
],
"selected_video_formats": [
"webm",
"mp4"
],
"save_path": "/home/user/Workplace/test/youtube",
"output_template": "%(uploader)s/%(title)s.%(ext)s",
"show_completion_popup": True,
"locale_name": "en_US",
"to_audio": False,
"confirm_deletion": True,
"min_filesize": 0,
"save_path_dirs": [
"/home/user/Downloads",
"/home/user/Desktop",
"/home/user/Videos",
"/home/user/Music",
"/home/user/Workplace/test/youtube"
],
"audio_format": "",
"max_downloads": 0,
"output_format": 1,
"embed_subs": False,
"write_auto_subs": False,
"video_format": "mp4",
"confirm_exit": False,
"referer": "",
"proxy": "",
"add_metadata": False,
"ignore_errors": False,
"log_time": True,
"password": "",
"playlist_end": 0,
"write_description": False,
"retries": 10,
"cmd_args": "--recode-video mkv --postprocessor-args \"-codec copy -report\"",
"write_thumbnail": False,
"playlist_start": 1,
"nomtime": False,
"write_info": False,
"username": "",
"subs_lang": "en",
"user_agent": "",
"max_filesize_unit": "",
"ignore_config": False,
"youtubedl_path": "/home/user/.config/youtube-dlg"
}
expected_cmd_list = ["--newline",
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
"--recode-video",
"mkv",
"--postprocessor-args",
"-codec copy -report"]
options_parser = OptionsParser()
self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
# Test the example presented in issue #54
options_dict["cmd_args"] = "-f \"(mp4)[width<1300]\""
options_dict["video_format"] = "0" # Set video format to 'default'
expected_cmd_list = ["--newline",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
"-f",
"(mp4)[width<1300]"]
self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
# Test with two quoted 'cmd_args'
options_dict["cmd_args"] = "--postprocessor-args \"-y -report\""
options_dict["video_format"] = "mp4" # Set video format back to 'mp4'
expected_cmd_list = ["--newline",
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
"--postprocessor-args",
"-y -report"]
self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
# Test with single quoted 'cmd_arg' followed by other cmd line args
options_dict["cmd_args"] = "--postprocessor-args \"-y\" -v"
expected_cmd_list = ["--newline",
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
"--postprocessor-args",
"-y",
"-v"]
self.assertItemsEqual(options_parser.parse(options_dict), expected_cmd_list)
def main():
unittest.main()

Loading…
Cancel
Save