def do_test_tracker(): # test done if no WIP iterative_eval_tracker.wip(1) assert iterative_eval_tracker.ns.todo == {1} assert not iterative_eval_tracker.done iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.done
def value(self, a_value): iterative_eval_tracker.calced(self) self.wip = False self._value = a_value if not self.close_enough(self._prev_value, tol=iterative_eval_tracker.tolerance): iterative_eval_tracker.wip(self)
def test_iterative_eval_tracker(): assert isinstance(iterative_eval_tracker.ns.todo, set) # init the tracker iterative_eval_tracker(iterations=100, tolerance=0.001) assert iterative_eval_tracker.ns.iteration_number == 0 assert iterative_eval_tracker.ns.iterations == 100 assert iterative_eval_tracker.ns.tolerance == 0.001 assert iterative_eval_tracker.tolerance == 0.001 assert iterative_eval_tracker.done # test done if no WIP iterative_eval_tracker.wip(1) assert iterative_eval_tracker.ns.todo == {1} assert not iterative_eval_tracker.done iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.done # init the tracker iterative_eval_tracker(iterations=2, tolerance=5) assert iterative_eval_tracker.ns.iteration_number == 0 assert iterative_eval_tracker.ns.iterations == 2 assert iterative_eval_tracker.ns.tolerance == 5 # test done if max iters exceeded iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.ns.iteration_number == 1 iterative_eval_tracker.wip(1) assert not iterative_eval_tracker.done iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.ns.iteration_number == 2 iterative_eval_tracker.wip(1) assert iterative_eval_tracker.done # check calced / iscalced assert not iterative_eval_tracker.is_calced(1) iterative_eval_tracker.calced(1) assert iterative_eval_tracker.is_calced(1) iterative_eval_tracker.inc_iteration_number() assert not iterative_eval_tracker.is_calced(1)
def test_iterative_eval_tracker(): assert isinstance(iterative_eval_tracker.ns.todo, set) def init_tracker(): # init the tracker iterative_eval_tracker(iterations=100, tolerance=0.001) assert iterative_eval_tracker.ns.iteration_number == 0 assert iterative_eval_tracker.ns.iterations == 100 assert iterative_eval_tracker.ns.tolerance == 0.001 assert iterative_eval_tracker.tolerance == 0.001 assert iterative_eval_tracker.done def do_test_tracker(): # test done if no WIP iterative_eval_tracker.wip(1) assert iterative_eval_tracker.ns.todo == {1} assert not iterative_eval_tracker.done iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.done init_tracker() do_test_tracker() # init the tracker iterative_eval_tracker(iterations=2, tolerance=5) assert iterative_eval_tracker.ns.iteration_number == 0 assert iterative_eval_tracker.ns.iterations == 2 assert iterative_eval_tracker.ns.tolerance == 5 # test done if max iters exceeded iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.ns.iteration_number == 1 iterative_eval_tracker.wip(1) assert not iterative_eval_tracker.done iterative_eval_tracker.inc_iteration_number() assert iterative_eval_tracker.ns.iteration_number == 2 iterative_eval_tracker.wip(1) assert iterative_eval_tracker.done # check calced / iscalced assert not iterative_eval_tracker.is_calced(1) iterative_eval_tracker.calced(1) assert iterative_eval_tracker.is_calced(1) iterative_eval_tracker.inc_iteration_number() assert not iterative_eval_tracker.is_calced(1) class AThread(threading.Thread): def run(self): try: init_tracker() import time time.sleep(0.1) do_test_tracker() self.result = True except: # noqa: E722 self.result = False thread = AThread() thread.start() init_tracker() do_test_tracker() thread.join() assert thread.result