def test_procedure_wrapper(): assert RandomProcedure.iterations.value == 100 procedure = RandomProcedure() procedure.iterations = 101 wrapper = ProcedureWrapper(procedure) new_wrapper = pickle.loads(pickle.dumps(wrapper)) assert hasattr(new_wrapper, 'procedure') assert new_wrapper.procedure.iterations == 101 assert RandomProcedure.iterations.value == 100
def test_procedure_wrapper(): assert RandomProcedure.iterations.value == 100 procedure = RandomProcedure() procedure.iterations = 101 file = tempfile.mktemp() results = Results(procedure, file) new_results = pickle.loads(pickle.dumps(results)) assert hasattr(new_results, 'procedure') assert new_results.procedure.iterations == 101 assert RandomProcedure.iterations.value == 100
def test_worker_closes_file_after_finishing(): procedure = RandomProcedure() procedure.iterations = 100 procedure.delay = 0.001 file = tempfile.mktemp() results = Results(procedure, file) worker = Worker(results) worker.start() worker.join(timeout=20.0) # Test if the file has been properly closed by removing the file os.remove(file)
def test_worker_finish(): procedure = RandomProcedure() procedure.iterations = 100 procedure.delay = 0.001 file = tempfile.mktemp() results = Results(procedure, file) worker = Worker(results) worker.start() worker.join(timeout=20.0) assert not worker.is_alive() new_results = Results.load(file, procedure_class=RandomProcedure) assert new_results.data.shape == (100, 2)
def test_procedure(): """ Ensure that the loaded test procedure is properly functioning """ procedure = RandomProcedure() assert procedure.iterations == 100 assert procedure.delay == 0.001 assert hasattr(procedure, 'execute')
def test_worker_stop(): procedure = RandomProcedure() file = tempfile.mktemp() results = Results(procedure, file) worker = Worker(results) worker.start() worker.stop() assert worker.should_stop() worker.join()
def test_zmq_does_not_crash_worker(caplog): """Check that a ZMQ serialisation usage error does not cause a crash. See https://github.com/ralph-group/pymeasure/issues/168 """ procedure = RandomProcedure() file = tempfile.mktemp() results = Results(procedure, file) # If we define a port here we get ZMQ communication # if cloudpickle is installed worker = Worker(results, port=5888, log_level=logging.DEBUG) worker.start() worker.join(timeout=20.0) # give it enough time to finish the procedure assert procedure.status == procedure.FINISHED del worker # make sure to clean up, reduce the possibility of test
def test_procedure(): """ Ensure that the loaded test procedure is properly functioning """ p = RandomProcedure() assert p.iterations == 100 assert hasattr(p, 'execute')