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


Python Pynliner.from_url方法代码示例

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


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

示例1: test_08_fromURL

# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import from_url [as 别名]
    def test_08_fromURL(self):
        """Test 'fromURL' constructor"""
        url = 'http://media.tannern.com/pynliner/test.html'
        p = Pynliner()
        p.from_url(url)
        self.assertEqual(p.root_url, 'http://media.tannern.com')
        self.assertEqual(p.relative_url, 'http://media.tannern.com/pynliner/')
        
        p._get_soup()
        
        p._get_external_styles()
        self.assertEqual(p.style_string, "p {color: #999}")
        
        p._get_internal_styles()
        self.assertEqual(p.style_string, "p {color: #999}\nh1 {color: #ffcc00;}\n")
        
        p._get_styles()
        
        output = p.run()
        desired = u"""<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>


</head>
<body>
<h1 style="color: #fc0">Hello World!</h1>
<p style="color: #999">Possim tincidunt putamus iriure eu nulla. Facer qui volutpat ut aliquam sequitur. Mutationem legere feugiat autem clari notare. Nulla typi augue suscipit lectores in.</p>
<p style="color: #999">Facilisis claritatem eum decima dignissim legentis. Nulla per legentis odio molestie quarta. Et velit typi claritas ipsum ullamcorper.</p>
</body>
</html>"""
        self.assertEqual(output, desired) 
开发者ID:ananelson,项目名称:pynliner,代码行数:35,代码来源:tests.py

示例2: test_fromURL

# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import from_url [as 别名]
    def test_fromURL(self):
        """Test 'fromURL' constructor"""
        url = 'http://media.tannern.com/pynliner/test.html'
        p = Pynliner()
        with mock.patch.object(Pynliner, '_get_url') as mocked:
            mocked.return_value = u"""<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<link rel="stylesheet" type="text/css" href="test.css"/>
<style type="text/css">h1 {color: #fc0;}</style>
</head>
<body>
<h1>Hello World!</h1>
<p>:)</p>
</body>
</html>"""
            p.from_url(url)
        self.assertEqual(p.root_url, 'http://media.tannern.com')
        self.assertEqual(p.relative_url, 'http://media.tannern.com/pynliner/')

        p._get_soup()

        with mock.patch.object(Pynliner, '_get_url') as mocked:
            mocked.return_value = 'p {color: #999}'
            p._get_external_styles()
        self.assertEqual(p.style_string, "p {color: #999}")

        p._get_internal_styles()
        self.assertEqual(p.style_string, "p {color: #999}\nh1 {color: #fc0;}\n")

        p._get_styles()

        output = p.run()
        desired = u"""<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>


</head>
<body>
<h1 style="color: #fc0">Hello World!</h1>
<p style="color: #999">:)</p>
</body>
</html>"""
        self.assertEqual(output, desired)
开发者ID:dcramer,项目名称:pynliner,代码行数:49,代码来源:tests.py

示例3: test_08_fromURL

# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import from_url [as 别名]
    def test_08_fromURL(self):
        """Test 'fromURL' constructor"""
        url = 'https://raw.github.com/voidfiles/pynliner/master/test_data/test.html'
        p = Pynliner()
        p.from_url(url)
        self.assertEqual(p.root_url, 'https://raw.github.com')
        self.assertEqual(p.relative_url, 'https://raw.github.com/voidfiles/pynliner/master/test_data/')

        p._get_soup()

        p._get_external_styles()
        self.assertEqual(p.style_string, "p {color: #999}")

        p._get_internal_styles()
        self.assertEqual(p.style_string, "p {color: #999}\nh1 {color: #ffcc00;}")

        p._get_styles()

        output = p.run()
        desired = u"""<html><head></head><body>\n        <h1 style="color: #fc0">Testing Title</h1>\n        <p style="color: #999">Awesome</p>\n    </body></html>"""
        self.assertEqual(output, desired)
开发者ID:voidfiles,项目名称:pynliner,代码行数:23,代码来源:tests.py


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