当前位置: 首页>>代码示例>>Python>>正文


Python UrlDispatcher.resources方法代码示例

本文整理汇总了Python中aiohttp.web.UrlDispatcher.resources方法的典型用法代码示例。如果您正苦于以下问题:Python UrlDispatcher.resources方法的具体用法?Python UrlDispatcher.resources怎么用?Python UrlDispatcher.resources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.web.UrlDispatcher的用法示例。


在下文中一共展示了UrlDispatcher.resources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestUrlDispatcher

# 需要导入模块: from aiohttp.web import UrlDispatcher [as 别名]
# 或者: from aiohttp.web.UrlDispatcher import resources [as 别名]

#.........这里部分代码省略.........
            route._sendfile_cb(fut, out_fd, in_fd, 0, 100, loop, False)
            m_os.sendfile.assert_called_with(out_fd, in_fd, 0, 100)
            self.assertTrue(fut.done())
            self.assertIs(exc, fut.exception())
            self.assertFalse(loop.add_writer.called)
            self.assertFalse(loop.remove_writer.called)

    def fill_routes(self):
        route1 = self.router.add_route('GET', '/plain', self.make_handler())
        route2 = self.router.add_route('GET', '/variable/{name}',
                                       self.make_handler())
        route3 = self.router.add_static('/static',
                                        os.path.dirname(aiohttp.__file__))
        return route1, route2, route3

    def test_routes_view_len(self):
        self.fill_routes()
        self.assertEqual(3, len(self.router.routes()))

    def test_routes_view_iter(self):
        routes = self.fill_routes()
        self.assertEqual(list(routes), list(self.router.routes()))

    def test_routes_view_contains(self):
        routes = self.fill_routes()
        for route in routes:
            self.assertIn(route, self.router.routes())

    def test_routes_abc(self):
        self.assertIsInstance(self.router.routes(), Sized)
        self.assertIsInstance(self.router.routes(), Iterable)
        self.assertIsInstance(self.router.routes(), Container)

    def fill_named_resources(self):
        route1 = self.router.add_route('GET', '/plain', self.make_handler(),
                                       name='route1')
        route2 = self.router.add_route('GET', '/variable/{name}',
                                       self.make_handler(), name='route2')
        route3 = self.router.add_static('/static',
                                        os.path.dirname(aiohttp.__file__),
                                        name='route3')
        return route1.name, route2.name, route3.name

    def test_named_routes_abc(self):
        self.assertIsInstance(self.router.named_routes(), Mapping)
        self.assertNotIsInstance(self.router.named_routes(), MutableMapping)

    def test_named_resources_abc(self):
        self.assertIsInstance(self.router.named_resources(), Mapping)
        self.assertNotIsInstance(self.router.named_resources(), MutableMapping)

    def test_named_routes(self):
        self.fill_named_resources()

        with self.assertWarns(DeprecationWarning):
            self.assertEqual(3, len(self.router.named_routes()))

    def test_named_resources(self):
        names = self.fill_named_resources()

        self.assertEqual(3, len(self.router.named_resources()))

        for name in names:
            self.assertIn(name, self.router.named_routes())
            self.assertIsInstance(self.router.named_routes()[name],
                                  AbstractResource)
开发者ID:1st1,项目名称:aiohttp,代码行数:70,代码来源:test_urldispatch.py


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