mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-05-18 19:36:27 +02:00
[utils] traverse_obj
: Allow iterables in traversal (#6902)
Authored by: Grub4K
This commit is contained in:
parent
c16644642b
commit
21b5ec86c2
2 changed files with 7 additions and 4 deletions
|
@ -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: ...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue