def testDeserializeWithHook(self): obj1 = range(10) obj2 = TestObject(5) json_str = sd.serialize([obj1, obj2]) [new_obj1, new_obj2] = sd.deserialize(json_str) self.assertEqual(obj2.a_list, new_obj2.a_list) json_str = sd.serialize(obj2) new_obj2 = sd.deserialize(json_str) self.assertEqual(obj2.a_list, new_obj2.a_list)
def testForColumn(self): self.column = createColumn(COLUMN_NAME, data=LIST, table=None, formula=VALID_FORMULA) json_str = sd.serialize(self.column) new_column = sd.deserialize(json_str) self.assertTrue(self.column.isEquivalent(new_column))
def testDeserializeWithHookForLists(self): obj = [np.array(range(x)) for x in range(5)] json_str = sd.serialize(obj) new_obj = sd.deserialize(json_str) self.assertEqual(len(obj), len(new_obj)) pairs = zip(obj, new_obj) for o1, o2 in pairs: self.assertEqual(o1.tolist(), o2)
def testSerializeWithHook(self): return obj1 = range(10) obj2 = TestObject(5) json_str = sd.serialize([obj1, obj2]) [new_obj1, obj2_dict] = json.loads(json_str) new_obj2 = TestObject(obj2_dict['range_length']) self.assertEqual(obj2.a_list, new_obj2.a_list)
def writeObjectToFile(an_object, filepath=None): """ Serializes and writes the object to the file :param object an_object: :param str filepath: :raises ValueError: if cannot find a filepath """ if 'getFilepath' in dir(an_object): filepath = an_object.getFilepath() if filepath is None: raise ValueError("No way to find filepath") with open(filepath, "w") as fh: fh.write(serialize(an_object))
def _serializeTable(table): with open(table.getFilepath(), "w") as fh: fh.write(serialize(table))
def testForTable(self): setupTableInitialization(self) json_str = sd.serialize(self.table) new_table = sd.deserialize(json_str) self.assertTrue(self.table.isEquivalent(new_table))
def testSerializeBasic(self): return obj = {"a": range(10)} json_str = sd.serialize(obj) self.assertEqual(json.loads(json_str), obj)
def testDeserializeBasic(self): return obj = range(10) json_str = sd.serialize(obj) new_obj = sd.deserialize(json_str) self.assertEqual(obj, new_obj)