def test_encode_simple_job(self): r = Result(input=FactA(), output=FactB()) r_json = r.to_json() new_r = Result.from_json(r_json) self.assertEqual(r.identifier, new_r.identifier) self.assertEqual(r.input.get(), new_r.input.get()) self.assertEqual(r.output, new_r.output) for a, b in zip(r.output, new_r.output): self.assertEqual(a, b) self.assertEqual(r.clock.start_date, new_r.clock.start_date) self.assertEqual(r.clock.end_date, new_r.clock.end_date)
def test_encode_complex_job_01(self): r = Result() r.input = FactA(a="42", b=2) r.output = FactB(a="42", b=2) r_json = r.to_json() new_r = Result.from_json(r_json) self.assertEqual(r.identifier, new_r.identifier) self.assertIsInstance(r.input, Composable) self.assertIsInstance(new_r.input, Composable) self.assertEqual(r.input.get(), new_r.input.get()) self.assertEqual(r.output, new_r.output)
def test_encode_complex_job_02(self): r = Result() r.input = Composite(FactA(a="42", b=2), FactB(a=1, b=2)) r.output = [FactA(a=1, b=4), FactA(a=2, b=3), FactB(a=3, b=2), FactB(a=4, b=1)] r_json = r.to_json() new_r = Result.from_json(r_json) self.assertEqual(r.identifier, new_r.identifier) self.assertIsInstance(r.input, Composable) self.assertIsInstance(new_r.input, Composable) self.assertEqual(r.input.get(), new_r.input.get()) self.assertEqual(r.output, new_r.output) self.assertEqual(len(r.output), 4)
def test_job_empty(self): r = Result() r_json = r.to_json() new_r = Result.from_json(r_json) self.assertEqual(new_r.to_json(), r.to_json())
def test_job_result_output3(self): r = Result() r.input = Composite(FactA(a=1, b=2), FactA(a=10, b=20)) r.output = FactA(a=10, b=20) r_json = r.to_json() output_should_be = [{ "__class__": "FactA", "__module__": "test_job", "fields": { "a": { "__class__": "IntegerField", "__module__": "opulence.common.fields.fields", "value": 10, "default": None, "mandatory": False, }, "b": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "20", "default": "b", "mandatory": False, }, "c": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "c", "default": "c", "mandatory": False, }, }, }] input_should_be = [ { "__class__": "FactA", "__module__": "test_job", "fields": { "a": { "__class__": "IntegerField", "__module__": "opulence.common.fields.fields", "value": 1, "default": None, "mandatory": False, }, "b": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "2", "default": "b", "mandatory": False, }, "c": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "c", "default": "c", "mandatory": False, }, }, }, { "__class__": "FactA", "__module__": "test_job", "fields": { "a": { "__class__": "IntegerField", "__module__": "opulence.common.fields.fields", "value": 10, "default": None, "mandatory": False, }, "b": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "20", "default": "b", "mandatory": False, }, "c": { "__class__": "StringField", "__module__": "opulence.common.fields.fields", "value": "c", "default": "c", "mandatory": False, }, }, }, ] self.assertEqual(r_json["output"], output_should_be) self.assertEqual(r_json["input"], input_should_be) new_r = Result.from_json(r_json) new_r_json = new_r.to_json() for a, b in zip(r.to_json()["input"], new_r_json["input"]): self.assertTrue(a == b) for a, b in zip(r.to_json()["output"], new_r_json["output"]): self.assertTrue(a == b)