-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjcd90_tkm368_TestXML.py
93 lines (73 loc) · 2.19 KB
/
jcd90_tkm368_TestXML.py
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
#!/usr/bin/env python
# ---------------------------
# cs327e-xml/TestXML.py
# Copyright (C) 2013
# Tracy Mullen, John Dees
# --------------------------
# -------
# imports
# -------
import StringIO
import unittest
from XML import *
# -----------
# TestXML
# -----------
class TestXML (unittest.TestCase) :
# -----
# xml_read
# -----
def test_read_1 (self) :
r = StringIO.StringIO("<Team><Cooly></Cooly></Team>")
inputList = []
inputList = xml_read(r, inputList)
self.assert_(inputList != [])
def test_read_2 (self) :
r = StringIO.StringIO("<Team><Cooly></Cooly></Team>")
inputList = []
inputList = xml_read(r, inputList)
self.assert_(inputList != ["<Team>","<Cooly>","</Cooly>","</Team>"])
def test_read_3 (self) :
r = StringIO.StringIO("<Team><Cooly></Cooly></Team>")
inputList = []
inputList = xml_read(r, inputList)
self.assert_(inputList == ["Team","Cooly","/Cooly","/Team"])
# --------
# findRoot
# --------
def test_eval_1(self) :
inputList = ["<Team><Cooly></Cooly></Team>"]
searchRoot = findRoot(inputList)
self.assert_(searchRoot == [])
def test_eval_2(self) :
inputList = ["<Team><Cooly></Cooly></Team><Team></Team>"]
searchRoot = findRoot(inputList)
self.assert_(searchRoot != ["<Team>","</Team>"])
def test_eval_3(self) :
inputList = ["Team","Cooly","/Cooly","/Team","Cooly","/Cooly"]
searchRoot = findRoot(inputList)
self.assert_(searchRoot == ["Cooly","/Cooly"])
# -------------
# xml_write
# -------------
def test_print_1(self) :
w = StringIO.StringIO()
inputList = ["1","2","3"]
xml_write(w,inputList)
self.assert_(w.getvalue() == "1\n2\n3\n")
def test_print_2(self) :
w = StringIO.StringIO()
inputList = [""]
xml_write(w,inputList)
self.assert_(w.getvalue() == "\n")
def test_print_3(self) :
w = StringIO.StringIO()
inputList = ["1"]
xml_write(w,inputList)
self.assert_(w.getvalue() == "1\n")
# ----
# main
# ----
print("TestXML.py")
unittest.main()
print("Done.")