示例#1
0
 def test_hdf_pandas(self):
     """Values that implement to_hdf/from_hdf, should write themselves to the HDF file correctly."""
     pl = DataContainer(table_name="pandas")
     pl.append(pd.DataFrame({"a": [1, 2], "b": ["x", "y"]}))
     pl.to_hdf(hdf=self.hdf)
     pl2 = self.hdf["pandas"].to_object()
     self.assertEqual(type(pl[0]), type(pl2[0]))
示例#2
0
 def test_hdf_no_wrap(self):
     """Nested mappings should not be wrapped as DataContainer after reading."""
     l = DataContainer(table_name="mappings")
     l.append({"foo": "bar"})
     l.append([1, 2, 3])
     l.to_hdf(self.hdf)
     m = l.copy()
     m.from_hdf(self.hdf, group_name="mappings")
     self.assertEqual(l, m,
                      "List with nested mappings not restored from HDF.")
     self.assertTrue(isinstance(m[0], dict),
                     "dicts wrapped after reading from HDF.")
     self.assertTrue(isinstance(m[1], list),
                     "lists wrapped after reading from HDF.")
示例#3
0
 def test_set_append(self):
     pl = DataContainer()
     # should not raise and exception
     pl[0] = 1
     pl[1] = 2
     self.assertEqual(pl[0], 1, "append via index broken on empty list")
     self.assertEqual(pl[1], 2, "append via index broken on non-empty list")
     pl.append([])
     self.assertTrue(
         isinstance(pl[-1], list),
         "append wraps sequences as DataContainer, but should not")
     pl.append({})
     self.assertTrue(
         isinstance(pl[-1], dict),
         "append wraps mappings as DataContainer, but should not")
示例#4
0
 def test_hdf_complex_members(self):
     """Values that implement to_hdf/from_hdf, should write themselves to the HDF file correctly."""
     pl = DataContainer(table_name="complex")
     pl.append(
         self.project.create_job(self.project.job_type.ScriptJob, "dummy1"))
     pl.append(
         self.project.create_job(self.project.job_type.ScriptJob, "dummy2"))
     pl.append(42)
     pl["foo"] = "bar"
     pl.to_hdf(hdf=self.hdf)
     pl2 = self.hdf["complex"].to_object()
     self.assertEqual(type(pl[0]), type(pl2[0]))
     self.assertEqual(type(pl[1]), type(pl2[1]))