summaryrefslogtreecommitdiff
path: root/tests/utils_tests/test_functional.py
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-06-07 12:34:35 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-06-12 06:09:20 +0200
commite042024b28fcef43606557554714352781fc1d13 (patch)
tree8534abd40c2836bd4035952bf688b4b7769a01f9 /tests/utils_tests/test_functional.py
parentfd97b0471b19cb45c4346e4947dfa7e69ff06158 (diff)
Allowed custom formatting of lazy() objects.
This allows for formatting of lazy objects which have a custom formatter defined by overriding the default implementation from `object`.
Diffstat (limited to 'tests/utils_tests/test_functional.py')
-rw-r--r--tests/utils_tests/test_functional.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py
index c8b8fe5a3f..fa23debb4d 100644
--- a/tests/utils_tests/test_functional.py
+++ b/tests/utils_tests/test_functional.py
@@ -246,6 +246,17 @@ class FunctionalTests(SimpleTestCase):
self.assertEqual(lazy_a() * 5, "aaaaa")
self.assertEqual(lazy_a() * lazy_5(), "aaaaa")
+ def test_lazy_format(self):
+ class QuotedString(str):
+ def __format__(self, format_spec):
+ value = super().__format__(format_spec)
+ return f"“{value}”"
+
+ lazy_f = lazy(lambda: QuotedString("Hello!"), QuotedString)
+ self.assertEqual(format(lazy_f(), ""), "“Hello!”")
+ f = lazy_f()
+ self.assertEqual(f"I said, {f}", "I said, “Hello!”")
+
def test_lazy_equality(self):
"""
== and != work correctly for Promises.