aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2023-01-11 04:09:13 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2023-01-11 04:09:13 -0500
commitfe385c3ff784ba3d19454a35446502c0ec295893 (patch)
tree897982793ef2a0c0f349044bf4cf803ccd483e6e /test
parentebdfcd3cd3f76534a590ba08933ff7ea54813316 (diff)
New upstream version 1.24.3.upstream/1.24.3
Diffstat (limited to 'test')
-rw-r--r--test/test_extractor.py18
-rw-r--r--test/test_util.py87
-rw-r--r--test/test_ytdl.py20
3 files changed, 85 insertions, 40 deletions
diff --git a/test/test_extractor.py b/test/test_extractor.py
index de43ff7..144c6f9 100644
--- a/test/test_extractor.py
+++ b/test/test_extractor.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2018-2020 Mike Fährmann
+# Copyright 2018-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -96,9 +96,10 @@ class TestExtractorModule(unittest.TestCase):
test_urls = []
# collect testcase URLs
+ append = test_urls.append
for extr in extractor.extractors():
for testcase in extr._get_tests():
- test_urls.append((testcase[0], extr))
+ append((testcase[0], extr))
# iterate over all testcase URLs
for url, extr1 in test_urls:
@@ -114,20 +115,23 @@ class TestExtractorModule(unittest.TestCase):
match = extr2.pattern.match(url)
if match:
- matches.append(match)
+ matches.append((match, extr2))
# fail if more or less than 1 match happened
if len(matches) > 1:
msg = "'{}' gets matched by more than one pattern:".format(url)
- for match in matches:
- msg += "\n- "
- msg += match.re.pattern
+ for match, extr in matches:
+ msg += "\n\n- {}:\n{}".format(
+ extr.__name__, match.re.pattern)
self.fail(msg)
- if len(matches) < 1:
+ elif len(matches) < 1:
msg = "'{}' isn't matched by any pattern".format(url)
self.fail(msg)
+ else:
+ self.assertIs(extr1, matches[0][1], url)
+
def test_docstrings(self):
"""ensure docstring uniqueness"""
for extr1 in extractor.extractors():
diff --git a/test/test_util.py b/test/test_util.py
index 4b8f9ae..67fdf60 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -24,39 +24,62 @@ from gallery_dl import util, text, exception # noqa E402
class TestRange(unittest.TestCase):
- def test_parse_range(self, f=util.RangePredicate.parse_range):
- self.assertEqual(
- f(""),
- [])
- self.assertEqual(
- f("1-2"),
- [(1, 2)])
+ def test_parse_empty(self, f=util.RangePredicate._parse):
+ self.assertEqual(f(""), [])
+ self.assertEqual(f([]), [])
+
+ def test_parse_digit(self, f=util.RangePredicate._parse):
+ self.assertEqual(f("2"), [range(2, 3)])
+
self.assertEqual(
- f("-"),
- [(1, sys.maxsize)])
+ f("2, 3, 4"),
+ [range(2, 3),
+ range(3, 4),
+ range(4, 5)],
+ )
+
+ def test_parse_range(self, f=util.RangePredicate._parse):
+ self.assertEqual(f("1-2"), [range(1, 3)])
+ self.assertEqual(f("2-"), [range(2, sys.maxsize)])
+ self.assertEqual(f("-3"), [range(1, 4)])
+ self.assertEqual(f("-"), [range(1, sys.maxsize)])
+
self.assertEqual(
f("-2,4,6-8,10-"),
- [(1, 2), (4, 4), (6, 8), (10, sys.maxsize)])
+ [range(1, 3),
+ range(4, 5),
+ range(6, 9),
+ range(10, sys.maxsize)],
+ )
self.assertEqual(
f(" - 3 , 4- 4, 2-6"),
- [(1, 3), (4, 4), (2, 6)])
+ [range(1, 4),
+ range(4, 5),
+ range(2, 7)],
+ )
+
+ def test_parse_slice(self, f=util.RangePredicate._parse):
+ self.assertEqual(f("2:4") , [range(2, 4)])
+ self.assertEqual(f("3::") , [range(3, sys.maxsize)])
+ self.assertEqual(f(":4:") , [range(1, 4)])
+ self.assertEqual(f("::5") , [range(1, sys.maxsize, 5)])
+ self.assertEqual(f("::") , [range(1, sys.maxsize)])
+ self.assertEqual(f("2:3:4"), [range(2, 3, 4)])
- def test_optimize_range(self, f=util.RangePredicate.optimize_range):
- self.assertEqual(
- f([]),
- [])
- self.assertEqual(
- f([(2, 4)]),
- [(2, 4)])
- self.assertEqual(
- f([(2, 4), (6, 8), (10, 12)]),
- [(2, 4), (6, 8), (10, 12)])
self.assertEqual(
- f([(2, 4), (4, 6), (5, 8)]),
- [(2, 8)])
+ f("2:4, 4:, :4, :4:, ::4"),
+ [range(2, 4),
+ range(4, sys.maxsize),
+ range(1, 4),
+ range(1, 4),
+ range(1, sys.maxsize, 4)],
+ )
self.assertEqual(
- f([(1, 1), (2, 2), (3, 6), (8, 9)]),
- [(1, 6), (8, 9)])
+ f(" : 3 , 4: 4, 2:6"),
+ [range(1, 3),
+ range(4, 4),
+ range(2, 6)],
+ )
class TestPredicate(unittest.TestCase):
@@ -68,7 +91,7 @@ class TestPredicate(unittest.TestCase):
for i in range(6):
self.assertTrue(pred(dummy, dummy))
with self.assertRaises(exception.StopExtraction):
- bool(pred(dummy, dummy))
+ pred(dummy, dummy)
pred = util.RangePredicate("1, 3, 5")
self.assertTrue(pred(dummy, dummy))
@@ -77,11 +100,11 @@ class TestPredicate(unittest.TestCase):
self.assertFalse(pred(dummy, dummy))
self.assertTrue(pred(dummy, dummy))
with self.assertRaises(exception.StopExtraction):
- bool(pred(dummy, dummy))
+ pred(dummy, dummy)
pred = util.RangePredicate("")
with self.assertRaises(exception.StopExtraction):
- bool(pred(dummy, dummy))
+ pred(dummy, dummy)
def test_unique_predicate(self):
dummy = None
@@ -116,6 +139,14 @@ class TestPredicate(unittest.TestCase):
with self.assertRaises(exception.FilterError):
util.FilterPredicate("b > 1")(url, {"a": 2})
+ pred = util.FilterPredicate(["a < 3", "b < 4", "c < 5"])
+ self.assertTrue(pred(url, {"a": 2, "b": 3, "c": 4}))
+ self.assertFalse(pred(url, {"a": 3, "b": 3, "c": 4}))
+ self.assertFalse(pred(url, {"a": 2, "b": 4, "c": 4}))
+ self.assertFalse(pred(url, {"a": 2, "b": 3, "c": 5}))
+ with self.assertRaises(exception.FilterError):
+ pred(url, {"a": 2})
+
def test_build_predicate(self):
pred = util.build_predicate([])
self.assertIsInstance(pred, type(lambda: True))
diff --git a/test/test_ytdl.py b/test/test_ytdl.py
index eedb4f9..a273604 100644
--- a/test/test_ytdl.py
+++ b/test/test_ytdl.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2022 Mike Fährmann
+# Copyright 2022-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -262,11 +262,21 @@ class Test_CommandlineArguments_YtDlp(Test_CommandlineArguments):
def test_metadata_from_title(self):
opts = self._(["--metadata-from-title", "%(artist)s - %(title)s"])
+
+ try:
+ legacy = (self.module.version.__version__ < "2023.01.01")
+ except AttributeError:
+ legacy = True
+
+ actions = [self.module.MetadataFromFieldPP.to_action(
+ "title:%(artist)s - %(title)s")]
+ if not legacy:
+ actions = {"pre_process": actions}
+
self.assertEqual(opts["postprocessors"][0], {
- "key": "MetadataParser",
- "when": "pre_process",
- "actions": [self.module.MetadataFromFieldPP.to_action(
- "title:%(artist)s - %(title)s")],
+ "key" : "MetadataParser",
+ "when" : "pre_process",
+ "actions": actions,
})