File: Element.py

package info (click to toggle)
plastex 3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,132 kB
  • sloc: python: 23,341; xml: 18,076; javascript: 7,755; ansic: 46; makefile: 40; sh: 26
file content (54 lines) | stat: -rwxr-xr-x 1,584 bytes parent folder | download | duplicates (2)
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
import unittest
from unittest import TestCase
from plasTeX.DOM import *

class ElementTest(TestCase):

    def testTagName(self):
        doc = Document()
        one = doc.createElement('one')
        assert one.nodeName == 'one'
        assert one.tagName == 'one'

    def testSetGetRemoveAttribute(self):
        doc = Document()
        one = doc.createElement('one')
        one.setAttribute('foo', 'bar')
        assert list(one.attributes.keys()) == ['foo']
        assert one.getAttribute('foo') == 'bar'
        assert one.getAttribute('aoeu') is None
        assert one.removeAttribute('aoeu') is None
        assert one.removeAttribute('foo') is None
        assert list(one.attributes.keys()) == []

    def testHasAttribute(self):
        doc = Document()
        one = doc.createElement('one')
        one.setAttribute('foo', 'bar')
        assert one.hasAttribute('foo')
        assert not one.hasAttribute('aoeu')

    def testGetElementsByTagName(self):
        doc = Document()
        one = doc.createElement('one')
        two = doc.createElement('two')
        twoClone = two.cloneNode()
        three = doc.createElement('three')
        four = doc.createElement('four')

        one.extend([two, three])
        three.extend([four, twoClone])

        elems = one.getElementsByTagName('two')
        assert len(elems) == 2, elems
        assert elems[0] is two
        assert elems[1] is twoClone

        elems = one.getElementsByTagName('four')
        assert len(elems) == 1
        assert elems[0] is four


if __name__ == '__main__':
    unittest.main()