[go: up one dir, main page]

File: test_document.py

package info (click to toggle)
dominate 2.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: python: 2,532; makefile: 20
file content (119 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from dominate import document
from dominate.tags import *

def test_doc():
  d = document()
  assert d.render() == \
'''<!DOCTYPE html>
<html>
  <head>
    <title>Dominate</title>
  </head>
  <body></body>
</html>'''


def test_decorator():
  @document()
  def foo():
    p('Hello World')

  f = foo()
  assert f.render() == \
'''<!DOCTYPE html>
<html>
  <head>
    <title>Dominate</title>
  </head>
  <body>
    <p>Hello World</p>
  </body>
</html>'''


def test_bare_decorator():
  @document
  def foo():
    p('Hello World')

  assert foo().render() == \
'''<!DOCTYPE html>
<html>
  <head>
    <title>Dominate</title>
  </head>
  <body>
    <p>Hello World</p>
  </body>
</html>'''


def test_title():
  d = document()
  assert d.title == 'Dominate'

  d = document(title='foobar')
  assert d.title == 'foobar'

  d.title = 'baz'
  assert d.title == 'baz'

  d.title = title('bar')
  assert d.title == 'bar'

  assert d.render() == \
'''<!DOCTYPE html>
<html>
  <head>
    <title>bar</title>
  </head>
  <body></body>
</html>'''

def test_containers():
  d = document()
  with d.footer:
    div('footer')
  with d:
    div('main1')
  with d.main:
    div('main2')
  print(d.header)
  print(d)
  print(d.body.children)
  with d.header:
    div('header1')
    div('header2')
  assert d.render() == \
'''<!DOCTYPE html>
<html>
  <head>
    <title>Dominate</title>
  </head>
  <body>
    <div>header1</div>
    <div>header2</div>
  ''''''
    <div>main1</div>
    <div>main2</div>
  ''''''
    <div>footer</div>
  </body>
</html>'''


def test_attributes():
  d = document(title=None, doctype=None, lang='en')
  assert d.render() == \
'''<html lang="en">
  <head></head>
  <body></body>
</html>'''

def test_repr():
  d = document(title='foo')
  assert d.__repr__() == '<dominate.document "foo">'

if __name__ == '__main__':
  # test_doc()
  test_decorator()