Skip to content

TST: Move tests/scripts to scripts/tests #22531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

Copy link
Member Author

@gfyoung gfyoung Aug 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it says in the code: it's needed to placate setup.cfg.

--strict-data-files is enabled across the board for all tests, so we need to "accommodate" that option here.

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