def test_draw_before_update(): class Status: done = False def watch(self, func): ... # Test that the default meter placeholder is valid to draw. pbar = ProgressBar([Status()]) pbar.draw()
def test_status_with_name(): st = SimpleStatus() pbar = ProgressBar([st]) st._finished() st = SimpleStatus() pbar = ProgressBar([st]) assert pbar.delay_draw == 0.2 time.sleep(0.25) st._finished()
def test_status_with_name(hw): from ophyd.status import DeviceStatus st = DeviceStatus(device=hw.det) pbar = ProgressBar([st]) st._finished() st = DeviceStatus(device=hw.det) pbar = ProgressBar([st]) assert pbar.delay_draw == 0.2 time.sleep(0.25) st._finished()
def umv(self, position, timeout=None): """ Move to a position, wait, and update with a progress bar. Parameters ---------- position: ``float`` Desired end position timeout: ``float``, optional If provided, the mover will throw an error if motion takes longer than timeout to complete. If omitted, the mover's default timeout will be use. """ status = self.move(position, timeout=timeout, wait=False) ProgressBar([status]) try: status_wait(status) except KeyboardInterrupt: self.stop()
def plan_test_progress_bars(n_progress_bars: int = 1): """ Test visualization of progress bars. Parameters ---------- n_progress_bars: int The number of progress bars to display. """ # Display at least one progress bar n_progress_bars = max(n_progress_bars, 1) # where the status object computes the fraction st_list = [StatusPlaceholder() for _ in range(n_progress_bars)] pbar = ProgressBar(st_list) v_min = 0 v_max = 1 n_pts = 10 step = (v_max - v_min) / n_pts print(f"TESTING {n_progress_bars} PROGRESS BARS ...\n") for n in range(n_pts): yield from bps.sleep(0.5) v = v_min + (n + 1) * step for n_pb in range(n_progress_bars): pbar.update(n_pb, name=f"TEST{n_pb + 1}", current=v, initial=v_min, target=v_max, fraction=n / n_pts) for st in st_list: st.done = True for n_pb in range(n_progress_bars): pbar.update(n_pb, name=f"TEST{n_pb + 1}", current=1, initial=0, target=1, fraction=1) s = "\n" * n_progress_bars print(f"{s}\nTEST COMPLETED ...")
def test_status_without_watch(): from ophyd.sim import NullStatus st = NullStatus() ProgressBar([st])
def test_tuple_progress(): class StatusPlaceholder: "Just enough to make ProgressBar happy. We will update manually." def __init__(self): self.done = False def watch(self, _): ... # where the status object computes the fraction st = StatusPlaceholder() pbar = ProgressBar([st]) pbar.update(0, name='', current=(0, 0), initial=(0, 0), target=(1, 1), fraction=0) pbar.update(0, name='', current=(0.2, 0.2), initial=(0, 0), target=(1, 1), fraction=0.2) pbar.update(0, name='', current=(1, 1), initial=(0, 0), target=(1, 1), fraction=1) st.done = True pbar.update(0, name='', current=(1, 1), initial=(0, 0), target=(1, 1), fraction=1) # where the progress bar computes the fraction st = StatusPlaceholder() pbar = ProgressBar([st]) pbar.update(0, name='', current=(0, 0), initial=(0, 0), target=(1, 1)) pbar.update(0, name='', current=(0.2, 0.2), initial=(0, 0), target=(1, 1)) pbar.update(0, name='', current=(1, 1), initial=(0, 0), target=(1, 1)) st.done = True pbar.update(0, name='', current=(1, 1), initial=(0, 0), target=(1, 1)) # minimal API st = StatusPlaceholder() pbar = ProgressBar([st]) pbar.update(0) pbar.update(0) st.done = True pbar.update(0) # name only st = StatusPlaceholder() pbar = ProgressBar([st]) pbar.update(0, name='foo') pbar.update(0, name='foo') st.done = True pbar.update(0, name='foo')
def test_status_without_watch(): st = NullStatus() ProgressBar([st])