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


Python UrlParser.is_canonically_equivalent方法代码示例

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


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

示例1: test_replace_subreddit

# 需要导入模块: from r2.lib.utils import UrlParser [as 别名]
# 或者: from r2.lib.utils.UrlParser import is_canonically_equivalent [as 别名]
    def test_replace_subreddit(self):
        test_cases = [
            ('/r/VIDEOS/', '/r/videos/', '/r/videos/'),
            ('/r/VIDEOS/new/', '/r/videos/', '/r/videos/new/'),
            ('/r/VIDEOS/new/#cats', '/r/videos/', '/r/videos/new/#cats'),
            ('/user/dave/m/cats/', '', '/user/dave/m/cats/'),
        ]

        for test_url, user_path, canonical_url in test_cases:
            subreddit = mock.create_autospec(BaseSite, spec_set=True)
            subreddit.user_path = user_path

            url = UrlParser(test_url).canonicalize_subreddit_path(subreddit)
            url.hostname = 'reddit'
            print test_url, user_path, canonical_url
            self.assertTrue(
                url.is_canonically_equivalent(canonical_url),
                '{0} is not equivalent to {1}'.format(
                    url, UrlParser(canonical_url)),
            )
开发者ID:zeantsoi,项目名称:reddit,代码行数:22,代码来源:urlparser_test.py

示例2: test_is_canonically_equivalent

# 需要导入模块: from r2.lib.utils import UrlParser [as 别名]
# 或者: from r2.lib.utils.UrlParser import is_canonically_equivalent [as 别名]
    def test_is_canonically_equivalent(self):

        test_cases = [
            ('/cats', '/cats', False),
            ('/cats/', '/cats/', True),
            ('/cats/', 'https://www.reddit.com/cats/', True),
            ('/cats#grumpy', '/cats#grumpy', False),
            ('/cats/#grumpy', '/cats/#grumpy', True),
            ('/cats/#grumpy', '/cats', True),
            ('/dogs?people=False', '/dogs?people=False', False),
            ('/dogs/?people=False', '/dogs/?people=False', True),
            ('/dogs/?cute=True&people=False',
             '/dogs/?people=False&cute=True', True),
        ]

        for test_url, canonical_url, assertion in test_cases:
            parsed = UrlParser(test_url)
            # this is to get around the need to patch the global request
            # object with the appropriate hostname.
            parsed.hostname = 'reddit'
            self.assertEquals(
                parsed.is_canonically_equivalent(canonical_url),
                assertion
            )
开发者ID:zeantsoi,项目名称:reddit,代码行数:26,代码来源:urlparser_test.py


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