diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-03-27 21:49:08 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-03-28 08:43:26 -0600 |
commit | d4b88c1dbd6898fb6fcebc97f36b421999340f71 (patch) | |
tree | 61cc0282cf2509afe364c91e97b59dfb2ebcafd3 /numpy/testing | |
parent | 40742184df68fc01f3392c9865f35d5402e74b01 (diff) | |
download | numpy-d4b88c1dbd6898fb6fcebc97f36b421999340f71.tar.gz |
2to3: Use absolute imports.
The new import `absolute_import` is added the `from __future__ import`
statement and The 2to3 `import` fixer is run to make the imports
compatible. There are several things that need to be dealt with to make
this work.
1) Files meant to be run as scripts run in a different environment than
files imported as part of a package, and so changes to those files need
to be skipped. The affected script files are:
* all setup.py files
* numpy/core/code_generators/generate_umath.py
* numpy/core/code_generators/generate_numpy_api.py
* numpy/core/code_generators/generate_ufunc_api.py
2) Some imported modules are not available as they are created during
the build process and consequently 2to3 is unable to handle them
correctly. Files that import those modules need a bit of extra work.
The affected files are:
* core/__init__.py,
* core/numeric.py,
* core/_internal.py,
* core/arrayprint.py,
* core/fromnumeric.py,
* numpy/__init__.py,
* lib/npyio.py,
* lib/function_base.py,
* fft/fftpack.py,
* random/__init__.py
Closes #3172
Diffstat (limited to 'numpy/testing')
-rw-r--r-- | numpy/testing/__init__.py | 12 | ||||
-rw-r--r-- | numpy/testing/decorators.py | 6 | ||||
-rw-r--r-- | numpy/testing/noseclasses.py | 4 | ||||
-rw-r--r-- | numpy/testing/nosetester.py | 12 | ||||
-rw-r--r-- | numpy/testing/nulltester.py | 2 | ||||
-rw-r--r-- | numpy/testing/numpytest.py | 2 | ||||
-rwxr-xr-x | numpy/testing/print_coercion_tables.py | 2 | ||||
-rw-r--r-- | numpy/testing/tests/test_decorators.py | 2 | ||||
-rw-r--r-- | numpy/testing/tests/test_doctesting.py | 2 | ||||
-rw-r--r-- | numpy/testing/tests/test_utils.py | 2 | ||||
-rw-r--r-- | numpy/testing/utils.py | 4 |
11 files changed, 25 insertions, 25 deletions
diff --git a/numpy/testing/__init__.py b/numpy/testing/__init__.py index 19b0d2052..cee2d6944 100644 --- a/numpy/testing/__init__.py +++ b/numpy/testing/__init__.py @@ -5,13 +5,13 @@ in a single location, so that test scripts can just import it and work right away. """ -from __future__ import division +from __future__ import division, absolute_import from unittest import TestCase -import decorators as dec -from utils import * -from numpytest import * -from nosetester import NoseTester as Tester -from nosetester import run_module_suite +from . import decorators as dec +from .utils import * +from .numpytest import * +from .nosetester import NoseTester as Tester +from .nosetester import run_module_suite test = Tester().test diff --git a/numpy/testing/decorators.py b/numpy/testing/decorators.py index eae9d93b0..6d3da95ed 100644 --- a/numpy/testing/decorators.py +++ b/numpy/testing/decorators.py @@ -13,7 +13,7 @@ function name, setup and teardown functions and so on - see ``nose.tools`` for more information. """ -from __future__ import division +from __future__ import division, absolute_import import warnings import sys @@ -210,7 +210,7 @@ def knownfailureif(fail_condition, msg=None): # Local import to avoid a hard nose dependency and only incur the # import time overhead at actual test-time. import nose - from noseclasses import KnownFailureTest + from .noseclasses import KnownFailureTest def knownfailer(*args, **kwargs): if fail_val(): raise KnownFailureTest(msg) @@ -249,7 +249,7 @@ def deprecated(conditional=True): # Local import to avoid a hard nose dependency and only incur the # import time overhead at actual test-time. import nose - from noseclasses import KnownFailureTest + from .noseclasses import KnownFailureTest def _deprecated_imp(*args, **kwargs): # Poor man's replacement for the with statement diff --git a/numpy/testing/noseclasses.py b/numpy/testing/noseclasses.py index 96c779c2e..f3c15b39d 100644 --- a/numpy/testing/noseclasses.py +++ b/numpy/testing/noseclasses.py @@ -4,7 +4,7 @@ # Because this module imports nose directly, it should not # be used except by nosetester.py to avoid a general NumPy # dependency on nose. -from __future__ import division +from __future__ import division, absolute_import import os import doctest @@ -15,7 +15,7 @@ from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin from nose.plugins.base import Plugin from nose.util import src import numpy -from nosetester import get_package_name +from .nosetester import get_package_name import inspect # Some of the classes in this module begin with 'Numpy' to clearly distinguish diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py index 7f1292cd8..326c36cac 100644 --- a/numpy/testing/nosetester.py +++ b/numpy/testing/nosetester.py @@ -4,7 +4,7 @@ Nose test running. This module implements ``test()`` and ``bench()`` functions for NumPy modules. """ -from __future__ import division +from __future__ import division, absolute_import import os import sys @@ -216,7 +216,7 @@ class NoseTester(object): A return value of None means use the nose builtin doctest plugin """ - from noseclasses import NumpyDoctest + from .noseclasses import NumpyDoctest return NumpyDoctest() def prepare_test_args(self, label='fast', verbose=1, extra_argv=None, @@ -245,7 +245,7 @@ class NoseTester(object): '--cover-tests', '--cover-erase'] # construct list of plugins import nose.plugins.builtin - from noseclasses import KnownFailure, Unplugger + from .noseclasses import KnownFailure, Unplugger plugins = [KnownFailure()] plugins += [p() for p in nose.plugins.builtin.plugins] # add doctesting if required @@ -331,7 +331,7 @@ class NoseTester(object): # cap verbosity at 3 because nose becomes *very* verbose beyond that verbose = min(verbose, 3) - import utils + from . import utils utils.verbose = verbose if doctests: @@ -371,7 +371,7 @@ class NoseTester(object): warnings.filterwarnings("ignore", message="numpy.ufunc size changed") try: - from noseclasses import NumpyTestProgram + from .noseclasses import NumpyTestProgram argv, plugins = self.prepare_test_args(label, verbose, extra_argv, doctests, coverage) @@ -447,7 +447,7 @@ class NoseTester(object): nose = import_nose() # get plugin to disable doctests - from noseclasses import Unplugger + from .noseclasses import Unplugger add_plugins = [Unplugger('doctest')] return nose.run(argv=argv, addplugins=add_plugins) diff --git a/numpy/testing/nulltester.py b/numpy/testing/nulltester.py index e0c7531b3..0419f9436 100644 --- a/numpy/testing/nulltester.py +++ b/numpy/testing/nulltester.py @@ -6,7 +6,7 @@ below requirements. See pkgtester, nosetester modules """ -from __future__ import division +from __future__ import division, absolute_import class NullTester(object): diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py index 5259ba773..4e2409e8d 100644 --- a/numpy/testing/numpytest.py +++ b/numpy/testing/numpytest.py @@ -1,4 +1,4 @@ -from __future__ import division +from __future__ import division, absolute_import import os import sys diff --git a/numpy/testing/print_coercion_tables.py b/numpy/testing/print_coercion_tables.py index 4982f5602..829ba0a16 100755 --- a/numpy/testing/print_coercion_tables.py +++ b/numpy/testing/print_coercion_tables.py @@ -2,7 +2,7 @@ """Prints type-coercion tables for the built-in NumPy types """ -from __future__ import division +from __future__ import division, absolute_import import numpy as np diff --git a/numpy/testing/tests/test_decorators.py b/numpy/testing/tests/test_decorators.py index 22d39e9a6..0acf5a11a 100644 --- a/numpy/testing/tests/test_decorators.py +++ b/numpy/testing/tests/test_decorators.py @@ -1,4 +1,4 @@ -from __future__ import division +from __future__ import division, absolute_import import numpy as np from numpy.testing import * diff --git a/numpy/testing/tests/test_doctesting.py b/numpy/testing/tests/test_doctesting.py index 58f65aa45..798c0e7e7 100644 --- a/numpy/testing/tests/test_doctesting.py +++ b/numpy/testing/tests/test_doctesting.py @@ -1,7 +1,7 @@ """ Doctests for NumPy-specific nose/doctest modifications """ -from __future__ import division +from __future__ import division, absolute_import # try the #random directive on the output line def check_random_directive(): diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 4dd5a8121..f08ca2b12 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1,4 +1,4 @@ -from __future__ import division +from __future__ import division, absolute_import import warnings import sys diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 019adeb27..c08dd0c33 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -2,7 +2,7 @@ Utility function to facilitate testing. """ -from __future__ import division +from __future__ import division, absolute_import import os import sys @@ -10,7 +10,7 @@ import re import operator import types import warnings -from nosetester import import_nose +from .nosetester import import_nose __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', |