1 | # PyXml Unit Tests |
---|
2 | |
---|
3 | from Rappture import PyXml |
---|
4 | import numpy as np |
---|
5 | |
---|
6 | rx = PyXml('test.xml') |
---|
7 | |
---|
8 | |
---|
9 | def test_input1(): |
---|
10 | global rx |
---|
11 | temp = rx['input.number(temperature).current'].value |
---|
12 | assert temp == '300K' |
---|
13 | |
---|
14 | |
---|
15 | def test_input2(): |
---|
16 | global rx |
---|
17 | temp = rx['input.number(temperature)'] |
---|
18 | assert temp['current'].value == '300K' |
---|
19 | |
---|
20 | |
---|
21 | def test_input2a(): |
---|
22 | global rx |
---|
23 | temp = rx['input.number(temperature)'] |
---|
24 | assert temp.get('current') == '300K' |
---|
25 | |
---|
26 | |
---|
27 | def test_input2b(): |
---|
28 | global rx |
---|
29 | temp = rx['input.number(temperature).current'] |
---|
30 | assert temp.value == '300K' |
---|
31 | |
---|
32 | |
---|
33 | def test_input3(): |
---|
34 | global rx |
---|
35 | inp = rx['input'] |
---|
36 | assert inp['number(temperature).current'].value == '300K' |
---|
37 | |
---|
38 | |
---|
39 | def test_input4(): |
---|
40 | global rx |
---|
41 | inp = rx['input'] |
---|
42 | temp = inp['number(temperature)'] |
---|
43 | assert temp['current'].value == '300K' |
---|
44 | |
---|
45 | |
---|
46 | def test_input_old1(): |
---|
47 | global rx |
---|
48 | temp = rx.get('input.number(temperature).current') |
---|
49 | assert temp == '300K' |
---|
50 | |
---|
51 | |
---|
52 | def test_input_curve(): |
---|
53 | global rx |
---|
54 | curve = rx['output.curve(f12).component.xy'].value |
---|
55 | curve = map(int, curve.split()) |
---|
56 | assert curve == [0, 0, 1, 1, 2, 4, 3, 9, 4, 16] |
---|
57 | |
---|
58 | |
---|
59 | def test_output_1(): |
---|
60 | global rx |
---|
61 | curve = rx['output.curve(temp).component'] |
---|
62 | curve['xy'] = "1 2" |
---|
63 | assert curve['xy'].value == "1 2" |
---|
64 | |
---|
65 | |
---|
66 | def test_output_2(): |
---|
67 | global rx |
---|
68 | curve = rx['output.curve(temp).component'] |
---|
69 | curve['xy'] = [[1], [2]] |
---|
70 | assert curve['xy'].value == "1 2" |
---|
71 | |
---|
72 | |
---|
73 | def test_output_3(): |
---|
74 | global rx |
---|
75 | curve = rx['output.curve(temp).component'] |
---|
76 | curve['xy'] = [[1.1], [2.2]] |
---|
77 | assert curve['xy'].value == "1.1 2.2" |
---|
78 | |
---|
79 | |
---|
80 | def test_output_4(): |
---|
81 | global rx |
---|
82 | curve = rx['output.curve(temp).component'] |
---|
83 | curve['xy'] = [[1], [2], [3]] |
---|
84 | assert curve['xy'].value == "1 2 3" |
---|
85 | |
---|
86 | |
---|
87 | def test_output_5(): |
---|
88 | global rx |
---|
89 | curve = rx['output.curve(temp).component'] |
---|
90 | curve['xy'] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] |
---|
91 | assert curve['xy'].value == "1 4 7 2 5 8 3 6 9" |
---|
92 | |
---|
93 | |
---|
94 | def test_output_6(): |
---|
95 | global rx |
---|
96 | curve = rx['output.curve(temp).component'] |
---|
97 | curve['xy'] = ([1, 2, 3], [4, 5, 6], [7, 8, 9]) |
---|
98 | assert curve['xy'].value == "1 4 7 2 5 8 3 6 9" |
---|
99 | |
---|
100 | |
---|
101 | def test_output_7(): |
---|
102 | global rx |
---|
103 | curve = rx['output.curve(temp).component'] |
---|
104 | curve['xy'] = ((1, 2, 3), (4, 5, 6), (7, 8, 9)) |
---|
105 | assert curve['xy'].value == "1 4 7 2 5 8 3 6 9" |
---|
106 | |
---|
107 | |
---|
108 | def test_output_8(): |
---|
109 | global rx |
---|
110 | curve = rx['output.curve(temp).component'] |
---|
111 | curve['xy'] = np.column_stack([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) |
---|
112 | assert curve['xy'].value == "1 4 7 2 5 8 3 6 9" |
---|
113 | |
---|
114 | |
---|
115 | def test_output_9(): |
---|
116 | global rx |
---|
117 | rx.put('output.string(temp).current', 'xyzzy') |
---|
118 | assert rx['output.string(temp).current'].value == "xyzzy" |
---|
119 | |
---|
120 | |
---|
121 | def test_output_10(): |
---|
122 | global rx |
---|
123 | data = rx['output.string(temp)'] |
---|
124 | data.put('current', 'xyzzy') |
---|
125 | assert rx['output.string(temp).current'].value == "xyzzy" |
---|
126 | |
---|
127 | |
---|
128 | def test_output_11(): |
---|
129 | global rx |
---|
130 | data = rx['output.string(temp)'] |
---|
131 | data.put('current', 'xyzzy') |
---|
132 | assert data['current'].value == "xyzzy" |
---|
133 | |
---|
134 | |
---|
135 | def test_output_12(): |
---|
136 | global rx |
---|
137 | data = rx['output.string(temp)'] |
---|
138 | data.put('current', 'xyzzy', compress=True) |
---|
139 | assert data['current'].value == "xyzzy" |
---|
140 | |
---|
141 | |
---|
142 | def test_output_13(): |
---|
143 | global rx |
---|
144 | data = rx['output.string(temp)'] |
---|
145 | data.put('current', 'results.txt', type='file') |
---|
146 | assert data['current'].value == "These are the results of our test.\n" |
---|
147 | |
---|
148 | |
---|
149 | def test_output_14(): |
---|
150 | global rx |
---|
151 | data = rx['output.string(temp)'] |
---|
152 | data.put('current', 'results.txt', type='file', compress=True) |
---|
153 | assert data['current'].value == "These are the results of our test.\n" |
---|