Skip to content

Commit 9b4161d

Browse files
committed
TST #172
1 parent 9452b2a commit 9b4161d

File tree

1 file changed

+78
-12
lines changed

1 file changed

+78
-12
lines changed

tests/test_plans.py

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import sys
99
import unittest
1010

11-
_path = os.path.dirname(__file__)
12-
_path = os.path.join(_path, '..')
11+
_test_path = os.path.dirname(__file__)
12+
_path = os.path.join(_test_path, '..')
1313
if _path not in sys.path:
1414
sys.path.insert(0, _path)
1515

@@ -45,29 +45,95 @@ def tearDown(self):
4545
pass
4646

4747
def test_addDeviceDataAsStream(self):
48-
with Capture_stdout() as printed_lines:
48+
with Capture_stdout() as received:
4949
summarize_plan(
5050
APS_plans.addDeviceDataAsStream(
5151
ophyd.sim.motor1,
5252
"test-device"))
5353

54-
received = "\n".join([v[:21] for v in str(printed_lines).strip().splitlines()])
55-
expected = str([" Read ['motor1']"])
56-
self.assertEqual(received, expected)
54+
expected = [" Read ['motor1']"]
55+
self.assertEqual(str(received), str(expected))
5756

58-
with Capture_stdout() as lines2:
57+
with Capture_stdout() as received:
5958
summarize_plan(
6059
APS_plans.addDeviceDataAsStream(
6160
[ophyd.sim.motor2, ophyd.sim.motor3],
6261
"test-device-list"))
6362

64-
print(f"|{lines2}|")
65-
received = "\n".join([v for v in str(lines2).strip().splitlines()])
66-
expected = str([
63+
expected = [
6764
" Read ['motor2']", # TODO: <-- Why?
6865
" Read ['motor2', 'motor3']",
69-
])
70-
self.assertEqual(received, expected)
66+
]
67+
self.assertEqual(str(received), str(expected))
68+
69+
def test_run_command_file(self):
70+
filename = os.path.join(_test_path, "actions.txt")
71+
with Capture_stdout() as received:
72+
summarize_plan(
73+
APS_plans.run_command_file(filename))
74+
75+
# print(f"|{received}|")
76+
expected = [
77+
'Command file: /home/mintadmin/Documents/eclipse/apstools/tests/actions.txt',
78+
'====== ============ ========================',
79+
'line # action parameters ',
80+
'====== ============ ========================',
81+
'5 sample_slits 0, 0, 0.4, 1.2 ',
82+
'7 preusaxstune ',
83+
'10 FlyScan 0, 0, 0, blank ',
84+
'11 FlyScan 5, 2, 0, empty container',
85+
'12 SAXS 0, 0, 0, blank ',
86+
'====== ============ ========================',
87+
'',
88+
'file line 5: sample_slits 0 0 0.4 1.2',
89+
'no handling for line 5: sample_slits 0 0 0.4 1.2',
90+
'file line 7: preusaxstune',
91+
'no handling for line 7: preusaxstune',
92+
'file line 10: FlyScan 0 0 0 blank',
93+
'no handling for line 10: FlyScan 0 0 0 blank',
94+
'file line 11: FlyScan 5 2 0 "empty container"',
95+
'no handling for line 11: FlyScan 5 2 0 "empty container"',
96+
'file line 12: SAXS 0 0 0 blank',
97+
'no handling for line 12: SAXS 0 0 0 blank',
98+
]
99+
self.assertEqual(str(received), str(expected))
100+
101+
filename = os.path.join(_test_path, "actions.xlsx")
102+
with Capture_stdout() as received:
103+
summarize_plan(
104+
APS_plans.run_command_file(filename))
105+
106+
# print(f"|{received}|")
107+
expected = [
108+
'Command file: /home/mintadmin/Documents/eclipse/apstools/tests/actions.xlsx',
109+
'====== ============ =============================',
110+
'line # action parameters ',
111+
'====== ============ =============================',
112+
'1 mono_shutter open ',
113+
'2 USAXSscan 45.07, 98.3, 0.0, Water Blank',
114+
'3 saxsExp 45.07, 98.3, 0.0, Water Blank',
115+
'4 waxwsExp 45.07, 98.3, 0.0, Water Blank',
116+
'5 USAXSscan 12, 12.0, 1.2, plastic ',
117+
'6 USAXSscan 12, 37.0, 0.1, Al foil ',
118+
'7 mono_shutter close ',
119+
'====== ============ =============================',
120+
'',
121+
"file line 1: ['mono_shutter', 'open', None, None, None]",
122+
"no handling for line 1: ['mono_shutter', 'open', None, None, None]",
123+
"file line 2: ['USAXSscan', 45.07, 98.3, 0.0, 'Water Blank']",
124+
"no handling for line 2: ['USAXSscan', 45.07, 98.3, 0.0, 'Water Blank']",
125+
"file line 3: ['saxsExp', 45.07, 98.3, 0.0, 'Water Blank']",
126+
"no handling for line 3: ['saxsExp', 45.07, 98.3, 0.0, 'Water Blank']",
127+
"file line 4: ['waxwsExp', 45.07, 98.3, 0.0, 'Water Blank']",
128+
"no handling for line 4: ['waxwsExp', 45.07, 98.3, 0.0, 'Water Blank']",
129+
"file line 5: ['USAXSscan', 12, 12.0, 1.2, 'plastic']",
130+
"no handling for line 5: ['USAXSscan', 12, 12.0, 1.2, 'plastic']",
131+
"file line 6: ['USAXSscan', 12, 37.0, 0.1, 'Al foil']",
132+
"no handling for line 6: ['USAXSscan', 12, 37.0, 0.1, 'Al foil']",
133+
"file line 7: ['mono_shutter', 'close', None, None, None]",
134+
"no handling for line 7: ['mono_shutter', 'close', None, None, None]"
135+
]
136+
self.assertEqual(str(received), str(expected))
71137

72138

73139
def suite(*args, **kw):

0 commit comments

Comments
 (0)