port python2.x code to python3.x
[tools/itest-core.git] / tests / unit / test_xmlparser.py
1 import unittest
2
3 from itest.xmlparser import Parser
4
5
6 class TestXMLParser(unittest.TestCase):
7
8     def test_simple(self):
9         self.assertEqual({
10                 'summary': 'test',
11                 'steps': 'echo test1\necho test2',
12                 },
13             Parser().parse("""<testcase>
14 <summary>test</summary>
15 <steps>
16 echo test1
17 echo test2
18 </steps>
19 </testcase>"""))
20
21     def test_tracking(self):
22         self.assertEqual({'tracking': [
23                     ('change', '90125'),
24                     ('ticket', '5150'),
25                     ]},
26             Parser().parse('''<testcase>
27 <tracking>
28   <change>90125</change>
29   <ticket>5150</ticket>
30 </tracking>
31 </testcase>'''))
32
33     def test_qa(self):
34         self.assertEqual({'qa': [
35                     ('Are you sure?', 'y'),
36                     ('Do you agree?', 'n'),
37                     ]},
38             Parser().parse('''<testcase>
39 <qa>
40   <prompt>Are you sure?</prompt>
41   <answer>y</answer>
42   <prompt>Do you agree?</prompt>
43   <answer>n</answer>
44 </qa>
45 </testcase>'''))
46
47     def test_qa_unmatch(self):
48         self.assertRaises(Exception, Parser().parse, '''<testcase>
49 <qa>
50   <prompt>Are you sure?</prompt>
51 </qa>
52 </testcase>''')
53
54     def test_conditions(self):
55         self.assertEqual({'conditions': {
56                 'whitelist': [
57                     'OpenSuse-64bit',
58                     'Ubuntu12.04',
59                     ],
60                 'blacklist': [
61                     'Fedora19-x86_64',
62                     ],
63                 }},
64             Parser().parse('''<testcase>
65 <conditions>
66   <whitelist>
67     <platform>OpenSuse-64bit</platform>
68     <platform>Ubuntu12.04</platform>
69   </whitelist>
70   <blacklist>
71     <platform>Fedora19-x86_64</platform>
72   </blacklist>
73 </conditions>
74 </testcase>'''))
75
76     def test_bad_case(self):
77         self.assertEqual(None, Parser().parse('I am not XML format!'))