コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: api_util.py プロジェクト: ScienceStacks/SciSheets
def readObjectFromFile(filepath, verify=False):
  """
  Get the object from the file
  :param str filepath: full path to file
  :param bool verify: checks the file path if the
      object has a getFilepath method
  :return object:
  :raises ValueError: Checks that the file path is set
  Notes: Handles legacy of accessing PCL files, which
         is mostly in tests.
  """
  if ut.getFileExtension(filepath).lower() == 'pcl':
    adj_filepath = ut.changeFileExtension(filepath,
        settings.SCISHEETS_EXT)
  else:
    adj_filepath = filepath
  with open(adj_filepath, "r") as fh:
    json_str = fh.read()
    new_object = deserialize(json_str)
  if 'getFilepath' in dir(new_object):
    if verify and new_object.getFilepath() != adj_filepath:
      if new_object.getFilepath() == filepath:
        new_object.setFilepath(adj_filepath)
      else:
        raise ValueError("File path is incorrect or missing.")
  return new_object
コード例 #4
0
ファイル: api_util.py プロジェクト: zdog234/SciSheets
def readObjectFromFile(filepath, verify=False):
  """
  Get the object from the file
  :param str filepath: full path to file
  :param bool verify: checks the file path if the
      object has a getFilepath method
  :return object:
  :raises ValueError: Checks that the file path is set
  Notes: Handles legacy of accessing PCL files, which
         is mostly in tests.
  """
  if ut.getFileExtension(filepath).lower() == 'pcl':
    adj_filepath = ut.changeFileExtension(filepath,
        settings.SCISHEETS_EXT)
  else:
    adj_filepath = filepath
  with open(adj_filepath, "r") as fh:
    json_str = fh.read()
    new_object = deserialize(json_str)
  if 'getFilepath' in dir(new_object):
    if verify and new_object.getFilepath() != adj_filepath:
      if new_object.getFilepath() == filepath:
        new_object.setFilepath(adj_filepath)
      else:
        raise ValueError("File path is incorrect or missing.")
  return new_object
コード例 #5
0
 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))
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
0
 def testForTable(self):
     setupTableInitialization(self)
     json_str = sd.serialize(self.table)
     new_table = sd.deserialize(json_str)
     self.assertTrue(self.table.isEquivalent(new_table))
コード例 #9
0
 def testDeserializeBasic(self):
     return
     obj = range(10)
     json_str = sd.serialize(obj)
     new_obj = sd.deserialize(json_str)
     self.assertEqual(obj, new_obj)
コード例 #10
0
 def testForTable(self):
   setupTableInitialization(self)
   json_str = sd.serialize(self.table)
   new_table = sd.deserialize(json_str)
   self.assertTrue(self.table.isEquivalent(new_table))
コード例 #11
0
 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))
コード例 #12
0
 def testDeserializeBasic(self):
   return
   obj = range(10)
   json_str = sd.serialize(obj)
   new_obj = sd.deserialize(json_str)
   self.assertEqual(obj, new_obj)