3
0
Fork 0

fix: add get_value() convenience function

This commit is contained in:
Lance Edgar 2026-02-16 18:11:11 -06:00
parent fb1a7b22d8
commit 5ec0a8e82d
5 changed files with 102 additions and 1 deletions

View file

@ -41,6 +41,35 @@ class TestGetClassHierarchy(TestCase):
self.assertEqual(classes, [C, B, A])
class TestGetValue(TestCase):
def test_basic(self):
class Object:
def __init__(self, **kw):
self.__dict__.update(kw)
class Dict(dict):
pass
# dict object
obj = {"foo": "bar"}
self.assertEqual(mod.get_value(obj, "foo"), "bar")
# object w/ attrs
obj = Object(foo="bar")
self.assertEqual(mod.get_value(obj, "foo"), "bar")
# dict-like w/ attrs
obj = Dict({"foo": "bar"})
obj.baz = "yyy"
self.assertEqual(mod.get_value(obj, "baz"), "yyy")
# missing attr
obj = Object(foo="bar")
self.assertRaises(AttributeError, mod.get_value, obj, "baz")
class TestLoadEntryPoints(TestCase):
def test_empty(self):