[h5py] 276/455: Update test infrastructure

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:41 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit e1ec6c0910d9d9e9ad6641dcc820db1b2c065a97
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Sun Jun 14 22:59:04 2009 +0000

    Update test infrastructure
---
 h5py/tests/common.py    |   6 ++-
 h5py/tests/test_vlen.py | 125 ++++++++++++++++++++----------------------------
 setup.py                |   2 +-
 3 files changed, 56 insertions(+), 77 deletions(-)

diff --git a/h5py/tests/common.py b/h5py/tests/common.py
index bebc7ce..855a61c 100644
--- a/h5py/tests/common.py
+++ b/h5py/tests/common.py
@@ -32,9 +32,11 @@ class ResourceManager(object):
     def __init__(self):
         self.fnames = set()
 
-    def get_name(self):
+    def get_name(self, suffix=None):
         """ Return a temporary filename, which can be unlinked with clear() """
-        fname = tempfile.mktemp()
+        if suffix is None:
+            suffix = '.hdf5'
+        fname = tempfile.mktemp(suffix)
         self.fnames.add(fname)
         return fname
 
diff --git a/h5py/tests/test_vlen.py b/h5py/tests/test_vlen.py
index 027e964..82a202c 100644
--- a/h5py/tests/test_vlen.py
+++ b/h5py/tests/test_vlen.py
@@ -1,14 +1,22 @@
 
+"""
+    Variable-length data types
+"""
+
 import numpy as np
 import h5py
+
 import unittest
-import os.path as op
-import os
-from common import skip
-from tempfile import mktemp
+from common import res
 
 class TestVlen(unittest.TestCase):
 
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        res.clear()
+
     def test_create(self):
         dt = h5py.new_vlen(str)
         self.assertEqual(str, h5py.get_vlen(dt))
@@ -16,7 +24,7 @@ class TestVlen(unittest.TestCase):
 
     def test_read_attr(self):
         
-        f = h5py.File(op.join(op.dirname(h5py.__file__), 'tests/data/vlstra.h5'), 'r')
+        f = h5py.File(res.get_data_path('vlstra.h5'), 'r')
 
         self.assertEqual(f.attrs['test_scalar'], "This is the string for the attribute")
 
@@ -25,67 +33,49 @@ class TestVlen(unittest.TestCase):
 
     def test_write_attr(self):
 
-        fname = mktemp('.hdf5')
+        f = h5py.File(res.get_name(),'w')
 
-        f = h5py.File(fname,'w')
-        try:
-            value = "This is the string!"
-            
-            dt = h5py.new_vlen(str)
-            f.attrs.create('test_string', value, dtype=dt)
-            self.assertEqual(f.attrs['test_string'], value)
+        value = "This is the string!"
         
-            aid = h5py.h5a.open(f.id, 'test_string')
-            self.assertEqual(dt, aid.dtype)
-        finally:
-            if f:
-                f.close()
-                os.unlink(fname)            
+        dt = h5py.new_vlen(str)
+        f.attrs.create('test_string', value, dtype=dt)
+        self.assertEqual(f.attrs['test_string'], value)
+    
+        aid = h5py.h5a.open(f.id, 'test_string')
+        self.assertEqual(dt, aid.dtype)         
 
 
     def test_read_strings(self):
 
-        f = h5py.File(op.join(op.dirname(h5py.__file__), 'tests/data/strings.h5'), 'r')
+        f = h5py.File(res.get_data_path('strings.h5'), 'r')
 
         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")
 
-        print "\nReading vlen strings:\n"+"-"*60
         dset = f["StringsEx"]
 
-        for idx, x in enumerate(dset):
-            print '%d  "%s"' % (idx, x)
-        print "-"*60
-
-        self.assert_(np.all(refarr == dset[...]))
-        self.assert_(np.all(refarr[2] == dset[2]))
-        self.assert_(np.all(refarr[1:3] == dset[1:3]))
+        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.new_vlen(str))
     
     def test_write_strings(self):
 
-        fname = mktemp('.hdf5')
+        f = h5py.File(res.get_name(), 'w')
 
-        f = h5py.File(fname, 'w')
-        try:
-            dt = h5py.new_vlen(str)
+        dt = h5py.new_vlen(str)
 
-            data_arr = np.array(["Hello there!", "string 2", "", "!!!!!"], dtype=dt)
+        data_arr = np.array(["Hello there!", "string 2", "", "!!!!!"], dtype=dt)
 
-            slices = [np.s_[0], np.s_[1:3], np.s_[...]]
+        slices = [np.s_[0], np.s_[1:3], np.s_[...]]
 
-            dset = f.create_dataset("vlen_ds", (4,), dt)
-            for s in slices:
-                print "slc %s data %s" % (s, data_arr[s])
-                dset[s] = data_arr[s]
-                self.assert_(np.all(dset[s] == data_arr[s]))
-        finally:
-            if f:
-                f.close()
-                os.unlink(fname)            
+        dset = f.create_dataset("vlen_ds", (4,), dt)
+        for s in slices:
+            dset[s] = data_arr[s]
+            self.assert_(np.all(dset[s] == data_arr[s]), "slc %s data %s" % (s, data_arr[s]))
 
 
     def test_compound(self):
@@ -94,47 +84,34 @@ class TestVlen(unittest.TestCase):
         dts = [ [('a_name','>i4'), ('vlen',vlen_dt), ('d_name', '>f4')],
                 [('a_name','=i8'), ('vlen',vlen_dt), ('d_name', '>f4')] ]
 
-        fname = mktemp('.hdf5')
-        f = h5py.File(fname, 'w')
-        try:
-            for dt in dts:
-                if 'vlen_ds' in f:                 del f['vlen_ds']
-                data = np.ndarray((1,),dtype=dt)
-                data['a_name'] = 42
-                data['vlen'] = 'This is a variable-length string'
-                data['d_name'] = 34.5
-                dset = f.create_dataset("vlen_ds", data=data)
-                self.assert_(np.all(dset[...] == data))
-
-        finally:
-            if f:
-                f.close()
-                os.unlink(fname)
+        f = h5py.File(res.get_name(), 'w')
+
+        for dt in dts:
+            if 'vlen_ds' in f:
+                del f['vlen_ds']
+            data = np.ndarray((1,),dtype=dt)
+            data['a_name'] = 42
+            data['vlen'] = 'This is a variable-length string'
+            data['d_name'] = 34.5
+            dset = f.create_dataset("vlen_ds", data=data)
+            self.assert_(np.all(dset[...] == data))
 
     def test_array(self):
 
-        fname = mktemp('.hdf5')
-        f = h5py.File(fname, 'w')
+        f = h5py.File(res.get_name(), 'w')
 
         data = [["Hi", ""],["Hello there", "A string"]]
 
-        try:
-            vlen_dt = h5py.new_vlen(str)
-            arr_dt = np.dtype((vlen_dt, (2,2)))
-
-            arr = np.ndarray((20,), dtype=arr_dt)
-
-            arr[0,:] = data
+        vlen_dt = h5py.new_vlen(str)
+        arr_dt = np.dtype((vlen_dt, (2,2)))
 
-            ds = f.create_dataset('ds', data=arr)
+        arr = np.ndarray((20,), dtype=arr_dt)
 
-            self.assert_(np.all(ds[0] == arr[0]))
-        finally:
-            if f:
-                f.close()
-                os.unlink(fname)            
+        arr[0,:] = data
 
+        ds = f.create_dataset('ds', data=arr)
 
+        self.assert_(np.all(ds[0] == arr[0]))
 
 
 
diff --git a/setup.py b/setup.py
index a761aeb..2b89dd2 100644
--- a/setup.py
+++ b/setup.py
@@ -557,7 +557,7 @@ setup(
   ext_modules = EXTENSIONS,
   requires = ['numpy (>=%s)' % MIN_NUMPY],
   cmdclass = CMD_CLASS,
-  test_suite = 'nose.collector'
+  test_suite = 'h5py.tests'
 )
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list