From 97d7990abde3fe4b525ae83958fd0b52d6a1d13f Mon Sep 17 00:00:00 2001 From: Theo Alexiou Date: Sun, 13 Feb 2022 17:27:12 +0100 Subject: Fixed #28358 -- Prevented LazyObject from mimicking nonexistent attributes. Thanks Sergey Fedoseev for the initial patch. --- tests/utils_tests/test_lazyobject.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/utils_tests/test_lazyobject.py') diff --git a/tests/utils_tests/test_lazyobject.py b/tests/utils_tests/test_lazyobject.py index 0ff15469d4..161c9dbcec 100644 --- a/tests/utils_tests/test_lazyobject.py +++ b/tests/utils_tests/test_lazyobject.py @@ -32,6 +32,28 @@ class LazyObjectTestCase(TestCase): return AdHocLazyObject() + def test_getattribute(self): + """ + Proxy methods don't exist on wrapped objects unless they're set. + """ + attrs = [ + "__getitem__", + "__setitem__", + "__delitem__", + "__iter__", + "__len__", + "__contains__", + ] + foo = Foo() + obj = self.lazy_wrap(foo) + for attr in attrs: + with self.subTest(attr): + self.assertFalse(hasattr(obj, attr)) + setattr(foo, attr, attr) + obj_with_attr = self.lazy_wrap(foo) + self.assertTrue(hasattr(obj_with_attr, attr)) + self.assertEqual(getattr(obj_with_attr, attr), attr) + def test_getattr(self): obj = self.lazy_wrap(Foo()) self.assertEqual(obj.foo, "bar") -- cgit v1.3