Skip to content

Commit

Permalink
TST: Move tests/scripts to scripts/tests (#22531)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung authored Sep 1, 2018
1 parent 77e53b8 commit 550a5ca
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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/

Expand Down
2 changes: 2 additions & 0 deletions ci/script_single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions scripts/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def pytest_addoption(parser):
parser.addoption("--strict-data-files", action="store_true",
help="Unused. For compat with setup.cfg.")
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -44,7 +46,7 @@ def sample(self):
float
Random number generated.
"""
return random.random() # noqa: F821
return random.random()

def random_letters(self):
"""
Expand All @@ -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):
Expand All @@ -78,7 +79,7 @@ def sample_values(self):
Random number generated.
"""
while True:
yield random.random() # noqa: F821
yield random.random()

def head(self):
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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", [
Expand Down

0 comments on commit 550a5ca

Please sign in to comment.