• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python context._get_value函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
开发者ID:foursquare,项目名称:pystache,代码行数:11,代码来源:test_context.py


示例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...")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py


示例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")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py


示例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)
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py


示例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")
开发者ID:foursquare,项目名称:pystache,代码行数:7,代码来源:test_context.py


示例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')
开发者ID:chuanzhang,项目名称:pystache,代码行数:26,代码来源:test_context.py


示例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")
开发者ID:foursquare,项目名称:pystache,代码行数:11,代码来源:test_context.py


示例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')
开发者ID:mintchaos,项目名称:pystache,代码行数:21,代码来源:test_context.py


示例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')
开发者ID:foursquare,项目名称:pystache,代码行数:15,代码来源:test_context.py


示例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')
开发者ID:foursquare,项目名称:pystache,代码行数:15,代码来源:test_context.py


示例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')
开发者ID:jakearchibald,项目名称:pystache,代码行数:15,代码来源:test_context.py


示例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")
开发者ID:phihag,项目名称:py3stache,代码行数:17,代码来源:test_context.py


示例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')
开发者ID:foursquare,项目名称:pystache,代码行数:19,代码来源:test_context.py


示例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__')
开发者ID:foursquare,项目名称:pystache,代码行数:21,代码来源:test_context.py


示例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)
开发者ID:foursquare,项目名称:pystache,代码行数:6,代码来源:test_context.py



注:本文中的pystache.context._get_value函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python context.Context类代码示例发布时间:2022-05-27
下一篇:
Python pystache.TemplateSpec类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap