diff options
| author | dirkf <fieldhouse@gmx.net> | 2025-11-01 20:24:43 +0000 |
|---|---|---|
| committer | dirkf <fieldhouse@gmx.net> | 2025-11-21 01:52:11 +0000 |
| commit | 23a848c3141ad2ba1e7bb62708f5ed72ef81c98a (patch) | |
| tree | 652f25823c6181222c72e940ac45b9dafd5f39d1 /test/test_utils.py | |
| parent | a96a77875023407233bae4111a36d113b756a4e3 (diff) | |
[utils] Add `partial_application` decorator function
Thx: yt-dlp/yt-dlp#10653
Diffstat (limited to 'test/test_utils.py')
| -rw-r--r-- | test/test_utils.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index 2947cce7e..9aca4df63 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -69,6 +69,7 @@ from youtube_dl.utils import ( parse_iso8601, parse_resolution, parse_qs, + partial_application, pkcs1pad, prepend_extension, read_batch_urls, @@ -1723,6 +1724,21 @@ Line 1 'a', 'b', 'c', 'd', from_dict={'a': 'c', 'c': [], 'b': 'd', 'd': None}), 'c-d') + def test_partial_application(self): + test_fn = partial_application(lambda x, kwarg=None: '{0}, kwarg={1!r}'.format(x, kwarg)) + self.assertTrue( + callable(test_fn(kwarg=10)), + 'missing positional parameter should apply partially') + self.assertEqual( + test_fn(10, kwarg=0.1), '10, kwarg=0.1', + 'positionally passed argument should call function') + self.assertEqual( + test_fn(x=10), '10, kwarg=None', + 'keyword passed positional should call function') + self.assertEqual( + test_fn(kwarg=0.1)(10), '10, kwarg=0.1', + 'call after partial application should call the function') + if __name__ == '__main__': unittest.main() |
