本文整理汇总了Python中pynliner.Pynliner._get_external_styles方法的典型用法代码示例。如果您正苦于以下问题:Python Pynliner._get_external_styles方法的具体用法?Python Pynliner._get_external_styles怎么用?Python Pynliner._get_external_styles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynliner.Pynliner
的用法示例。
在下文中一共展示了Pynliner._get_external_styles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_08_fromURL
# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import _get_external_styles [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)
示例2: test_fromURL
# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import _get_external_styles [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)
示例3: test_08_fromURL
# 需要导入模块: from pynliner import Pynliner [as 别名]
# 或者: from pynliner.Pynliner import _get_external_styles [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)