fix: add get_value() convenience function
This commit is contained in:
parent
fb1a7b22d8
commit
5ec0a8e82d
5 changed files with 102 additions and 1 deletions
|
|
@ -48,6 +48,32 @@ class TestAppHandler(FileTestCase):
|
|||
def test_get_enum(self):
|
||||
self.assertIs(self.app.get_enum(), wuttjamaican.enum)
|
||||
|
||||
def test_get_value(self):
|
||||
|
||||
class Object:
|
||||
def __init__(self, **kw):
|
||||
self.__dict__.update(kw)
|
||||
|
||||
class Dict(dict):
|
||||
pass
|
||||
|
||||
# dict object
|
||||
obj = {"foo": "bar"}
|
||||
self.assertEqual(self.app.get_value(obj, "foo"), "bar")
|
||||
|
||||
# object w/ attrs
|
||||
obj = Object(foo="bar")
|
||||
self.assertEqual(self.app.get_value(obj, "foo"), "bar")
|
||||
|
||||
# dict-like w/ attrs
|
||||
obj = Dict({"foo": "bar"})
|
||||
obj.baz = "yyy"
|
||||
self.assertEqual(self.app.get_value(obj, "baz"), "yyy")
|
||||
|
||||
# missing attr
|
||||
obj = Object(foo="bar")
|
||||
self.assertRaises(AttributeError, self.app.get_value, obj, "baz")
|
||||
|
||||
def test_load_object(self):
|
||||
|
||||
# just confirm the method works on a basic level; the
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue