[h5py] 277/455: Dump python-nose

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 50b31e83ab1620746243050bcb949006e190e895
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Mon Jun 15 19:51:27 2009 +0000

    Dump python-nose
---
 h5py/tests/__init__.py       | 37 ++++++++++++++++++++++++++++++++-----
 h5py/tests/common.py         | 11 +++++++----
 h5py/tests/test_dataset.py   | 14 ++++++++------
 h5py/tests/test_filters.py   | 36 ++++++++++++++++++------------------
 h5py/tests/test_highlevel.py | 38 ++++++++++++--------------------------
 h5py/tests/test_slicing.py   | 36 +++++++++++++++---------------------
 6 files changed, 92 insertions(+), 80 deletions(-)

diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index 088fabf..505e285 100644
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -10,12 +10,39 @@
 # 
 #-
 
+import h5py.tests
+import unittest
+
+mnames = [
+'test_dataset',
+'test_filters',
+'test_h5a',
+'test_h5d',
+'test_h5f',
+'test_h5g',
+'test_h5i',
+'test_h5p',
+'test_h5',
+'test_h5r',
+'test_h5s',
+'test_h5t',
+'test_highlevel',
+'test_slicing',
+'test_threads',
+'test_utils',
+'test_vlen']
+
+
 def runtests():
-    try:
-        import nose
-    except ImportError:
-        raise ImportError("python-nose is required to run unit tests")
-    nose.run('h5py.tests')
+
+    ldr = unittest.TestLoader()
+    suite = unittest.TestSuite()
+    modules = [__import__('h5py.tests.'+x, fromlist=[h5py.tests]) for x in mnames]
+    for m in modules:
+        suite.addTests(ldr.loadTestsFromModule(m))
+
+    runner = unittest.TextTestRunner()
+    return runner.run(suite)
 
 def autotest():
     try:
diff --git a/h5py/tests/common.py b/h5py/tests/common.py
index 855a61c..5b61200 100644
--- a/h5py/tests/common.py
+++ b/h5py/tests/common.py
@@ -56,7 +56,11 @@ class ResourceManager(object):
         """ Return the full path to a data file (given its basename) """
         return op.abspath(op.join(DATADIR, name))
 
-    
+    def get_data_copy(self, name):
+        iname = self.get_data_path(name)
+        fname = self.get_name()
+        shutil.copy(iname, fname)
+        return fname
 
 res = ResourceManager()
 
@@ -101,7 +105,6 @@ def delhdf(f):
 
 EPSILON = 1e-5
 import numpy as np
-from nose.tools import assert_equal
 
 INTS = ('i', 'i1', '<i2', '>i2', '<i4', '>i4')
 FLOATS = ('f', '<f4', '>f4', '<f8', '>f8')
@@ -125,8 +128,8 @@ def assert_arr_equal(dset, arr, message=None, precision=None):
         assert dset - arr < precision, message
         return
 
-    assert_equal(dset.shape, arr.shape, message)
-    assert_equal(dset.dtype, arr.dtype, message)
+    assert dset.shape == arr.shape, message
+    assert dset.dtype == arr.dtype, message
     assert np.all(np.abs(dset[...] - arr[...]) < precision), "%s %s" % (dset[...], arr[...]) if not message else message
 
 class HDF5TestCase(unittest.TestCase):
diff --git a/h5py/tests/test_dataset.py b/h5py/tests/test_dataset.py
index c2d5c95..5354dca 100644
--- a/h5py/tests/test_dataset.py
+++ b/h5py/tests/test_dataset.py
@@ -7,16 +7,18 @@
 
 import numpy as np
 
+import h5py
+import unittest
 from common import makehdf, delhdf, assert_arr_equal,\
-                   INTS, FLOATS, COMPLEX, STRINGS
+                   INTS, FLOATS, COMPLEX, STRINGS, res
 
-class TestDataset(object):
+class TestDataset(unittest.TestCase):
 
     def setUp(self):
-        self.f = makehdf()
+        self.f = h5py.File(res.get_name(), 'w')
     
     def tearDown(self):
-        delhdf(self.f)
+        res.clear()
 
     def make_dset(self, *args, **kwds):
         if 'dset' in self.f:
@@ -33,7 +35,7 @@ class TestDataset(object):
             srcdata = np.arange(np.product(s)).reshape(s)
 
             for t in types:
-                print "test %s %s" % (s, t)
+                msg = "test %s %s" % (s, t)
                 data = srcdata.astype(t)
 
                 dset = self.make_dset(s, t)
@@ -44,7 +46,7 @@ class TestDataset(object):
 
                 dset = self.make_dset(data=data)
  
-                assert np.all(dset[...] == data)
+                assert np.all(dset[...] == data), msg
 
                 
                 
diff --git a/h5py/tests/test_filters.py b/h5py/tests/test_filters.py
index a3f529d..c517cd8 100644
--- a/h5py/tests/test_filters.py
+++ b/h5py/tests/test_filters.py
@@ -2,17 +2,17 @@ import numpy as np
 import h5py
 from h5py import filters
 
-from nose.tools import assert_equal, assert_raises
+import unittest
 
-from common import makehdf, delhdf
+from common import res
 
-class TestFilters(object):
+class TestFilters(unittest.TestCase):
 
     def setUp(self):
-        self.f = makehdf()
+        self.f = h5py.File(res.get_name(), 'w')
 
     def tearDown(self):
-        delhdf(self.f)
+        res.clear()
 
     def make_dset(self, shape=None, dtype=None, **kwds):
         if 'dset' in self.f:
@@ -37,7 +37,7 @@ class TestFilters(object):
 
         for kwds, result in pairs:
             dset = self.make_dset((10,10), **kwds)
-            assert_equal(bool(dset.chunks), result)
+            self.assertEqual(bool(dset.chunks), result)
 
         # Test user-defined chunking
         shapes = [(), (1,), (10,5), (1,10), (2**60, 2**60, 2**34)]
@@ -50,7 +50,7 @@ class TestFilters(object):
         for shape in shapes:
             for chunk in chunks[shape]:
                 dset = self.make_dset(shape, chunks=chunk)
-                assert_equal(dset.chunks, chunk)
+                self.assertEqual(dset.chunks, chunk)
 
     def test_compression(self):
         # Dataset compression keywords only
@@ -65,10 +65,10 @@ class TestFilters(object):
             opts     += (filters.DEFAULT_SZIP,)
 
         for s, r, o in zip(settings, results, opts):
-            print 'compression "%s"' % s
+            msg =  'compression "%s"' % s
             dset = self.make_dset(compression=s)
-            assert_equal(dset.compression, r)
-            assert_equal(dset.compression_opts, o)
+            self.assertEqual(dset.compression, r, msg)
+            self.assertEqual(dset.compression_opts, o, msg)
 
     def test_compression_opts(self):
         # Dataset compression keywords & options
@@ -82,10 +82,10 @@ class TestFilters(object):
 
         for t in types:
             for o in opts[t]:
-                print "compression %s %s" % (t, o)
+                msg = "compression %s %s" % (t, o)
                 dset = self.make_dset(compression=t, compression_opts=o)
-                assert_equal(dset.compression, t)
-                assert_equal(dset.compression_opts, o)
+                self.assertEqual(dset.compression, t, msg)
+                self.assertEqual(dset.compression_opts, o, msg)
 
     def test_fletcher32_shuffle(self):
         # Check fletcher32 and shuffle
@@ -94,11 +94,11 @@ class TestFilters(object):
         results = (False, False, True)
 
         for s, r in zip(settings, results):
-            print "test %s %s" % (s,r)
+            msg = "test %s %s" % (s,r)
             dset = self.make_dset(fletcher32=s)
-            assert_equal(dset.fletcher32, r)
+            self.assertEqual(dset.fletcher32, r, msg)
             dset = self.make_dset(shuffle=s)
-            assert_equal(dset.shuffle, r)
+            self.assertEqual(dset.shuffle, r, msg)
 
     def test_data(self):
         # Ensure data can be read/written with filters
@@ -110,12 +110,12 @@ class TestFilters(object):
         types = ('f','i', 'c')
 
         def test_dset(shape, dtype, **kwds):
-            print "test %s %s %s" % (shape, dtype, kwds)
+            msg = "test %s %s %s" % (shape, dtype, kwds)
 
             dset = self.make_dset(s, dtype, **kwds)
             arr = (np.random.random(s)*100).astype(dtype)
             dset[...] = arr
-            assert np.all(dset[...] == arr)
+            assert np.all(dset[...] == arr), msg
 
         for s in shapes:
             for t in types:
diff --git a/h5py/tests/test_highlevel.py b/h5py/tests/test_highlevel.py
index e7e5c89..7fe91d3 100644
--- a/h5py/tests/test_highlevel.py
+++ b/h5py/tests/test_highlevel.py
@@ -20,7 +20,7 @@ import numpy
 from h5py.highlevel import *
 from h5py import *
 from h5py.h5 import H5Error
-from common import getfullpath, HDF5TestCase, api_18, api_16
+from common import getfullpath, HDF5TestCase, api_18, api_16, res
 import testfiles
 
 class SliceFreezer(object):
@@ -48,12 +48,10 @@ SHAPES = [(), (1,), (10,5), (1,10), (10,1), (100,1,100), (51,2,1025)]
 class TestFile(HDF5TestCase):
 
     def setUp(self):
-        newname = tempfile.mktemp('.hdf5')
-        shutil.copy(HDFNAME, newname)
-        self.fname = newname
+        self.fname = res.get_data_copy(HDFNAME)
 
     def tearDown(self):
-        os.unlink(self.fname)
+        res.clear()
 
     def test_unicode(self):
         # Two cases:
@@ -61,21 +59,13 @@ class TestFile(HDF5TestCase):
         #       Store w/filesystem encoding; should be readable as Unicode
         # 2. Raw byte string in ASCII range
         #       Store w/filesystem encoding; should be read as ASCII
-        fnames = (tempfile.mktemp(u'_\u201a.hdf5'),
-                  tempfile.mktemp('_.hdf5'))
-        print ""
-        for fname, typ in zip(fnames, (unicode, str, str)):
-            print 'checking "%r" (%s)' % (fname, typ)
-            f = None
-            try:
-                f = File(fname, 'w')
-                self.assert_(isinstance(f.filename, typ))
-                self.assertEqual(f.filename, fname)
-            finally:
-                if f:
-                    f.close()
-                if os.path.exists(fname):
-                    os.unlink(fname)
+        fnames = [res.get_name(u'_\u201a.hdf5'), res.get_name('_.hdf5')]
+        for fname, typ in zip(fnames, [unicode, str]):
+            msg = 'checking "%r" (%s)' % (fname, typ)
+            f = File(fname, 'w')
+            self.assert_(isinstance(f.filename, typ), msg)
+            self.assertEqual(f.filename, fname, msg)
+            f.close()
         
     def test_File_init_r(self):
         with File(self.fname, 'r') as f:
@@ -391,7 +381,6 @@ class TestExceptions(HDF5TestCase):
                      "create_dataset": ("foobar", (), 'i'),}
 
         for meth, args in valerrors.iteritems():
-            print "    Testing %s" % meth
             self.assertRaises(ValueError, getattr(self.f, meth), *args)
 
     def test_attributes(self):
@@ -422,13 +411,10 @@ class TestExceptions(HDF5TestCase):
 class TestGroup(HDF5TestCase):
 
     def setUp(self):
-
-        self.fname = tempfile.mktemp('.hdf5')
-        self.f = File(self.fname, 'w')
+        self.f = File(res.get_name(), 'w')
 
     def tearDown(self):
-        self.f.close()
-        os.unlink(self.fname)
+        res.clear()
 
     def assert_equal_contents(self, a, b):
         self.assertEqual(set(a), set(b))
diff --git a/h5py/tests/test_slicing.py b/h5py/tests/test_slicing.py
index 8174912..b182da3 100644
--- a/h5py/tests/test_slicing.py
+++ b/h5py/tests/test_slicing.py
@@ -1,8 +1,8 @@
 import numpy as np
 import os
-from nose.tools import assert_equal
+import unittest
 
-from common import makehdf, delhdf, assert_arr_equal, skip
+from common import makehdf, delhdf, assert_arr_equal, skip, res
 
 import h5py
 
@@ -14,13 +14,13 @@ class SliceFreezer(object):
 
 s = SliceFreezer()
 
-class TestSlicing(object):
+class TestSlicing(unittest.TestCase):
 
     def setUp(self):
-        self.f = makehdf()
+        self.f = h5py.File(res.get_name(), 'w')
 
     def tearDown(self):
-        delhdf(self.f)
+        res.clear()
 
     def generate(self, shape, dtype):
 
@@ -59,26 +59,22 @@ class TestSlicing(object):
 
         for slc in slices:
 
-            print "slice %s" % (slc,)
+            msg = " slice %s" % (slc,)
 
-            print "    write"
             arr[slc] += np.random.rand()
             dset[slc] = arr[slc]
-            assert_arr_equal(dset, arr)
+            assert_arr_equal(dset, arr, "write"+msg)
 
-            print "    read"
             out = dset[slc]
-            assert_arr_equal(out, arr[slc])
+            assert_arr_equal(out, arr[slc], "read"+msg)
 
-            print "    write direct"
             arr[slc] += np.random.rand()
             dset.write_direct(arr, slc, slc)
-            assert_arr_equal(dset, arr)
+            assert_arr_equal(dset, arr, "write direct"+msg)
 
-            print "    read direct"
             out = np.ndarray(shape, 'f')
             dset.read_direct(out, slc, slc)
-            assert_arr_equal(out[slc], arr[slc])
+            assert_arr_equal(out[slc], arr[slc], "read direct"+msg)
 
     def test_slices_big(self):
         # Test slicing behavior for indices larger than 2**32
@@ -90,20 +86,19 @@ class TestSlicing(object):
         regions = [ (42,1), (100,100), (1,42), (1,1), (4,1025)]
 
         for base in bases:
-            print "Testing base 2**%d" % np.log2(base)
 
             slices = [ s[base:base+x, base:base+y] for x, y in regions]
 
             dset = self.generate_dset(shape, dtype, maxshape=(None, None))
 
             for region, slc in zip(regions, slices):
-                print "    Testing shape %s slice %s" % (region, slc,)
+                msg = "Testing base %s shape %s slice %s" % (np.log2(base), region, slc,)
         
                 data = np.arange(np.product(region), dtype=dtype).reshape(region)
 
                 dset[slc] = data
 
-                assert_arr_equal(dset[slc], data)
+                assert_arr_equal(dset[slc], data, msg)
 
     def test_scalars(self):
         # Confirm correct behavior for scalar datasets
@@ -132,10 +127,9 @@ class TestSlicing(object):
 
             subarr = np.random.random(shape)
 
-            print "broadcast %s %s" % (slc, shape)
             dset[slc] = subarr
             arr[slc] = subarr
-            assert_arr_equal(dset, arr)
+            assert_arr_equal(dset, arr, "broadcast %s %s" % (slc, shape))
 
 
     @skip
@@ -173,8 +167,8 @@ class TestSlicing(object):
                    (s['b',...,5], srcarr[...,5]['b']) ]
 
         for slc, result in pairs:
-            print "slicing %s" % (slc,)
-            assert np.all(dset[slc] == result)
+            msg = "slicing %s" % (slc,)
+            assert np.all(dset[slc] == result), msg
 
 
 

-- 
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