Ejemplo n.º 1
0
 def test_read_attr(self):
     """ (Vlen) Attribute read """
     f = h5py.File(tests.getpath('vlstra.h5'),'r')
     try:
         self.assertEqual(f.attrs['test_scalar'], "This is the string for the attribute")
     finally:
         f.close()
Ejemplo n.º 2
0
 def test_read_attr(self):
     """ (Vlen) Attribute read """
     f = h5py.File(tests.getpath('vlstra.h5'), 'r')
     try:
         self.assertEqual(f.attrs['test_scalar'],
                          "This is the string for the attribute")
     finally:
         f.close()
Ejemplo n.º 3
0
    def test_read_dset(self):
        """ (Vlen) Dataset read """
        f = h5py.File(tests.getpath('strings.h5'), 'r')
        try:
            refarr = np.array(["A fight is a contract that takes two people to honor.",
                               "A combative stance means that you've accepted the contract.",
                               "In which case, you deserve what you get.",
                               "  --  Professor Cheng Man-ch'ing"], dtype="O")

            dset = f["StringsEx"]

            self.assert_(np.all(refarr == dset[...]), "Failed:\n%s" % "\n".join(str(x) for x in dset))
            self.assert_(np.all(refarr[2] == dset[2]), str(dset[2]))
            self.assert_(np.all(refarr[1:3] == dset[1:3]), str(dset[1:3]))

            self.assertEqual(dset.dtype, h5py.special_dtype(vlen=str))
        finally:
            f.close()
Ejemplo n.º 4
0
    def test_read_dset(self):
        """ (Vlen) Dataset read """
        f = h5py.File(tests.getpath('strings.h5'), 'r')
        try:
            refarr = np.array([
                "A fight is a contract that takes two people to honor.",
                "A combative stance means that you've accepted the contract.",
                "In which case, you deserve what you get.",
                "  --  Professor Cheng Man-ch'ing"
            ],
                              dtype="O")

            dset = f["StringsEx"]

            self.assert_(np.all(refarr == dset[...]),
                         "Failed:\n%s" % "\n".join(str(x) for x in dset))
            self.assert_(np.all(refarr[2] == dset[2]), str(dset[2]))
            self.assert_(np.all(refarr[1:3] == dset[1:3]), str(dset[1:3]))

            self.assertEqual(dset.dtype, h5py.special_dtype(vlen=str))
        finally:
            f.close()