diff options
author | Seth Troisi <sethtroisi@google.com> | 2020-01-08 23:49:17 -0800 |
---|---|---|
committer | Seth Troisi <sethtroisi@google.com> | 2020-01-15 13:19:56 -0800 |
commit | 1427484e9015e73b7017ee9336ce914a6f15187b (patch) | |
tree | 2db89078addee6a01697ab8bd4160c25d59fffc4 /numpy/tests | |
parent | b6bc0941d4f07310456079ab2497c3d1bde4a5e7 (diff) | |
download | numpy-1427484e9015e73b7017ee9336ce914a6f15187b.tar.gz |
MAINT: Remove sys.version checks in tests
Diffstat (limited to 'numpy/tests')
-rw-r--r-- | numpy/tests/test_public_api.py | 3 | ||||
-rw-r--r-- | numpy/tests/test_reloading.py | 5 | ||||
-rw-r--r-- | numpy/tests/test_warnings.py | 111 |
3 files changed, 56 insertions, 63 deletions
diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index 48dd42a9f..b4aa7ec3d 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -28,9 +28,6 @@ def check_dir(module, module_name=None): return results -@pytest.mark.skipif( - sys.version_info[0] < 3, - reason="NumPy exposes slightly different functions on Python 2") def test_numpy_namespace(): # None of these objects are publicly documented to be part of the main # NumPy namespace (some are useful though, others need to be cleaned up) diff --git a/numpy/tests/test_reloading.py b/numpy/tests/test_reloading.py index 2b5a324ba..a6d2e62a9 100644 --- a/numpy/tests/test_reloading.py +++ b/numpy/tests/test_reloading.py @@ -3,10 +3,7 @@ import sys from numpy.testing import assert_raises, assert_, assert_equal from numpy.compat import pickle -if sys.version_info[:2] >= (3, 4): - from importlib import reload -else: - from imp import reload +from importlib import reload def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. diff --git a/numpy/tests/test_warnings.py b/numpy/tests/test_warnings.py index 48896f4b7..ff75681dc 100644 --- a/numpy/tests/test_warnings.py +++ b/numpy/tests/test_warnings.py @@ -5,72 +5,71 @@ all of these occurrences but should catch almost all. import sys import pytest -if sys.version_info >= (3, 4): - from pathlib import Path - import ast - import tokenize - import numpy +from pathlib import Path +import ast +import tokenize +import numpy - class ParseCall(ast.NodeVisitor): - def __init__(self): - self.ls = [] +class ParseCall(ast.NodeVisitor): + def __init__(self): + self.ls = [] - def visit_Attribute(self, node): - ast.NodeVisitor.generic_visit(self, node) - self.ls.append(node.attr) + def visit_Attribute(self, node): + ast.NodeVisitor.generic_visit(self, node) + self.ls.append(node.attr) - def visit_Name(self, node): - self.ls.append(node.id) + def visit_Name(self, node): + self.ls.append(node.id) - class FindFuncs(ast.NodeVisitor): - def __init__(self, filename): - super().__init__() - self.__filename = filename +class FindFuncs(ast.NodeVisitor): + def __init__(self, filename): + super().__init__() + self.__filename = filename - def visit_Call(self, node): - p = ParseCall() - p.visit(node.func) - ast.NodeVisitor.generic_visit(self, node) + def visit_Call(self, node): + p = ParseCall() + p.visit(node.func) + ast.NodeVisitor.generic_visit(self, node) - if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings': - if node.args[0].s == "ignore": - raise AssertionError( - "ignore filter should not be used; found in " - "{} on line {}".format(self.__filename, node.lineno)) + if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings': + if node.args[0].s == "ignore": + raise AssertionError( + "ignore filter should not be used; found in " + "{} on line {}".format(self.__filename, node.lineno)) - if p.ls[-1] == 'warn' and ( - len(p.ls) == 1 or p.ls[-2] == 'warnings'): + if p.ls[-1] == 'warn' and ( + len(p.ls) == 1 or p.ls[-2] == 'warnings'): - if "testing/tests/test_warnings.py" == self.__filename: - # This file - return + if "testing/tests/test_warnings.py" == self.__filename: + # This file + return - # See if stacklevel exists: - if len(node.args) == 3: - return - args = {kw.arg for kw in node.keywords} - if "stacklevel" in args: - return - raise AssertionError( - "warnings should have an appropriate stacklevel; found in " - "{} on line {}".format(self.__filename, node.lineno)) + # See if stacklevel exists: + if len(node.args) == 3: + return + args = {kw.arg for kw in node.keywords} + if "stacklevel" in args: + return + raise AssertionError( + "warnings should have an appropriate stacklevel; found in " + "{} on line {}".format(self.__filename, node.lineno)) - @pytest.mark.slow - def test_warning_calls(): - # combined "ignore" and stacklevel error - base = Path(numpy.__file__).parent +@pytest.mark.slow +def test_warning_calls(): + # combined "ignore" and stacklevel error + base = Path(numpy.__file__).parent - for path in base.rglob("*.py"): - if base / "testing" in path.parents: - continue - if path == base / "__init__.py": - continue - if path == base / "random" / "__init__.py": - continue - # use tokenize to auto-detect encoding on systems where no - # default encoding is defined (e.g. LANG='C') - with tokenize.open(str(path)) as file: - tree = ast.parse(file.read()) - FindFuncs(path).visit(tree) + for path in base.rglob("*.py"): + if base / "testing" in path.parents: + continue + if path == base / "__init__.py": + continue + if path == base / "random" / "__init__.py": + continue + # use tokenize to auto-detect encoding on systems where no + # default encoding is defined (e.g. LANG='C') + with tokenize.open(str(path)) as file: + tree = ast.parse(file.read()) + FindFuncs(path).visit(tree) |