def test_print_progress(self): out = StringIO() monitor = Monitor(out=out) sd = SnapshotDict(status="") for i in range(0, 100): status = REALIZATION_STATE_FINISHED if i < 50 else REALIZATION_STATE_WAITING sd.reals[i] = Realization(status=status, active=True) monitor._snapshots[0] = Snapshot(sd.dict()) monitor._start_time = datetime.now() general_event = _UpdateEvent( phase_name="Test Phase", current_phase=0, total_phases=2, progress=0.5, indeterminate=False, iteration=0, ) monitor._print_progress(general_event) self.assertEqual( """\r --> Test Phase 1/2 |███████████████ | 50% Running time: 0 seconds Waiting 50/100 Pending 0/100 Running 0/100 Failed 0/100 Finished 50/100 Unknown 0/100 """, out.getvalue(), )
def test_print_progress(self): out = StringIO() monitor = Monitor(out=out) sd = SnapshotDict(status="") for i in range(0, 100): status = REALIZATION_STATE_FINISHED if i < 50 else REALIZATION_STATE_WAITING sd.reals[i] = Realization(status=status, active=True) monitor._snapshots[0] = Snapshot(sd.dict()) monitor._start_time = datetime.now() general_event = _UpdateEvent( phase_name="Test Phase", current_phase=0, total_phases=2, progress=0.5, indeterminate=False, iteration=0, ) monitor._print_progress(general_event) # For some reason, `tqdm` adds an extra line containing a progress-bar, # even though this test only calls it once. # I suspect this has something to do with the way `tqdm` does refresh, # but do not know how to fix it. # Seems not be a an issue when used normally. expected = """ --> Test Phase | | 0% it 1/2 |##############################5 | 50% Running time: 0 seconds Waiting 50/100 Pending 0/100 Running 0/100 Failed 0/100 Finished 50/100 Unknown 0/100 """ assert out.getvalue().replace("\r", "\n") == expected
def test_print_progress(self): out = StringIO() monitor = Monitor(out=out) states = [ SimulationStateStatus("Finished", None, None), SimulationStateStatus("Waiting", None, None), ] states[0].count = 10 states[0].total_count = 100 general_event = GeneralEvent("Test Phase", 0, 2, 0.5, False, states, 10) monitor._print_progress(general_event) self.assertEqual( """\r --> Test Phase 1/2 |███████████████ | 50% Running time: 10 seconds Finished 10/100 Waiting 0/1 """, out.getvalue())