[YoutubeDL] format spec: add additional checks for invalid syntax
[youtube-dl] / test / test_YoutubeDL.py
index bf2baae07fe443b3865ea2b1e4e540b466cff84e..20f45f439748723998ce690cf54da55bfff34d29 100644 (file)
@@ -302,6 +302,16 @@ class TestFormatSelection(unittest.TestCase):
             downloaded = ydl.downloaded_info_dicts[0]
             self.assertEqual(downloaded['format_id'], f1['format_id'])
 
+    def test_invalid_format_specs(self):
+        def assert_syntax_error(format_spec):
+            ydl = YDL({'format': format_spec})
+            info_dict = _make_result([{'format_id': 'foo', 'url': TEST_URL}])
+            self.assertRaises(SyntaxError, ydl.process_ie_result, info_dict)
+
+        assert_syntax_error('bestvideo,,best')
+        assert_syntax_error('+bestaudio')
+        assert_syntax_error('bestvideo+')
+
     def test_format_filtering(self):
         formats = [
             {'format_id': 'A', 'filesize': 500, 'width': 1000},