aboutsummaryrefslogtreecommitdiff
path: root/test/test_utils.py
diff options
context:
space:
mode:
authorbashonly <88596187+bashonly@users.noreply.github.com>2024-10-30 21:53:41 +0000
committerGitHub <noreply@github.com>2024-10-30 21:53:41 +0000
commitb6dc2c49e8793c6dfa21275e61caf49ec1148b81 (patch)
tree68e44258d8f6aba23f71e449316639008bfd3a4c /test/test_utils.py
parent76802f461332d444e596437c42374fa237fa5174 (diff)
[utils] Allow partial application for more functions (#11391)
Also adds the `trim_str` traversal helper Authored by: bashonly, Grub4K Co-authored-by: Simon Sawicki <contact@grub4k.xyz>
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index d4b846f56..04f91547a 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -4,6 +4,7 @@
import os
import sys
import unittest
+import unittest.mock
import warnings
import datetime as dt
@@ -71,6 +72,7 @@ from yt_dlp.utils import (
intlist_to_bytes,
iri_to_uri,
is_html,
+ join_nonempty,
js_to_json,
limit_length,
locked_file,
@@ -343,11 +345,13 @@ class TestUtil(unittest.TestCase):
self.assertEqual(remove_start(None, 'A - '), None)
self.assertEqual(remove_start('A - B', 'A - '), 'B')
self.assertEqual(remove_start('B - A', 'A - '), 'B - A')
+ self.assertEqual(remove_start('non-empty', ''), 'non-empty')
def test_remove_end(self):
self.assertEqual(remove_end(None, ' - B'), None)
self.assertEqual(remove_end('A - B', ' - B'), 'A')
self.assertEqual(remove_end('B - A', ' - B'), 'B - A')
+ self.assertEqual(remove_end('non-empty', ''), 'non-empty')
def test_remove_quotes(self):
self.assertEqual(remove_quotes(None), None)
@@ -2148,6 +2152,16 @@ Line 1
assert run_shell(args) == expected
assert run_shell(shell_quote(args, shell=True)) == expected
+ def test_partial_application(self):
+ assert callable(int_or_none(scale=10)), 'missing positional parameter should apply partially'
+ assert int_or_none(10, scale=0.1) == 100, 'positionally passed argument should call function'
+ assert int_or_none(v=10) == 10, 'keyword passed positional should call function'
+ assert int_or_none(scale=0.1)(10) == 100, 'call after partial applicatino should call the function'
+
+ assert callable(join_nonempty(delim=', ')), 'varargs positional should apply partially'
+ assert callable(join_nonempty()), 'varargs positional should apply partially'
+ assert join_nonempty(None, delim=', ') == '', 'passed varargs should call the function'
+
if __name__ == '__main__':
unittest.main()