本文整理汇总了Python中pystache.context._get_value函数的典型用法代码示例。如果您正苦于以下问题:Python _get_value函数的具体用法?Python _get_value怎么用?Python _get_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dictionary__callable_not_called
def test_dictionary__callable_not_called(self):
"""
Test that callable values are returned as-is (and in particular not called).
"""
def foo_callable(self):
return "bar"
item = {"foo": foo_callable}
self.assertNotEqual(_get_value(item, "foo"), "bar")
self.assertTrue(_get_value(item, "foo") is foo_callable)
示例2: test_object__attribute_is_callable
def test_object__attribute_is_callable(self):
"""
Test getting a callable attribute from an object.
"""
item = SimpleObject()
self.assertEqual(_get_value(item, "foo_callable"), "called...")
示例3: test_dictionary__key_present
def test_dictionary__key_present(self):
"""
Test getting a key from a dictionary.
"""
item = {"foo": "bar"}
self.assertEqual(_get_value(item, "foo"), "bar")
示例4: test_object__non_built_in_type
def test_object__non_built_in_type(self):
"""
Test getting an attribute from an instance of a type that isn't built-in.
"""
item = datetime(2012, 1, 2)
self.assertEqual(_get_value(item, "day"), 2)
示例5: test_object__attribute_present
def test_object__attribute_present(self):
"""
Test getting an attribute from an object.
"""
item = SimpleObject()
self.assertEqual(_get_value(item, "foo"), "bar")
示例6: test_built_in_type__integer
def test_built_in_type__integer(self):
"""
Test getting from an integer.
"""
class MyInt(int): pass
item1 = MyInt(10)
item2 = 10
try:
item2.real
except AttributeError:
# Then skip this unit test. The numeric type hierarchy was
# added only in Python 2.6, in which case integers inherit
# from complex numbers the "real" attribute, etc:
#
# http://docs.python.org/library/numbers.html
#
return
self.assertEquals(item1.real, 10)
self.assertEquals(item2.real, 10)
self.assertEquals(_get_value(item1, 'real'), 10)
self.assertNotFound(item2, 'real')
示例7: test_dictionary__dict_subclass
def test_dictionary__dict_subclass(self):
"""
Test that subclasses of dict are treated as dictionaries.
"""
class DictSubclass(dict): pass
item = DictSubclass()
item["foo"] = "bar"
self.assertEqual(_get_value(item, "foo"), "bar")
示例8: test_built_in_type__list
def test_built_in_type__list(self):
"""
Test getting from a list.
"""
class MyList(list): pass
item1 = MyList([1, 2, 3])
item2 = [1, 2, 3]
self.assertEqual(item1.pop(), 3)
self.assertEqual(item2.pop(), 3)
self.assertEqual(_get_value(item1, 'pop'), 2)
self.assertNotFound(item2, 'pop')
# get list items by index
self.assertEqual(_get_value(item2, '0'), 1)
# Don't throw errors if we pass a non-int to a list.
self.assertNotFound(item2, 'numberone')
示例9: test_built_in_type__list
def test_built_in_type__list(self):
"""
Test getting from a list.
"""
class MyList(list): pass
item1 = MyList([1, 2, 3])
item2 = [1, 2, 3]
self.assertEqual(item1.pop(), 3)
self.assertEqual(item2.pop(), 3)
self.assertEqual(_get_value(item1, 'pop'), 2)
self.assertNotFound(item2, 'pop')
示例10: test_built_in_type__string
def test_built_in_type__string(self):
"""
Test getting from a string.
"""
class MyStr(str): pass
item1 = MyStr('abc')
item2 = 'abc'
self.assertEqual(item1.upper(), 'ABC')
self.assertEqual(item2.upper(), 'ABC')
self.assertEqual(_get_value(item1, 'upper'), 'ABC')
self.assertNotFound(item2, 'upper')
示例11: test_built_in_type__integer
def test_built_in_type__integer(self):
"""
Test getting from an integer.
"""
class MyInt(int): pass
item1 = MyInt(10)
item2 = 10
self.assertEquals(item1.real, 10)
self.assertEquals(item2.real, 10)
self.assertEquals(_get_value(item1, 'real'), 10)
self.assertNotFound(item2, 'real')
示例12: test_built_in_type__string
def test_built_in_type__string(self):
"""
Test getting from a string.
"""
class MyStr(str):
pass
item1 = MyStr("abc")
item2 = "abc"
self.assertEqual(item1.upper(), "ABC")
self.assertEqual(item2.upper(), "ABC")
self.assertEqual(_get_value(item1, "upper"), "ABC")
self.assertNotFound(item2, "upper")
示例13: test_object__property__raising_exception
def test_object__property__raising_exception(self):
"""
Test getting a property that raises an exception.
"""
class Foo(object):
@property
def bar(self):
return 1
@property
def baz(self):
raise ValueError("test")
foo = Foo()
self.assertEqual(_get_value(foo, 'bar'), 1)
self.assertNotFound(foo, 'missing')
self.assertRaises(ValueError, _get_value, foo, 'baz')
示例14: test_built_in_type__integer
def test_built_in_type__integer(self):
"""
Test getting from an integer.
"""
class MyInt(int): pass
cust_int = MyInt(10)
pure_int = 10
# We have to use a built-in method like __neg__ because "public"
# attributes like "real" were not added to Python until Python 2.6,
# when the numeric type hierarchy was added:
#
# http://docs.python.org/library/numbers.html
#
self.assertEqual(cust_int.__neg__(), -10)
self.assertEqual(pure_int.__neg__(), -10)
self.assertEqual(_get_value(cust_int, '__neg__'), -10)
self.assertNotFound(pure_int, '__neg__')
示例15: assertNotFound
def assertNotFound(self, item, key):
"""
Assert that a call to _get_value() returns _NOT_FOUND.
"""
self.assertIs(_get_value(item, key), _NOT_FOUND)