diff --git a/Makefile b/Makefile index 4a82566cf726e..4a4aca21e1b78 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ build: clean_pyc python setup.py build_ext --inplace lint-diff: - git diff master --name-only -- "*.py" | grep "pandas" | xargs flake8 + git diff master --name-only -- "*.py" | grep -E "pandas|scripts" | xargs flake8 develop: build -python setup.py develop diff --git a/ci/lint.sh b/ci/lint.sh index c7ea92e6a67e6..533e1d18d8e0e 100755 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -24,6 +24,11 @@ if [ "$LINT" ]; then if [ $? -ne "0" ]; then RET=1 fi + + flake8 scripts/tests --filename=*.py + if [ $? -ne "0" ]; then + RET=1 + fi echo "Linting *.py DONE" echo "Linting setup.py" @@ -175,7 +180,7 @@ if [ "$LINT" ]; then RET=1 fi echo "Check for old-style classes DONE" - + echo "Check for backticks incorrectly rendering because of missing spaces" grep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/ diff --git a/ci/script_single.sh b/ci/script_single.sh index 60e2fbb33ee5d..ed12ee35b9151 100755 --- a/ci/script_single.sh +++ b/ci/script_single.sh @@ -28,6 +28,8 @@ elif [ "$COVERAGE" ]; then echo pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas + echo pytest -s -r xXs --strict scripts + pytest -s -r xXs --strict scripts else echo pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas # TODO: doctest diff --git a/pandas/tests/scripts/__init__.py b/scripts/tests/__init__.py similarity index 100% rename from pandas/tests/scripts/__init__.py rename to scripts/tests/__init__.py diff --git a/scripts/tests/conftest.py b/scripts/tests/conftest.py new file mode 100644 index 0000000000000..f8318b8d402af --- /dev/null +++ b/scripts/tests/conftest.py @@ -0,0 +1,3 @@ +def pytest_addoption(parser): + parser.addoption("--strict-data-files", action="store_true", + help="Unused. For compat with setup.cfg.") diff --git a/pandas/tests/scripts/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py similarity index 88% rename from pandas/tests/scripts/test_validate_docstrings.py rename to scripts/tests/test_validate_docstrings.py index 25cb1d7aff649..933d02cc8c627 100644 --- a/pandas/tests/scripts/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1,8 +1,10 @@ -import os -import sys - -import numpy as np +import string +import random import pytest +import numpy as np + +import validate_docstrings +validate_one = validate_docstrings.validate_one class GoodDocStrings(object): @@ -44,7 +46,7 @@ def sample(self): float Random number generated. """ - return random.random() # noqa: F821 + return random.random() def random_letters(self): """ @@ -60,9 +62,8 @@ def random_letters(self): letters : str String of random letters. """ - length = random.randint(1, 10) # noqa: F821 - letters = ''.join(random.choice(string.ascii_lowercase) # noqa: F821 - for i in range(length)) + length = random.randint(1, 10) + letters = "".join(random.sample(string.ascii_lowercase, length)) return length, letters def sample_values(self): @@ -78,7 +79,7 @@ def sample_values(self): Random number generated. """ while True: - yield random.random() # noqa: F821 + yield random.random() def head(self): """ @@ -491,44 +492,6 @@ def no_punctuation(self): class TestValidator(object): - @pytest.fixture(autouse=True, scope="class") - def import_scripts(self): - """ - Import the validation scripts from the scripts directory. - - Because the scripts directory is above the top level pandas package, - we need to modify `sys.path` so that Python knows where to find it. - - The code below traverses up the file system to find the scripts - directory, adds the location to `sys.path`, and imports the required - module into the global namespace before as part of class setup. - - During teardown, those changes are reverted. - """ - - up = os.path.dirname - global_validate_one = "validate_one" - file_dir = up(os.path.abspath(__file__)) - - script_dir = os.path.join(up(up(up(file_dir))), "scripts") - sys.path.append(script_dir) - - try: - from validate_docstrings import validate_one - globals()[global_validate_one] = validate_one - except ImportError: - # Remove addition to `sys.path` - sys.path.pop() - - # Import will fail if the pandas installation is not inplace. - raise pytest.skip("pandas/scripts directory does not exist") - - yield - - # Teardown. - sys.path.pop() - del globals()[global_validate_one] - def _import_path(self, klass=None, func=None): """ Build the required import path for tests in this module. @@ -545,27 +508,29 @@ def _import_path(self, klass=None, func=None): str Import path of specified object in this module """ - base_path = 'pandas.tests.scripts.test_validate_docstrings' + base_path = "scripts.tests.test_validate_docstrings" + if klass: - base_path = '.'.join([base_path, klass]) + base_path = ".".join([base_path, klass]) + if func: - base_path = '.'.join([base_path, func]) + base_path = ".".join([base_path, func]) return base_path def test_good_class(self): - assert validate_one(self._import_path( # noqa: F821 + assert validate_one(self._import_path( klass='GoodDocStrings')) == 0 @pytest.mark.parametrize("func", [ 'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1', 'contains', 'mode']) def test_good_functions(self, func): - assert validate_one(self._import_path( # noqa: F821 + assert validate_one(self._import_path( klass='GoodDocStrings', func=func)) == 0 def test_bad_class(self): - assert validate_one(self._import_path( # noqa: F821 + assert validate_one(self._import_path( klass='BadGenericDocStrings')) > 0 @pytest.mark.parametrize("func", [