mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[tests] support 'range()' for #count and metadata checks
This commit is contained in:
parent
d7aac9fc06
commit
642998504d
@ -48,6 +48,13 @@ class TestExtractorResults(unittest.TestCase):
|
|||||||
for url, exc in cls._skipped:
|
for url, exc in cls._skipped:
|
||||||
print('- {} ("{}")'.format(url, exc))
|
print('- {} ("{}")'.format(url, exc))
|
||||||
|
|
||||||
|
def assertRange(self, value, range, msg=None):
|
||||||
|
if range.step > 1:
|
||||||
|
self.assertIn(value, range, msg=msg)
|
||||||
|
else:
|
||||||
|
self.assertLessEqual(value, range.stop, msg=msg)
|
||||||
|
self.assertGreaterEqual(value, range.start, msg=msg)
|
||||||
|
|
||||||
def _run_test(self, result):
|
def _run_test(self, result):
|
||||||
result.pop("#comment", None)
|
result.pop("#comment", None)
|
||||||
only_matching = (len(result) <= 3)
|
only_matching = (len(result) <= 3)
|
||||||
@ -129,12 +136,15 @@ class TestExtractorResults(unittest.TestCase):
|
|||||||
|
|
||||||
if "#count" in result:
|
if "#count" in result:
|
||||||
count = result["#count"]
|
count = result["#count"]
|
||||||
|
len_urls = len(tjob.url_list)
|
||||||
if isinstance(count, str):
|
if isinstance(count, str):
|
||||||
self.assertRegex(count, r"^ *(==|!=|<|<=|>|>=) *\d+ *$")
|
self.assertRegex(count, r"^ *(==|!=|<|<=|>|>=) *\d+ *$")
|
||||||
expr = "{} {}".format(len(tjob.url_list), count)
|
expr = "{} {}".format(len_urls, count)
|
||||||
self.assertTrue(eval(expr), msg=expr)
|
self.assertTrue(eval(expr), msg=expr)
|
||||||
|
elif isinstance(count, range):
|
||||||
|
self.assertRange(len_urls, count)
|
||||||
else: # assume integer
|
else: # assume integer
|
||||||
self.assertEqual(len(tjob.url_list), count)
|
self.assertEqual(len_urls, count)
|
||||||
|
|
||||||
if "#pattern" in result:
|
if "#pattern" in result:
|
||||||
self.assertGreater(len(tjob.url_list), 0)
|
self.assertGreater(len(tjob.url_list), 0)
|
||||||
@ -159,6 +169,8 @@ class TestExtractorResults(unittest.TestCase):
|
|||||||
self._test_kwdict(value, test)
|
self._test_kwdict(value, test)
|
||||||
elif isinstance(test, type):
|
elif isinstance(test, type):
|
||||||
self.assertIsInstance(value, test, msg=key)
|
self.assertIsInstance(value, test, msg=key)
|
||||||
|
elif isinstance(test, range):
|
||||||
|
self.assertRange(value, test, msg=key)
|
||||||
elif isinstance(test, list):
|
elif isinstance(test, list):
|
||||||
subtest = False
|
subtest = False
|
||||||
for idx, item in enumerate(test):
|
for idx, item in enumerate(test):
|
||||||
|
Loading…
Reference in New Issue
Block a user