예제 #1
0
파일: test_group.py 프로젝트: tovrstra/h5py
    def test_issue_212(self):
        """ Issue 212

        Fails with:

        AttributeError: 'SharedConfig' object has no attribute 'lapl'
        """
        def closer(x):
            def w():
                try:
                    if x:
                        x.close()
                except IOError:
                    pass

            return w

        orig_name = self.mktemp()
        new_name = self.mktemp()
        f = File(orig_name, 'w')
        self.addCleanup(closer(f))
        f.create_group('a')
        f.close()

        g = File(new_name, 'w')
        self.addCleanup(closer(g))
        g['link'] = ExternalLink(orig_name, '/')  # note root group
        g.close()

        h = File(new_name, 'r')
        self.addCleanup(closer(h))
        self.assertIsInstance(h['link']['a'], Group)
예제 #2
0
파일: test_group.py 프로젝트: tovrstra/h5py
 def test_create(self):
     """ Creating external links """
     self.f['ext'] = ExternalLink(self.ename, '/external')
     grp = self.f['ext']
     self.ef = grp.file
     self.assertNotEqual(self.ef, self.f)
     self.assertEqual(grp.name, '/external')
예제 #3
0
 def test_unicode_encode(self):
     """
     Check that external links encode unicode filenames properly
     Testing issue #732
     """
     ext_filename = os.path.join(mkdtemp(), u"α.hdf5")
     with File(ext_filename, "w") as ext_file:
         ext_file.create_group('external')
     self.f['ext'] = ExternalLink(ext_filename, '/external')
예제 #4
0
파일: test_group.py 프로젝트: tovrstra/h5py
    def test_close_file(self):
        """ Files opened by accessing external links can be closed

        Issue 189.
        """
        self.f['ext'] = ExternalLink(self.ename, '/')
        grp = self.f['ext']
        f2 = grp.file
        f2.close()
        self.assertFalse(f2)
예제 #5
0
 def test_unicode_hdf5_path(self):
     """
     Check that external links handle unicode hdf5 paths properly
     Testing issue #333
     """
     ext_filename = os.path.join(mkdtemp(), "external.hdf5")
     with File(ext_filename, "w") as ext_file:
         ext_file.create_group(u'α')
         ext_file[u"α"].attrs["ext_attr"] = "code"
     self.f['ext'] = ExternalLink(ext_filename, u'/α')
     self.assertEqual(self.f["ext"].attrs["ext_attr"], "code")
예제 #6
0
 def test_unicode_decode(self):
     """
     Check that external links decode unicode filenames properly
     Testing issue #732
     """
     ext_filename = os.path.join(mkdtemp(), u"α.hdf5")
     with File(ext_filename, "w") as ext_file:
         ext_file.create_group('external')
         ext_file["external"].attrs["ext_attr"] = "code"
     self.f['ext'] = ExternalLink(ext_filename, '/external')
     self.assertEqual(self.f["ext"].attrs["ext_attr"], "code")
예제 #7
0
파일: test_group.py 프로젝트: tovrstra/h5py
    def test_copy_external_links(self):

        filename = self.f1.filename
        self.f1['foo'] = [1, 2, 3]
        self.f2['bar'] = ExternalLink(filename, 'foo')
        self.f1.close()
        self.f1 = None

        self.assertArrayEqual(self.f2['bar'], np.array([1, 2, 3]))

        self.f2.copy('bar', 'baz', expand_external=True)
        os.unlink(filename)
        self.assertArrayEqual(self.f2['baz'], np.array([1, 2, 3]))
예제 #8
0
파일: test_group.py 프로젝트: tovrstra/h5py
    def test_get_link_class(self):
        """ Get link classes """
        default = object()

        sl = SoftLink('/mongoose')
        el = ExternalLink('somewhere.hdf5', 'mongoose')

        self.f.create_group('hard')
        self.f['soft'] = sl
        self.f['external'] = el

        out_hl = self.f.get('hard', default, getlink=True, getclass=True)
        out_sl = self.f.get('soft', default, getlink=True, getclass=True)
        out_el = self.f.get('external', default, getlink=True, getclass=True)

        self.assertEqual(out_hl, HardLink)
        self.assertEqual(out_sl, SoftLink)
        self.assertEqual(out_el, ExternalLink)
예제 #9
0
파일: test_group.py 프로젝트: tovrstra/h5py
    def test_get_link(self):
        """ Get link values """
        sl = SoftLink('/mongoose')
        el = ExternalLink('somewhere.hdf5', 'mongoose')

        self.f.create_group('hard')
        self.f['soft'] = sl
        self.f['external'] = el

        out_hl = self.f.get('hard', getlink=True)
        out_sl = self.f.get('soft', getlink=True)
        out_el = self.f.get('external', getlink=True)

        #TODO: redo with SoftLink/ExternalLink built-in equality
        self.assertIsInstance(out_hl, HardLink)
        self.assertIsInstance(out_sl, SoftLink)
        self.assertEqual(out_sl._path, sl._path)
        self.assertIsInstance(out_el, ExternalLink)
        self.assertEqual(out_el._path, el._path)
        self.assertEqual(out_el._filename, el._filename)
예제 #10
0
파일: test_group.py 프로젝트: tovrstra/h5py
 def test_exc_missingfile(self):
     """ KeyError raised when attempting to open missing file """
     self.f['ext'] = ExternalLink('mongoose.hdf5', '/foo')
     with self.assertRaises(KeyError):
         self.f['ext']
예제 #11
0
파일: test_group.py 프로젝트: tovrstra/h5py
 def test_exc(self):
     """ KeyError raised when attempting to open broken link """
     self.f['ext'] = ExternalLink(self.ename, '/missing')
     with self.assertRaises(KeyError):
         self.f['ext']
예제 #12
0
파일: test_group.py 프로젝트: tovrstra/h5py
 def test_erepr(self):
     """ External link repr """
     el = ExternalLink('foo.hdf5', '/foo')
     self.assertIsInstance(repr(el), basestring)
예제 #13
0
파일: test_group.py 프로젝트: tovrstra/h5py
 def test_epath(self):
     """ External link paths attributes """
     el = ExternalLink('foo.hdf5', '/foo')
     self.assertEqual(el.filename, 'foo.hdf5')
     self.assertEqual(el.path, '/foo')