Skip to content

Commit 0b5226d

Browse files
committed
TST #195 make it testable
1 parent 76fbf47 commit 0b5226d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

apstools/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def wrapper(*args, **kwargs):
262262
return wrapper
263263

264264

265-
def show_ophyd_symbols(show_pv=True, printing=True, verbose=False):
265+
def show_ophyd_symbols(show_pv=True, printing=True, verbose=False, symbols=None):
266266
"""
267267
show all the ophyd Signal and Device objects defined as globals
268268
@@ -274,14 +274,17 @@ def show_ophyd_symbols(show_pv=True, printing=True, verbose=False):
274274
If True, print table to stdout.
275275
verbose: bool (default: False)
276276
If True, also show ``str(obj``.
277+
symbols: dict (default: `globals()`)
278+
If None, use global symbol table.
279+
If not None, use provided dictionary.
277280
"""
278281
table = pyRestTable.Table()
279282
table.labels = ["name", "ophyd structure"]
280283
if show_pv:
281284
table.addLabel("EPICS PV")
282285
if verbose:
283286
table.addLabel("object representation")
284-
g = globals()
287+
g = symbols or globals()
285288
for k, v in sorted(g.items()):
286289
if isinstance(v, (ophyd.Signal, ophyd.Device)):
287290
row = [k, v.__class__.__name__]

tests/test_utils.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,19 @@ def test_trim_string_for_EPICS(self):
153153

154154
def test_show_ophyd_symbols(self):
155155
from ophyd.sim import hw
156-
sims = hw()
157-
globals().update(sims.__dict__)
158-
num = len(sims.__dict__)
156+
sims = hw().__dict__
157+
wont_show = ("flyer1", "flyer2", "new_trivial_flyer", "trivial_flyer")
158+
num = len(sims) - len(wont_show)
159+
kk = sorted(sims.keys())
159160
# sims hardware not found by show_ophyd_symbols() in globals!
160-
table = APS_utils.show_ophyd_symbols()
161+
table = APS_utils.show_ophyd_symbols(symbols=sims, printing=False)
161162
self.assertEqual(3, len(table.labels))
162-
# FIXME: self.assertEqual(num, len(table.rows))
163+
rr = [r[0] for r in table.rows]
164+
for k in kk:
165+
msg = f"{k} not found"
166+
if k not in wont_show:
167+
self.assertTrue(k in rr, msg)
168+
self.assertEqual(num, len(table.rows))
163169

164170

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

0 commit comments

Comments
 (0)