From 642998504db8511c773b10ce22e4904b91999428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 23 Sep 2023 17:54:53 +0200 Subject: [PATCH] [tests] support 'range()' for #count and metadata checks --- test/test_results.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/test_results.py b/test/test_results.py index 512ca219..f9ec9aeb 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -48,6 +48,13 @@ class TestExtractorResults(unittest.TestCase): for url, exc in cls._skipped: 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): result.pop("#comment", None) only_matching = (len(result) <= 3) @@ -129,12 +136,15 @@ class TestExtractorResults(unittest.TestCase): if "#count" in result: count = result["#count"] + len_urls = len(tjob.url_list) if isinstance(count, str): self.assertRegex(count, r"^ *(==|!=|<|<=|>|>=) *\d+ *$") - expr = "{} {}".format(len(tjob.url_list), count) + expr = "{} {}".format(len_urls, count) self.assertTrue(eval(expr), msg=expr) + elif isinstance(count, range): + self.assertRange(len_urls, count) else: # assume integer - self.assertEqual(len(tjob.url_list), count) + self.assertEqual(len_urls, count) if "#pattern" in result: self.assertGreater(len(tjob.url_list), 0) @@ -159,6 +169,8 @@ class TestExtractorResults(unittest.TestCase): self._test_kwdict(value, test) elif isinstance(test, type): self.assertIsInstance(value, test, msg=key) + elif isinstance(test, range): + self.assertRange(value, test, msg=key) elif isinstance(test, list): subtest = False for idx, item in enumerate(test):