[Scipy-svn] r6802 - in trunk/scipy/io: arff/tests matlab/tests tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Sep 12 17:46:09 EDT 2010


Author: warren.weckesser
Date: 2010-09-12 16:46:08 -0500 (Sun, 12 Sep 2010)
New Revision: 6802

Modified:
   trunk/scipy/io/arff/tests/test_arffread.py
   trunk/scipy/io/matlab/tests/test_byteordercodes.py
   trunk/scipy/io/tests/test_wavfile.py
Log:
TST: io: Don't use 'import *'. Don't use plain 'assert'.  Simplify a test by using 'assert_raises'.

Modified: trunk/scipy/io/arff/tests/test_arffread.py
===================================================================
--- trunk/scipy/io/arff/tests/test_arffread.py	2010-09-12 21:31:02 UTC (rev 6801)
+++ trunk/scipy/io/arff/tests/test_arffread.py	2010-09-12 21:46:08 UTC (rev 6802)
@@ -4,7 +4,8 @@
 
 import numpy as np
 
-from numpy.testing import TestCase, assert_array_almost_equal, assert_equal
+from numpy.testing import TestCase, assert_array_almost_equal, assert_equal, \
+        assert_, assert_raises
 
 from scipy.io.arff.arffread import loadarff
 from scipy.io.arff.arffread import read_header, parse_type, ParseArffError
@@ -61,7 +62,7 @@
                     'numeric', 'string', 'string', 'nominal', 'nominal']
 
         for i in range(len(attrs)):
-            assert parse_type(attrs[i][1]) == expected[i]
+            assert_(parse_type(attrs[i][1]) == expected[i])
 
     def test_badtype_parsing(self):
         """Test parsing wrong type of attribute from their value."""
@@ -69,11 +70,7 @@
         rel, attrs = read_header(ofile)
 
         for name, value in attrs:
-            try:
-                parse_type(value)
-                raise Error("Could parse type of crap, should not happen.")
-            except ParseArffError:
-                pass
+            assert_raises(ParseArffError, parse_type, value)
 
     def test_fullheader1(self):
         """Parsing trivial header with nothing."""
@@ -81,18 +78,18 @@
         rel, attrs = read_header(ofile)
 
         # Test relation
-        assert rel == 'test1'
+        assert_(rel == 'test1')
 
         # Test numerical attributes
-        assert len(attrs) == 5
+        assert_(len(attrs) == 5)
         for i in range(4):
-            assert attrs[i][0] == 'attr%d' % i
-            assert attrs[i][1] == 'REAL'
+            assert_(attrs[i][0] == 'attr%d' % i)
+            assert_(attrs[i][1] == 'REAL')
         classes = attrs[4][1]
 
         # Test nominal attribute
-        assert attrs[4][0] == 'class'
-        assert attrs[4][1] == '{class0, class1, class2, class3}'
+        assert_(attrs[4][0] == 'class')
+        assert_(attrs[4][1] == '{class0, class1, class2, class3}')
 
 if __name__ == "__main__":
     import nose

Modified: trunk/scipy/io/matlab/tests/test_byteordercodes.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_byteordercodes.py	2010-09-12 21:31:02 UTC (rev 6801)
+++ trunk/scipy/io/matlab/tests/test_byteordercodes.py	2010-09-12 21:46:08 UTC (rev 6802)
@@ -2,29 +2,28 @@
 
 import sys
 
-import numpy as np
+from numpy.testing import assert_raises, assert_, run_module_suite
 
-from numpy.testing import assert_raises, run_module_suite
-
 import scipy.io.matlab.byteordercodes as sibc
 
+
 def test_native():
     native_is_le = sys.byteorder == 'little'
-    assert sibc.sys_is_le == native_is_le
+    assert_(sibc.sys_is_le == native_is_le)
 
 def test_to_numpy():
     if sys.byteorder == 'little':
-        assert sibc.to_numpy_code('native') == '<'
-        assert sibc.to_numpy_code('swapped') == '>'
+        assert_(sibc.to_numpy_code('native') == '<')
+        assert_(sibc.to_numpy_code('swapped') == '>')
     else:
-        assert sibc.to_numpy_code('native') == '>'
-        assert sibc.to_numpy_code('swapped') == '<'
-    assert sibc.to_numpy_code('native') == sibc.to_numpy_code('=')
-    assert sibc.to_numpy_code('big') == '>'
+        assert_(sibc.to_numpy_code('native') == '>')
+        assert_(sibc.to_numpy_code('swapped') == '<')
+    assert_(sibc.to_numpy_code('native') == sibc.to_numpy_code('='))
+    assert_(sibc.to_numpy_code('big') == '>')
     for code in ('little', '<', 'l', 'L', 'le'):
-        assert sibc.to_numpy_code(code) == '<'
+        assert_(sibc.to_numpy_code(code) == '<')
     for code in ('big', '>', 'b', 'B', 'be'):
-        assert sibc.to_numpy_code(code) == '>'
+        assert_(sibc.to_numpy_code(code) == '>')
     assert_raises(ValueError, sibc.to_numpy_code, 'silly string')
 
 if __name__ == "__main__":

Modified: trunk/scipy/io/tests/test_wavfile.py
===================================================================
--- trunk/scipy/io/tests/test_wavfile.py	2010-09-12 21:31:02 UTC (rev 6801)
+++ trunk/scipy/io/tests/test_wavfile.py	2010-09-12 21:46:08 UTC (rev 6802)
@@ -2,7 +2,7 @@
 import tempfile
 import numpy as np
 
-from numpy.testing import *
+from numpy.testing import assert_equal, assert_, assert_raises, assert_array_equal
 from scipy.io import wavfile
 
 def datafile(fn):
@@ -10,15 +10,15 @@
 
 def test_read_1():
     rate, data = wavfile.read(datafile('test-44100-le-1ch-4bytes.wav'))
-    assert rate == 44100
-    assert np.issubdtype(data.dtype, np.int32)
-    assert data.shape == (4410,)
+    assert_equal(rate, 44100)
+    assert_(np.issubdtype(data.dtype, np.int32))
+    assert_equal(data.shape, (4410,))
 
 def test_read_2():
     rate, data = wavfile.read(datafile('test-8000-le-2ch-1byteu.wav'))
-    assert rate == 8000
-    assert np.issubdtype(data.dtype, np.uint8)
-    assert data.shape == (800, 2)
+    assert_equal(rate, 8000)
+    assert_(np.issubdtype(data.dtype, np.uint8))
+    assert_equal(data.shape, (800, 2))
 
 def test_read_fail():
     assert_raises(ValueError, wavfile.read, datafile('example_1.nc'))
@@ -36,8 +36,8 @@
         wavfile.write(tmpfile, rate, data)
         rate2, data2 = wavfile.read(tmpfile)
 
-        assert rate == rate2
-        assert data2.dtype.byteorder in ('<', '=', '|'), data2.dtype
+        assert_equal(rate, rate2)
+        assert_(data2.dtype.byteorder in ('<', '=', '|'), msg=data2.dtype)
         assert_array_equal(data, data2)
     finally:
         os.unlink(tmpfile)




More information about the Scipy-svn mailing list