summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2022-08-09 19:34:34 +0100
committerdirkf <fieldhouse@gmx.net>2022-10-11 00:05:17 +0100
commit2ced5a79128f53faad94dc494d05925eb957c414 (patch)
tree0fc1820ec2357d4cddaa77cb67dd63bef11b2b6b
parent82e4eca711a128138ed0b84ddb4321e403d56340 (diff)
downloadyoutube-dl-2ced5a79128f53faad94dc494d05925eb957c414.tar.gz
youtube-dl-2ced5a79128f53faad94dc494d05925eb957c414.tar.xz
[test] Implement string "lambda x: condition(x)" as an expected value
Semantics equivalent to `assert condition(got)`
-rw-r--r--test/helper.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/test/helper.py b/test/helper.py
index e62aab11e..c6a2f0667 100644
--- a/test/helper.py
+++ b/test/helper.py
@@ -128,6 +128,12 @@ def expect_value(self, got, expected, field):
self.assertTrue(
contains_str in got,
'field %s (value: %r) should contain %r' % (field, got, contains_str))
+ elif isinstance(expected, compat_str) and re.match(r'^lambda \w+:', expected):
+ fn = eval(expected)
+ suite = expected.split(':', 1)[1].strip()
+ self.assertTrue(
+ fn(got),
+ 'Expected field %s to meet condition %s, but value %r failed ' % (field, suite, got))
elif isinstance(expected, type):
self.assertTrue(
isinstance(got, expected),
@@ -137,7 +143,7 @@ def expect_value(self, got, expected, field):
elif isinstance(expected, list) and isinstance(got, list):
self.assertEqual(
len(expected), len(got),
- 'Expect a list of length %d, but got a list of length %d for field %s' % (
+ 'Expected a list of length %d, but got a list of length %d for field %s' % (
len(expected), len(got), field))
for index, (item_got, item_expected) in enumerate(zip(got, expected)):
type_got = type(item_got)

Generated by cgit