def test_canonical(): r = create_request('', '') p = create_presentation(True) h = html.Renderer() assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href=""></head><body></body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="" rel="canonical"></head><body></body></html>' r = create_request('', '') p = create_presentation(True) h = html.Renderer() h.head << h.head.link(rel='canonical', href='/bar') assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/bar"></head><body></body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/bar" rel="canonical"></head><body></body></html>' r = create_request('/foo', '') p = create_presentation(True) h = html.Renderer() assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/foo"></head><body></body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/foo" rel="canonical"></head><body></body></html>' r = create_request('/foo', '') p = create_presentation(True) h = html.Renderer() h.head << h.head.link(rel='canonical', href='/bar') assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/bar"></head><body></body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/bar" rel="canonical"></head><body></body></html>'
def test_14(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.head.head << h.body assert merge_head(p, r, h) == b'<html><head></head><body></body></html>'
def test_parse9(): h = html.Renderer() root = h.fromstring('<a>text</a><b>text</b>', fragment=True) assert isinstance(root, tuple) assert len(root) == 2 assert root[0].tostring() == b'<a>text</a>' assert root[1].tostring() == b'<b>text</b>'
def test_absolute_asset_url5(): h = html.Renderer(static_url='/static/root2') assert h.absolute_asset_url('', '/static/root') == '/static/root/' assert h.absolute_asset_url('/', '/static/root') == '/' assert h.absolute_asset_url('/abc', '/static/root') == '/abc' assert h.absolute_asset_url('http://abc', '/static/root') == 'http://abc' assert h.absolute_asset_url('abc', '') == '/abc' assert h.absolute_asset_url('abc/', '') == '/abc/' assert h.absolute_asset_url('abc', '/static/root') == '/static/root/abc' assert h.absolute_asset_url('abc', '/static/root/') == '/static/root/abc' assert h.absolute_asset_url('abc/', '/static/root') == '/static/root/abc/' assert h.absolute_asset_url('abc/', '/static/root/') == '/static/root/abc/' assert h.absolute_asset_url('') == '/static/root2/' assert h.absolute_asset_url('/') == '/' assert h.absolute_asset_url('/abc') == '/abc' assert h.absolute_asset_url('http://abc') == 'http://abc' assert h.absolute_asset_url('abc', '') == '/abc' assert h.absolute_asset_url('abc/', '') == '/abc/' assert h.absolute_asset_url('abc') == '/static/root2/abc' assert h.absolute_asset_url('abc') == '/static/root2/abc' assert h.absolute_asset_url('abc/') == '/static/root2/abc/' assert h.absolute_asset_url('abc/') == '/static/root2/abc/'
def test_html1(): h = html.Renderer() assert h.div(h.p('test')).tostring() == b'<div><p>test</p></div>' with pytest.raises(AttributeError): h.foo
def test_3(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.p('hello') assert merge_head( p, r, h) == b'<html><head></head><body><p>hello</p></body></html>'
def test_16(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.head.head << 'hello' << h.body << 'world' assert merge_head( p, r, h) == b'<html><head></head>hello<body></body>world</html>'
def test_parse6(): h = html.Renderer() root = h.fromstring('<a>text</a>') assert type(root) == html.Tag x = xml.Renderer() root = x.fromstring('<a>text</a>') assert type(root) == xml.Tag
def test_18(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.html(id='foo') << 'hello' assert merge_head( p, r, h) == [b'<html id="foo"><head/><body/></html>', b'hello']
def test_parse3(): """ XHTML namespace unit test - HTMLRender - parse_html - bad encoding """ h = html.Renderer() filename = os.path.join(os.path.dirname(__file__), 'iso-8859.xml') with pytest.raises(UnicodeDecodeError): h.fromfile(filename, encoding='utf-8') h.fromfile(filename, encoding='iso8859-1')
def test_19(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.comment('c1') << h.html << 'hello' << h.comment('c2') assert merge_head(p, r, h) == [ b'<!--c1-->', b'<html><head/><body/></html>', b'hello', b'<!--c2-->' ]
def test_2(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.comment('c1') << 'hello' << h.comment('c2') assert merge_head( p, r, h) == b'<html><head></head><body><!--c1-->hello<!--c2--></body></html>'
def test_39(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.processing_instruction('hello') << h.html(h.p('foo')) assert merge_head(p, r, h) == [ b'<?hello ?>', b'<html><head/><body><p>foo</p></body></html>' ]
def test_40(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.html(h.p('foo'), id='html') assert merge_head( p, r, h) == b'<html id="html"><head></head><body><p>foo</p></body></html>'
def test_cache_buster(): h = html.Renderer(assets_version='1.2') assert h.a(href='/abc').tostring() == b'<a href="/abc"></a>' assert h.a(href='abc').tostring() == b'<a href="abc"></a>' assert h.head.link(rel='stylesheet', href='/abc').get('href') == '/abc' assert h.head.link(rel='stylesheet', href='abc').get('href') == '/abc?ver=1.2' assert h.head.link(rel='next', href='/abc').get('href') == '/abc' assert h.head.link(rel='next', href='abc').get('href') == 'abc' assert h.script(src='/abc').tostring() == b'<script src="/abc"></script>' assert h.script( src='abc').tostring() == b'<script src="/abc?ver=1.2"></script>' h = html.Renderer(static_url='/root', assets_version='1.2') assert h.a(href='/abc').tostring() == b'<a href="/abc"></a>' assert h.a(href='abc').tostring() == b'<a href="abc"></a>' assert h.head.link(rel='stylesheet', href='/abc').get('href') == '/abc' assert h.head.link(rel='stylesheet', href='abc').get('href') == '/root/abc?ver=1.2' assert h.head.link(rel='next', href='/abc').get('href') == '/abc' assert h.head.link(rel='next', href='abc').get('href') == 'abc' assert h.script(src='/abc').tostring() == b'<script src="/abc"></script>' assert h.script( src='abc').tostring() == b'<script src="/root/abc?ver=1.2"></script>' h = html.Renderer(static_url='/root', assets_version='1.2') assert h.script(src='/abc?foo=bar').tostring( ) == b'<script src="/abc?foo=bar"></script>' assert h.script(src='abc?foo=bar').tostring( ) == b'<script src="/root/abc?foo=bar&ver=1.2"></script>' assert h.script(src='/abc?foo=bar&hello=world').tostring( ) == b'<script src="/abc?foo=bar&hello=world"></script>' assert h.script(src='abc?foo=bar&hello=world').tostring( ) == b'<script src="/root/abc?foo=bar&hello=world&ver=1.2"></script>'
def test_46(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.body(h.p('foo'), id="body") assert merge_head( p, r, h) == b'<html><head></head><body id="body"><p>foo</p></body></html>' r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h.head.javascript_url('/foo.js') h << h.body(h.p('foo'), id="body") result = merge_head(p, r, h) assert result == b'<html><head><script type="text/javascript" src="/foo.js"></script></head><body id="body"><p>foo</p></body></html>' \ or result == b'<html><head><script src="/foo.js" type="text/javascript"></script></head><body id="body"><p>foo</p></body></html>'
def test_44(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << [h.head.head(h.head.title, id='head'), h.p('foo')] assert merge_head( p, r, h ) == b'<html><head id="head"><title></title></head><body><p>foo</p></body></html>' r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h.head.javascript_url('/foo.js') h << [h.head.head(h.head.title, id='head'), h.p('foo')] result = merge_head(p, r, h) assert result == b'<html><head id="head"><title></title><script type="text/javascript" src="/foo.js"></script></head><body><p>foo</p></body></html>' \ or result == b'<html><head id="head"><title></title><script src="/foo.js" type="text/javascript"></script></head><body><p>foo</p></body></html>'
def test_new_tags(): h = html.Renderer() with pytest.raises(AttributeError): h.section h = html5.Renderer() root = h.section assert root.tostring() == b'<section></section>'
def test_obsolete_tags(): h = html.Renderer() root = h.center assert root.tostring() == b'<center></center>' h = html5.Renderer() with pytest.raises(AttributeError): h.center
def test_28(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() with h.html: h << h.head.head << 'hello' assert merge_head(p, r, h) == b'<html><head></head><body>hello</body></html>'
def test_17(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.comment('c1') << h.head.head << h.p('hello') << h.comment( 'c2') << h.body('world') << h.comment('c3') assert merge_head( p, r, h ) == b'<html><!--c1--><head></head><p>hello</p><!--c2--><body>world</body><!--c3--></html>'
def test_25(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() with h.html: h << h.comment('c1') << h.body(h.p('hello')) << h.comment('c2') assert merge_head( p, r, h ) == b'<html><head></head><!--c1--><body><p>hello</p></body><!--c2--></html>'
def test_38(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h << h.processing_instruction('hello') << h.p( 'foo') << h.processing_instruction('world') assert merge_head( p, r, h ) == b'<html><head></head><body><?hello ><p>foo</p><?world ></body></html>'
def test_37(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h.head << h.head.head(id='header_id') h << h.head.head(class_='header_class') << h.p('foo') assert merge_head( p, r, h ) == b'<html><head class="header_class" id="header_id"></head><body><p>foo</p></body></html>'
def test_36(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() h.head << h.head.title('hello') h << h.head.head(h.head.title('world')) << h.p('foo') assert merge_head( p, r, h ) == b'<html><head><title>world</title><title>hello</title></head><body><p>foo</p></body></html>'
def test_32(): r = create_request('/a', '/b') p = create_presentation(False) h = html.Renderer() with h.html: h << h.comment('c1') << h.head.head << h.comment( 'c2') << h.body << h.comment('c3') assert merge_head( p, r, h ) == b'<html><!--c1--><head></head><!--c2--><body></body><!--c3--></html>'
def test_html(): h = html.Renderer() p = presentation.PresentationService(None, None, False) r = p.serialize(h.p('hello')) assert r == b'<p>hello</p>' r = p.serialize(h.p(u'été'), 'utf-8', None) assert r == b'<p>\xc3\xa9t\xc3\xa9</p>' r = p.serialize(h.p('hello'), 'utf-8', '<!DOCTYPE html>') assert r == b'<!DOCTYPE html>\n<p>hello</p>'
def test_1(): p = create_presentation(False) r = create_request('/a', '/b') h = html.Renderer() h << 'hello' assert merge_head(p, r, h) == b'<html><head></head><body>hello</body></html>' r = create_request('', '') p = create_presentation(True) h = html.Renderer() h << 'hello' assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href=""></head><body>hello</body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="" rel="canonical"></head><body>hello</body></html>' r = create_request('/a', '') p = create_presentation(True) h = html.Renderer() h << 'hello' assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/a"></head><body>hello</body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/a" rel="canonical"></head><body>hello</body></html>' r = create_request('', '/b') p = create_presentation(True) h = html.Renderer() h << 'hello' assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/b"></head><body>hello</body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/b" rel="canonical"></head><body>hello</body></html>' r = create_request('/a', '/b') p = create_presentation(True) h = html.Renderer() h << 'hello' assert merge_head(p, r, h) == b'<html><head><link rel="canonical" href="/b/a"></head><body>hello</body></html>' \ or merge_head(p, r, h) == b'<html><head><link href="/b/a" rel="canonical"></head><body>hello</body></html>'
def test_parse10(): h = html.Renderer() root = h.fromstring('hello<a>text</a><b>text</b>', fragment=True) assert isinstance(root, tuple) assert len(root) == 3 assert root[0] == b'hello' assert root[1].tostring() == b'<a>text</a>' assert root[2].tostring() == b'<b>text</b>' root = h.fromstring('hello<a>text</a><b>text</b>', fragment=True, no_leading_text=True) assert isinstance(root, tuple) assert len(root) == 2 assert root[0].tostring() == b'<a>text</a>' assert root[1].tostring() == b'<b>text</b>'
def test_absolute_asset_url6(): h = html.Renderer(static_url='/static/root') assert h.absolute_asset_url('/tmp?a=42', '/abc') == '/tmp?a=42' assert h.absolute_asset_url('tmp?a=42', '/abc') == '/abc/tmp?a=42' assert h.absolute_asset_url('http://localhost/tmp?a=42', '/abc') == 'http://localhost/tmp?a=42' assert h.absolute_asset_url('/tmp?a=42', '/abc', b=43) in ('/tmp?a=42&b=43', '/tmp?b=43&a=42') assert h.absolute_asset_url('tmp?a=42', '/abc', b=43) in ('/abc/tmp?a=42&b=43', '/abc/tmp?b=43&a=42') assert h.absolute_asset_url('http://localhost/tmp?a=42', '/abc', b=43) in ('http://localhost/tmp?a=42&b=43', 'http://localhost/tmp?b=43&a=42')