[Scipy-svn] r3818 - trunk/scipy/io/tests

scipy-svn@scip... scipy-svn@scip...
Sat Jan 12 01:02:16 CST 2008


Author: matthew.brett@gmail.com
Date: 2008-01-12 01:02:12 -0600 (Sat, 12 Jan 2008)
New Revision: 3818

Removed:
   trunk/scipy/io/tests/test_datasource.py
Modified:
   trunk/scipy/io/tests/test_array_import.py
   trunk/scipy/io/tests/test_mmio.py
   trunk/scipy/io/tests/test_npfile.py
   trunk/scipy/io/tests/test_recaster.py
Log:
Datasource moved to numpy, this removes the tests for it

Modified: trunk/scipy/io/tests/test_array_import.py
===================================================================
--- trunk/scipy/io/tests/test_array_import.py	2008-01-12 06:53:41 UTC (rev 3817)
+++ trunk/scipy/io/tests/test_array_import.py	2008-01-12 07:02:12 UTC (rev 3818)
@@ -6,18 +6,15 @@
 # also check out numpyio.fread.__doc__ and other method docstrings.
 
 import os
-from numpy.testing import *
-set_package_path()
-import io
-from io import numpyio
-restore_path()
+from scipy.testing import *
+import scipy.io as io
+from scipy.io import numpyio
 
-
 import numpy.oldnumeric as N
 import tempfile
 
-class TestNumpyio(NumpyTestCase):
-    def check_basic(self):
+class TestNumpyio(TestCase):
+    def test_basic(self):
         # Generate some data
         a = 255*rand(20)
         # Open a file
@@ -34,8 +31,8 @@
         assert(N.product(a.astype(N.Int16) == b,axis=0))
         os.remove(fname)
 
-class TestReadArray(NumpyTestCase):
-    def check_complex(self):
+class TestReadArray(TestCase):
+    def test_complex(self):
         a = rand(13,4) + 1j*rand(13,4)
         fname = tempfile.mktemp('.dat')
         io.write_array(fname,a)
@@ -43,7 +40,7 @@
         assert_array_almost_equal(a,b,decimal=4)
         os.remove(fname)
 
-    def check_float(self):
+    def test_float(self):
         a = rand(3,4)*30
         fname = tempfile.mktemp('.dat')
         io.write_array(fname,a)
@@ -51,7 +48,7 @@
         assert_array_almost_equal(a,b,decimal=4)
         os.remove(fname)
 
-    def check_integer(self):
+    def test_integer(self):
         from scipy import stats
         a = stats.randint.rvs(1,20,size=(3,4))
         fname = tempfile.mktemp('.dat')
@@ -61,4 +58,4 @@
         os.remove(fname)
 
 if __name__ == "__main__":
-    NumpyTest().run()
+    unittest.main()

Deleted: trunk/scipy/io/tests/test_datasource.py
===================================================================
--- trunk/scipy/io/tests/test_datasource.py	2008-01-12 06:53:41 UTC (rev 3817)
+++ trunk/scipy/io/tests/test_datasource.py	2008-01-12 07:02:12 UTC (rev 3818)
@@ -1,256 +0,0 @@
-
-import bz2
-import gzip
-import os
-import sys
-import struct
-from tempfile import mkdtemp, mkstemp, NamedTemporaryFile
-from shutil import rmtree
-from urlparse import urlparse
-
-from numpy.testing import *
-
-# HACK: import the src datasource
-#       Until datasource is robust enough to include in scipy.io package
-sys.path.insert(0, os.path.abspath('..'))
-import datasource
-del sys.path[0]
-
-#set_package_path()
-#from scipy.io import datasource
-#restore_path()
-
-def urlopen_stub(url, data=None):
-    '''Stub to replace urlopen for testing.'''
-    if url == valid_httpurl():
-        tmpfile = NamedTemporaryFile(prefix='urltmp_')
-        return tmpfile
-    else:
-        raise datasource.URLError('Name or service not known')
-
-# Rebind urlopen during testing.  For a 'real' test, uncomment the rebinding
-# below.
-datasource.urlopen = urlopen_stub
-
-# A valid website for more robust testing
-http_path = 'http://www.google.com/'
-http_file = 'index.html'
-
-http_fakepath = 'http://fake.abc.web/site/'
-http_fakefile = 'fake.txt'
-
-magic_line = 'three is the magic number'
-
-
-# Utility functions used by many TestCases
-def valid_textfile(filedir):
-    # Generate and return a valid temporary file.
-    fd, path = mkstemp(suffix='.txt', prefix='dstmp_', dir=filedir, text=True)
-    os.close(fd)
-    return path
-
-def invalid_textfile(filedir):
-    # Generate and return an invalid filename.
-    fd, path = mkstemp(suffix='.txt', prefix='dstmp_',  dir=filedir)
-    os.close(fd)
-    os.remove(path)
-    return path
-
-def valid_httpurl():
-    return http_path+http_file
-
-def invalid_httpurl():
-    return http_fakepath+http_fakefile
-
-def valid_baseurl():
-    return http_path
-
-def invalid_baseurl():
-    return http_fakepath
-
-def valid_httpfile():
-    return http_file
-
-def invalid_httpfile():
-    return http_fakefile
-
-class TestDataSourceOpen(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-        self.ds = datasource.DataSource(self.tmpdir)
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-        del self.ds
-
-    def test_ValidHTTP(self):
-        assert self.ds.open(valid_httpurl())
-
-    def test_InvalidHTTP(self):
-        self.assertRaises(IOError, self.ds.open, invalid_httpurl())
-
-    def test_ValidFile(self):
-        local_file = valid_textfile(self.tmpdir)
-        assert self.ds.open(local_file)
-
-    def test_InvalidFile(self):
-        invalid_file = invalid_textfile(self.tmpdir)
-        self.assertRaises(IOError, self.ds.open, invalid_file)
-
-    def test_ValidGzipFile(self):
-        # Test datasource's internal file_opener for Gzip files.
-        filepath = os.path.join(self.tmpdir, 'foobar.txt.gz')
-        fp = gzip.open(filepath, 'w')
-        fp.write(magic_line)
-        fp.close()
-        fp = self.ds.open(filepath)
-        result = fp.readline()
-        fp.close()
-        self.assertEqual(magic_line, result)
-
-    def test_ValidBz2File(self):
-        # Test datasource's internal file_opener for BZip2 files.
-        filepath = os.path.join(self.tmpdir, 'foobar.txt.bz2')
-        fp = bz2.BZ2File(filepath, 'w')
-        fp.write(magic_line)
-        fp.close()
-        fp = self.ds.open(filepath)
-        result = fp.readline()
-        fp.close()
-        self.assertEqual(magic_line, result)
-
-
-class TestDataSourceExists(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-        self.ds = datasource.DataSource(self.tmpdir)
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-        del self.ds
-
-    def test_ValidHTTP(self):
-        assert self.ds.exists(valid_httpurl())
-
-    def test_InvalidHTTP(self):
-        self.assertEqual(self.ds.exists(invalid_httpurl()), False)
-
-    def test_ValidFile(self):
-        # Test valid file in destpath
-        tmpfile = valid_textfile(self.tmpdir)
-        assert self.ds.exists(tmpfile)
-        # Test valid local file not in destpath
-        localdir = mkdtemp()
-        tmpfile = valid_textfile(localdir)
-        assert self.ds.exists(tmpfile)
-        rmtree(localdir)
-
-    def test_InvalidFile(self):
-        tmpfile = invalid_textfile(self.tmpdir)
-        self.assertEqual(self.ds.exists(tmpfile), False)
-
-
-class TestDataSourceAbspath(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-        self.ds = datasource.DataSource(self.tmpdir)
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-        del self.ds
-
-    def test_ValidHTTP(self):
-        scheme, netloc, upath, pms, qry, frg = urlparse(valid_httpurl())
-        local_path = os.path.join(self.tmpdir, netloc, upath.strip(os.sep))
-        self.assertEqual(local_path, self.ds.abspath(valid_httpurl()))
-
-    def test_ValidFile(self):
-        tmpfile = valid_textfile(self.tmpdir)
-        tmpfilename = os.path.split(tmpfile)[-1]
-        # Test with filename only
-        self.assertEqual(tmpfile, self.ds.abspath(os.path.split(tmpfile)[-1]))
-        # Test filename with complete path
-        self.assertEqual(tmpfile, self.ds.abspath(tmpfile))
-
-    def test_InvalidHTTP(self):
-        scheme, netloc, upath, pms, qry, frg = urlparse(invalid_httpurl())
-        invalidhttp = os.path.join(self.tmpdir, netloc, upath.strip(os.sep))
-        self.assertNotEqual(invalidhttp, self.ds.abspath(valid_httpurl()))
-
-    def test_InvalidFile(self):
-        invalidfile = valid_textfile(self.tmpdir)
-        tmpfile = valid_textfile(self.tmpdir)
-        tmpfilename = os.path.split(tmpfile)[-1]
-        # Test with filename only
-        self.assertNotEqual(invalidfile, self.ds.abspath(tmpfilename))
-        # Test filename with complete path
-        self.assertNotEqual(invalidfile, self.ds.abspath(tmpfile))
-
-
-class TestRespositoryAbspath(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-        self.repos = datasource.Repository(valid_baseurl(), self.tmpdir)
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-        del self.repos
-
-    def test_ValidHTTP(self):
-        scheme, netloc, upath, pms, qry, frg = urlparse(valid_httpurl())
-        local_path = os.path.join(self.repos._destpath, netloc, \
-                                  upath.strip(os.sep))
-        filepath = self.repos.abspath(valid_httpfile())
-        self.assertEqual(local_path, filepath)
-
-
-class TestRepositoryExists(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-        self.repos = datasource.Repository(valid_baseurl(), self.tmpdir)
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-        del self.repos
-
-    def test_ValidFile(self):
-        # Create local temp file
-        tmpfile = valid_textfile(self.tmpdir)
-        assert self.repos.exists(tmpfile)
-
-    def test_InvalidFile(self):
-        tmpfile = invalid_textfile(self.tmpdir)
-        self.assertEqual(self.repos.exists(tmpfile), False)
-
-    def test_RemoveHTTPFile(self):
-        assert self.repos.exists(valid_httpurl())
-
-    def test_CachedHTTPFile(self):
-        localfile = valid_httpurl()
-        # Create a locally cached temp file with an URL based
-        # directory structure.  This is similar to what Repository.open
-        # would do.
-        scheme, netloc, upath, pms, qry, frg = urlparse(localfile)
-        local_path = os.path.join(self.repos._destpath, netloc)
-        os.mkdir(local_path, 0700)
-        tmpfile = valid_textfile(local_path)
-        assert self.repos.exists(tmpfile)
-
-
-class TestOpenFunc(NumpyTestCase):
-    def setUp(self):
-        self.tmpdir = mkdtemp()
-
-    def tearDown(self):
-        rmtree(self.tmpdir)
-
-    def test_DataSourceOpen(self):
-        local_file = valid_textfile(self.tmpdir)
-        # Test case where destpath is passed in
-        assert datasource.open(local_file, destpath=self.tmpdir)
-        # Test case where default destpath is used
-        assert datasource.open(local_file)
-
-
-if __name__ == "__main__":
-    NumpyTest().run()

Modified: trunk/scipy/io/tests/test_mmio.py
===================================================================
--- trunk/scipy/io/tests/test_mmio.py	2008-01-12 06:53:41 UTC (rev 3817)
+++ trunk/scipy/io/tests/test_mmio.py	2008-01-12 07:02:12 UTC (rev 3818)
@@ -1,17 +1,16 @@
 #!/usr/bin/env python
 
 from tempfile import mktemp
-from numpy.testing import *
 from numpy import array,transpose
+from scipy.testing import *
 
-set_package_path()
-from io.mmio import mminfo,mmread,mmwrite
 import scipy
-restore_path()
+import scipy.sparse
+from scipy.io.mmio import mminfo,mmread,mmwrite
 
-class TestMMIOArray(NumpyTestCase):
+class TestMMIOArray(TestCase):
 
-    def check_simple(self):
+    def test_simple(self):
         a = [[1,2],[3,4]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -19,7 +18,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_rectangular(self):
+    def test_simple_rectangular(self):
         a = [[1,2,3],[4,5,6]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -27,7 +26,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_rectangular_real(self):
+    def test_simple_rectangular_real(self):
         a = [[1,2],[3.5,4],[5,6]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -35,7 +34,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_real(self):
+    def test_simple_real(self):
         a = [[1,2],[3,4.0]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -43,7 +42,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_complex(self):
+    def test_simple_complex(self):
         a = [[1,2],[3,4j]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -51,7 +50,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_symmetric(self):
+    def test_simple_symmetric(self):
         a = [[1,2],[2,4]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -59,7 +58,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_skew_symmetric(self):
+    def test_simple_skew_symmetric(self):
         a = [[1,2],[-2,4]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -67,7 +66,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_skew_symmetric_float(self):
+    def test_simple_skew_symmetric_float(self):
         a = array([[1,2],[-2.0,4]],'f')
         fn = mktemp()
         mmwrite(fn,a)
@@ -75,7 +74,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_simple_hermitian(self):
+    def test_simple_hermitian(self):
         a = [[1,2+3j],[2-3j,4]]
         fn = mktemp()
         mmwrite(fn,a)
@@ -83,7 +82,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_random_symmetric_real(self):
+    def test_random_symmetric_real(self):
         sz = (20,20)
         a = rand(*sz)
         a = a + transpose(a)
@@ -93,7 +92,7 @@
         b = mmread(fn)
         assert_array_almost_equal(a,b)
 
-    def check_random_rect_real(self):
+    def test_random_rect_real(self):
         sz = (20,15)
         a = rand(*sz)
         fn = mktemp()
@@ -184,8 +183,8 @@
     5     4  
 '''
 
-class TestMMIOCoordinate(NumpyTestCase):
-    def check_read_geneal(self):
+class TestMMIOCoordinate(TestCase):
+    def test_read_geneal(self):
         """read a general matrix"""
         fn = mktemp()
         f = open(fn,'w')
@@ -200,7 +199,7 @@
         b = mmread(fn).todense()
         assert_array_almost_equal(a,b)
 
-    def check_read_hermitian(self):
+    def test_read_hermitian(self):
         """read a hermitian matrix"""
         fn = mktemp()
         f = open(fn,'w')
@@ -215,7 +214,7 @@
         b = mmread(fn).todense()
         assert_array_almost_equal(a,b)
     
-    def check_read_skew(self):
+    def test_read_skew(self):
         """read a skew-symmetric matrix"""
         fn = mktemp()
         f = open(fn,'w')
@@ -230,7 +229,7 @@
         b = mmread(fn).todense()
         assert_array_almost_equal(a,b)
     
-    def check_read_symmetric(self):
+    def test_read_symmetric(self):
         """read a symmetric matrix"""
         fn = mktemp()
         f = open(fn,'w')
@@ -245,7 +244,7 @@
         b = mmread(fn).todense()
         assert_array_almost_equal(a,b)
 
-    def check_read_symmetric(self):
+    def test_read_symmetric(self):
         """read a symmetric pattern matrix"""
         fn = mktemp()
         f = open(fn,'w')
@@ -261,7 +260,7 @@
         assert_array_almost_equal(a,b)
 
 
-    def check_real_write_read(self):
+    def test_real_write_read(self):
         I = array([0, 0, 1, 2, 3, 3, 3, 4])
         J = array([0, 3, 1, 2, 1, 3, 4, 4])
         V = array([  1.0,   6.0,   10.5, 0.015,   250.5,  -280.0, 33.32, 12.0 ])
@@ -276,7 +275,7 @@
         b = mmread(fn).todense()
         assert_array_almost_equal(a,b)
 
-    def check_complex_write_read(self):
+    def test_complex_write_read(self):
         I = array([0, 0, 1, 2, 3, 3, 3, 4])
         J = array([0, 3, 1, 2, 1, 3, 4, 4])
         V = array([  1.0 + 3j,    6.0 + 2j,  10.50 + 0.9j, 0.015 + -4.4j,
@@ -293,4 +292,4 @@
         assert_array_almost_equal(a,b)
 
 if __name__ == "__main__":
-    NumpyTest().run()
+    unittest.main()

Modified: trunk/scipy/io/tests/test_npfile.py
===================================================================
--- trunk/scipy/io/tests/test_npfile.py	2008-01-12 06:53:41 UTC (rev 3817)
+++ trunk/scipy/io/tests/test_npfile.py	2008-01-12 07:02:12 UTC (rev 3818)
@@ -1,14 +1,12 @@
+import os
 from StringIO import StringIO
-import os
 from tempfile import mkstemp
-from numpy.testing import *
+from scipy.testing import *
 import numpy as N
 
-set_package_path()
-from io.npfile import npfile, sys_endian_code
-restore_path()
+from scipy.io.npfile import npfile, sys_endian_code
 
-class TestNpFile(NumpyTestCase):
+class TestNpFile(TestCase):
 
     def test_init(self):
         fd, fname = mkstemp()
@@ -102,3 +100,6 @@
         assert_array_equal(npf.read_array(adt, shp, endian='dtype'), bs_arr)
         npf.rewind()
         assert_array_equal(npf.read_array(adt, shp, order='C'), cf_arr)
+
+if __name__ == "__main__":
+    unittest.main()

Modified: trunk/scipy/io/tests/test_recaster.py
===================================================================
--- trunk/scipy/io/tests/test_recaster.py	2008-01-12 06:53:41 UTC (rev 3817)
+++ trunk/scipy/io/tests/test_recaster.py	2008-01-12 07:02:12 UTC (rev 3818)
@@ -1,16 +1,14 @@
-from numpy.testing import *
 import numpy as N
+from scipy.testing import *
 
-set_package_path()
-from io.recaster import sctype_attributes, Recaster, RecastError
-restore_path()
+from scipy.io.recaster import sctype_attributes, Recaster, RecastError
 
 try:  # Python 2.3 support
     from sets import Set as set
 except:
     pass
 
-class TestRecaster(NumpyTestCase):
+class TestRecaster(TestCase):
 
     def test_init(self):
         # Setting sctype_list
@@ -173,3 +171,7 @@
             dtt = arr.dtype.type
             assert dtt is outp, \
                    'Expected %s from %s, got %s' % (outp, inp, dtt)
+            
+if __name__ == "__main__":
+    unittest.main()
+



More information about the Scipy-svn mailing list