source: branches/uq/lang/python/Rappture/test/pyxml_test.py @ 5410

Last change on this file since 5410 was 5410, checked in by mmh, 9 years ago

add new python API, PyXml?

File size: 3.5 KB
Line 
1# PyXml Unit Tests
2
3from Rappture import PyXml
4import numpy as np
5
6rx = PyXml('test.xml')
7
8
9def test_input1():
10    global rx
11    temp = rx['input.number(temperature).current'].value
12    assert temp == '300K'
13
14
15def test_input2():
16    global rx
17    temp = rx['input.number(temperature)']
18    assert temp['current'].value == '300K'
19
20
21def test_input2a():
22    global rx
23    temp = rx['input.number(temperature)']
24    assert temp.get('current') == '300K'
25
26
27def test_input2b():
28    global rx
29    temp = rx['input.number(temperature).current']
30    assert temp.value == '300K'
31
32
33def test_input3():
34    global rx
35    inp = rx['input']
36    assert inp['number(temperature).current'].value == '300K'
37
38
39def test_input4():
40    global rx
41    inp = rx['input']
42    temp = inp['number(temperature)']
43    assert temp['current'].value == '300K'
44
45
46def test_input_old1():
47    global rx
48    temp = rx.get('input.number(temperature).current')
49    assert temp == '300K'
50
51
52def 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
59def 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
66def 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
73def 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
80def 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
87def 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
94def 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
101def 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
108def 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
115def 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
121def 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
128def 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
135def 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
142def 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
149def 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"
Note: See TracBrowser for help on using the repository browser.