[go: up one dir, main page]

File: test_dom1core.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 (34 lines) | stat: -rw-r--r-- 898 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
import pytest

from dominate.tags import *

def test_dom():
  container = div()
  with container.add(div(id='base')) as dom:
    s1 = span('Hello', id='span1')
    s2 = span('World', id='span2')

  s3 = span('foobar', id='span3')
  dom.appendChild(s3)
  assert container.getElementById('base') is dom
  assert container.getElementById('span1') is s1
  assert container.getElementById('span3') is s3
  assert container.getElementById('foo') is None
  assert container.getElementsByTagName('span') == [s1, s2, s3]
  assert container.getElementsByTagName('SPAN') == [s1, s2, s3]
  assert container.getElementsByTagName(1234) is None

def test_element():
  d = div(
    span(id='a'),
    span(id='a'),
  )
  with pytest.raises(ValueError):
    d.getElementById('a')

def test_parent_node():
  parent = div(id='parent')
  child = div(id='child')
  parent.add(child)

  assert child.parentNode is parent