sources for test_html.py [rev. unknown]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from py.xml import html 
def test_html_name_stickyness(): 
    class my(html.p): 
        pass 
    x = my("hello") 
    assert unicode(x) == '<p>hello</p>' 
def test_stylenames(): 
    class my: 
        class body(html.body): 
            style = html.Style(font_size = "12pt")
    u = unicode(my.body())
    assert u == '<body style="font-size: 12pt"></body>' 
def test_class_None(): 
    t = html.body(class_=None)
    u = unicode(t) 
    assert u == '<body></body>'
def test_alternating_style(): 
    alternating = (
        html.Style(background="white"), 
        html.Style(background="grey"),
    )
    class my(html): 
        class li(html.li): 
            def style(self): 
                i = self.parent.index(self) 
                return alternating[i%2]
            style = property(style) 
    
    x = my.ul(
            my.li("hello"), 
            my.li("world"), 
            my.li("42"))
    u = unicode(x) 
    assert u == ('<ul><li style="background: white">hello</li>'
                     '<li style="background: grey">world</li>'
                     '<li style="background: white">42</li>'
                 '</ul>')
def test_singleton():
    h = html.head(html.link(href="foo"))
    assert unicode(h) == '<head><link href="foo"/></head>'
    
    h = html.head(html.script(src="foo"))
    assert unicode(h) == '<head><script src="foo"></script></head>'
def test_inline():
    h = html.div(html.span('foo'), html.span('bar'))
    assert (h.unicode(indent=2) ==
            '<div><span>foo</span><span>bar</span></div>')