Python h5py.ExternalLink() Examples
The following are 26
code examples of h5py.ExternalLink().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
h5py
, or try the search function
.
Example #1
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #2
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #3
Source File: test_group.py From keras-lambda with MIT License | 6 votes |
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)
Example #4
Source File: test_group.py From keras-lambda with MIT License | 6 votes |
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)
Example #5
Source File: fileops.py From cooler with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _copy(src_uri, dst_uri, overwrite, link, rename, soft_link): src_path, src_group = parse_cooler_uri(src_uri) dst_path, dst_group = parse_cooler_uri(dst_uri) if sum([link, rename, soft_link]) > 1: raise ValueError('Must provide at most one of: "link", "rename", "soft_link"') if not os.path.isfile(dst_path) or overwrite: write_mode = "w" else: write_mode = "r+" with h5py.File(src_path, "r+") as src, h5py.File( dst_path, write_mode ) as dst: # noqa if src_path == dst_path: if link or rename: src[dst_group] = src[src_group] if rename: del src[src_group] elif soft_link: src[dst_group] = h5py.SoftLink(src_group) else: src.copy(src_group, dst_group) else: if link: raise OSError("Can't hard link between two different files.") elif soft_link: dst[dst_group] = h5py.ExternalLink(src_path, src_group) else: if dst_group == "/": for subgrp in src[src_group].keys(): src.copy(src_group + "/" + subgrp, dst, subgrp) dst[dst_group].attrs.update(src[src_group].attrs) else: src.copy(src_group, dst, dst_group if dst_group != "/" else None)
Example #6
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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]))
Example #7
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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)
Example #8
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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')
Example #9
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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)
Example #10
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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']
Example #11
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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'] # I would prefer IOError but there's no way to fix this as the exception # class is determined by HDF5.
Example #12
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
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')
Example #13
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
def test_epath(self): """ External link paths attributes """ el = ExternalLink('foo.hdf5', '/foo') self.assertEqual(el.filename, 'foo.hdf5') self.assertEqual(el.path, '/foo')
Example #14
Source File: test_group.py From keras-lambda with MIT License | 5 votes |
def test_softlinks(self): """ Broken softlinks are contained, but their members are not """ self.f.create_group('grp') self.f['/grp/soft'] = h5py.SoftLink('/mongoose') self.f['/grp/external'] = h5py.ExternalLink('mongoose.hdf5', '/mongoose') self.assertIn('/grp/soft', self.f) self.assertNotIn('/grp/soft/something', self.f) self.assertIn('/grp/external', self.f) self.assertNotIn('/grp/external/something', self.f)
Example #15
Source File: test_file.py From keras-lambda with MIT License | 5 votes |
def test_mode_external(self): """ Mode property works for files opened via external links Issue 190. """ fname1 = self.mktemp() fname2 = self.mktemp() f1 = File(fname1,'w') f1.close() f2 = File(fname2,'w') try: f2['External'] = h5py.ExternalLink(fname1, '/') f3 = f2['External'].file self.assertEqual(f3.mode, 'r+') finally: f2.close() f3.close() f2 = File(fname2,'r') try: f3 = f2['External'].file self.assertEqual(f3.mode, 'r') finally: f2.close() f3.close()
Example #16
Source File: test_file.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_mode_external(self): """ Mode property works for files opened via external links Issue 190. """ fname1 = self.mktemp() fname2 = self.mktemp() f1 = File(fname1,'w') f1.close() f2 = File(fname2,'w') try: f2['External'] = h5py.ExternalLink(fname1, '/') f3 = f2['External'].file self.assertEqual(f3.mode, 'r+') finally: f2.close() f3.close() f2 = File(fname2,'r') try: f3 = f2['External'].file self.assertEqual(f3.mode, 'r') finally: f2.close() f3.close()
Example #17
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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]))
Example #18
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #19
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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"] = "test" self.f['ext'] = ExternalLink(ext_filename, u'/α') self.assertEqual(self.f["ext"].attrs["ext_attr"], "test")
Example #20
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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')
Example #21
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #22
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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']
Example #23
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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'] # I would prefer IOError but there's no way to fix this as the exception # class is determined by HDF5.
Example #24
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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')
Example #25
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_epath(self): """ External link paths attributes """ el = ExternalLink('foo.hdf5', '/foo') self.assertEqual(el.filename, 'foo.hdf5') self.assertEqual(el.path, '/foo')
Example #26
Source File: test_group.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_softlinks(self): """ Broken softlinks are contained, but their members are not """ self.f.create_group('grp') self.f['/grp/soft'] = h5py.SoftLink('/mongoose') self.f['/grp/external'] = h5py.ExternalLink('mongoose.hdf5', '/mongoose') self.assertIn('/grp/soft', self.f) self.assertNotIn('/grp/soft/something', self.f) self.assertIn('/grp/external', self.f) self.assertNotIn('/grp/external/something', self.f)