|
8 | 8 | import sys |
9 | 9 | import unittest |
10 | 10 |
|
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, '..') |
13 | 13 | if _path not in sys.path: |
14 | 14 | sys.path.insert(0, _path) |
15 | 15 |
|
@@ -45,29 +45,95 @@ def tearDown(self): |
45 | 45 | pass |
46 | 46 |
|
47 | 47 | def test_addDeviceDataAsStream(self): |
48 | | - with Capture_stdout() as printed_lines: |
| 48 | + with Capture_stdout() as received: |
49 | 49 | summarize_plan( |
50 | 50 | APS_plans.addDeviceDataAsStream( |
51 | 51 | ophyd.sim.motor1, |
52 | 52 | "test-device")) |
53 | 53 |
|
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)) |
57 | 56 |
|
58 | | - with Capture_stdout() as lines2: |
| 57 | + with Capture_stdout() as received: |
59 | 58 | summarize_plan( |
60 | 59 | APS_plans.addDeviceDataAsStream( |
61 | 60 | [ophyd.sim.motor2, ophyd.sim.motor3], |
62 | 61 | "test-device-list")) |
63 | 62 |
|
64 | | - print(f"|{lines2}|") |
65 | | - received = "\n".join([v for v in str(lines2).strip().splitlines()]) |
66 | | - expected = str([ |
| 63 | + expected = [ |
67 | 64 | " Read ['motor2']", # TODO: <-- Why? |
68 | 65 | " 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)) |
71 | 137 |
|
72 | 138 |
|
73 | 139 | def suite(*args, **kw): |
|
0 commit comments