aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.py
diff options
context:
space:
mode:
authorSimon Sawicki <contact@grub4k.xyz>2023-04-24 19:56:35 +0200
committerGitHub <noreply@github.com>2023-04-24 19:56:35 +0200
commit21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e (patch)
tree28515276d2458b18e19beb8cc86cf536855820b6 /test/test_utils.py
parentc16644642b08e2bf4130a6c5fa01395d8718c990 (diff)
downloadhypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.tar.lz
hypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.tar.xz
hypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.zip
[utils] `traverse_obj`: Allow iterables in traversal (#6902)
Authored by: Grub4K
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index d4a301583..f2f3b8170 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -2016,6 +2016,8 @@ Line 1
msg='nested `...` queries should work')
self.assertCountEqual(traverse_obj(_TEST_DATA, (..., ..., 'index')), range(4),
msg='`...` query result should be flattened')
+ self.assertEqual(traverse_obj(range(4), ...), list(range(4)),
+ msg='`...` should accept iterables')
# Test function as key
self.assertEqual(traverse_obj(_TEST_DATA, lambda x, y: x == 'urls' and isinstance(y, list)),
@@ -2023,6 +2025,8 @@ Line 1
msg='function as query key should perform a filter based on (key, value)')
self.assertCountEqual(traverse_obj(_TEST_DATA, lambda _, x: isinstance(x[0], str)), {'str'},
msg='exceptions in the query function should be catched')
+ self.assertEqual(traverse_obj(range(4), lambda _, x: x % 2 == 0), [0, 2],
+ msg='function key should accept iterables')
if __debug__:
with self.assertRaises(Exception, msg='Wrong function signature should raise in debug'):
traverse_obj(_TEST_DATA, lambda a: ...)