[Numpy-discussion] How to run unittests at build time?

Filipe Pires Alvarenga Fernandes ocefpaf@gmail....
Wed Sep 21 16:15:14 CDT 2011


Don't know about about Debian, but this works OK for RPM distros:

PYTHONPATH="%{buildroot}%{py_sitedir}" %{__python} -c \
                                    "import pkg_resources, numpy ; numpy.test()"

The only thing you are missing is the "import pkg_resources", let me
know if that works for you.

-Filipe


On Wed, Sep 21, 2011 at 16:56, Sandro Tosi <morph@debian.org> wrote:
> Hello,
> at (Debian) package build time, it would be really important to run
> the tests suite, but I'm not getting how to do that.
>
> The simple approach doesn't work:
>
>>>>
> $ PYTHONPATH=build/lib.linux-x86_64-2.6 python -c "import numpy; numpy.test()"
> Traceback (most recent call last):
>  File "<string>", line 1, in <module>
>  File "numpy/__init__.py", line 127, in <module>
>    raise ImportError(msg)
> ImportError: Error importing numpy: you should not try to import numpy from
>        its source directory; please exit the numpy source tree, and relaunch
>        your python intepreter from there.
> <<<
>
> because '.' is placed first in the sys.path list, so it gets used the
> numpy/ dir in . instead the one in build/lib... . Ok, so let's tune
> sys.path:
>
>>>>
> $ python -c "import sys ; sys.path.insert(0,
> 'build/lib.linux-x86_64-2.6') ; import numpy; numpy.test()"
> Running unit tests for numpy
> NumPy version 1.6.1
> NumPy is installed in build/lib.linux-x86_64-2.6/numpy
> Python version 2.6.7 (r267:88850, Aug  3 2011, 11:33:52) [GCC 4.6.1]
> nose version 1.0.0
> EEEEEEE
> ======================================================================
> ERROR: Failure: NameError (name 'numeric' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module>
>    __all__ += numeric.__all__
> NameError: name 'numeric' is not defined
>
> ======================================================================
> ERROR: Failure: ImportError (cannot import name log)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/distutils/fcompiler/__init__.py",
> line 37, in <module>
>    from numpy.distutils import log
> ImportError: cannot import name log
>
> ======================================================================
> ERROR: Failure: NameError (name 'type_check' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module>
>    __all__ += type_check.__all__
> NameError: name 'type_check' is not defined
>
> ======================================================================
> ERROR: Failure: NameError (name 'numeric' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/ma/testutils.py", line 17, in <module>
>    import numpy.core.umath as umath
>  File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module>
>    __all__ += numeric.__all__
> NameError: name 'numeric' is not defined
>
> ======================================================================
> ERROR: Failure: NameError (name 'defmatrix' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/matrixlib/__init__.py", line
> 4, in <module>
>    __all__ = defmatrix.__all__
> NameError: name 'defmatrix' is not defined
>
> ======================================================================
> ERROR: Failure: NameError (name 'numeric' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 86, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/__init__.py", line
> 14, in <module>
>    from compat import *
>  File "build/lib.linux-x86_64-2.6/numpy/oldnumeric/compat.py", line
> 13, in <module>
>    import numpy.core.multiarray as multiarray
>  File "build/lib.linux-x86_64-2.6/numpy/core/__init__.py", line 30, in <module>
>    __all__ += numeric.__all__
> NameError: name 'numeric' is not defined
>
> ======================================================================
> ERROR: Failure: NameError (name 'type_check' is not defined)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/usr/lib/pymodules/python2.6/nose/loader.py", line 390, in
> loadTestsFromName
>    addr.filename, addr.module)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 39, in
> importFromPath
>    return self.importFromDir(dir_path, fqname)
>  File "/usr/lib/pymodules/python2.6/nose/importer.py", line 84, in
> importFromDir
>    mod = load_module(part_fqname, fh, filename, desc)
>  File "build/lib.linux-x86_64-2.6/numpy/polynomial/__init__.py", line
> 28, in <module>
>    from numpy.lib import deprecate
>  File "build/lib.linux-x86_64-2.6/numpy/lib/__init__.py", line 23, in <module>
>    __all__ += type_check.__all__
> NameError: name 'type_check' is not defined
>
> ----------------------------------------------------------------------
> Ran 7 tests in 0.004s
>
> FAILED (errors=7)
> <<<
>
> Not nice either, let's try another way, importing * from numpy:
>
> $ python -c "import sys ; sys.path.insert(0,
> 'build/lib.linux-x86_64-2.6') ; import numpy; from numpy import * ;
> numpy.test()"
>
> same result as above.
>
> So, what's the proper way to run the tests suite at build time?
>
> Thanks in advance,
> --
> Sandro Tosi (aka morph, morpheus, matrixhasu)
> My website: http://matrixhasu.altervista.org/
> Me at Debian: http://wiki.debian.org/SandroTosi
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list