def test_load(self): storage_path = tempfile.mkdtemp() logger_storage = CWLLoggerStorageManager(storage_path) cwllogger = CWLLogger(tempfile.mkdtemp()) data = cwllogger.to_dict() logger_storage.save(data) loaded_logs = list(logger_storage.load()) self.assertListEqual([data], loaded_logs) data2 = cwllogger.to_dict() logger_storage.save(data2) # results are order with modification time so it must be inside loaded_logs = list(logger_storage.load()) d = [data2, data] self.assertListEqual( d, loaded_logs, f'Results are not the same: ---------\n{json.dumps(d, indent=2)}\n-------\n{json.dumps(loaded_logs, indent=2)}' ) data3 = CWLLogger(tempfile.mkdtemp()).to_dict() logger_storage.save(data3) # results are order with modification time so it must be inside loaded_logs = list(logger_storage.load(2)) self.assertListEqual([data3, data2], loaded_logs)
def test_to_dict(self): logger = CWLLogger(self.tmp_dir) dict_log = logger.to_dict() import jsonschema schema_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'cwlkernel', 'loggerSchema.schema.json') with open(schema_path) as f: schema = json.load(f) jsonschema.validate(dict_log, schema)
def test_get_logs_from_past_kernels(self): new_dir = tempfile.mkdtemp() logger = CWLLogger(new_dir) logger.save() self.assertListEqual([logger.to_dict()['process_id']], [l['process_id'] for l in logger.load()])