def ioworker(in_queue, stop): """ Saves Phase objects from the in_queue. If the Queue is empty this function will only stop if the 'stop' event is set. """ while True: try: phases_path, phases = in_queue.get(timeout=0.5) create_dir_recursive(phases_path) Phase.save_phases(phases, phases_path) in_queue.task_done() except queue.Empty: if not stop.is_set(): continue else: return
def ioworker(in_queue, stop): """ Saves Phase objects from the in_queue. If the Queue is empty this function will only stop if the 'stop' event is set. """ while True: try: phases_path, phases = in_queue.get(timeout=0.5) create_dir_recursive(phases_path) Phase.save_phases(phases, phases_path) in_queue.task_done() except queue.Empty: if not stop.is_set(): continue else: return
def test_import_export(self): from io import BytesIO phases = [Phase(R=0, G=1), Phase(R=1, G=2)] fn = BytesIO() Phase.save_phases(phases, filename=fn) loaded_phases = list(JSONPhaseParser.parse(fn)) def strip_uuid(data): new_data = [] for line in data.split('\n'): if "uuid" not in line: new_data.append(line) return "\n".join(new_data) outp1 = [strip_uuid(phase.dump_object()) for phase in phases] outp2 = [strip_uuid(phase.dump_object()) for phase in loaded_phases] self.assertEqual(outp1, outp2)
def test_import_export(self): from io import BytesIO phases = [Phase(R=0, G=1), Phase(R=1, G=2)] fn = BytesIO() Phase.save_phases(phases, filename=fn) loaded_phases = list(JSONPhaseParser.parse(fn)) def strip_uuid(data): new_data = [] for line in data.split('\n'): if "uuid" not in line: new_data.append(line) return "\n".join(new_data) outp1 = [strip_uuid(phase.dump_object()) for phase in phases] outp2 = [strip_uuid(phase.dump_object()) for phase in loaded_phases] self.assertEqual(outp1, outp2)