Skip to content

Commit 550a5ca

Browse files
authored
TST: Move tests/scripts to scripts/tests (#22531)
1 parent 77e53b8 commit 550a5ca

File tree

6 files changed

+30
-55
lines changed

6 files changed

+30
-55
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build: clean_pyc
1313
python setup.py build_ext --inplace
1414

1515
lint-diff:
16-
git diff master --name-only -- "*.py" | grep "pandas" | xargs flake8
16+
git diff master --name-only -- "*.py" | grep -E "pandas|scripts" | xargs flake8
1717

1818
develop: build
1919
-python setup.py develop

ci/lint.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ if [ "$LINT" ]; then
2424
if [ $? -ne "0" ]; then
2525
RET=1
2626
fi
27+
28+
flake8 scripts/tests --filename=*.py
29+
if [ $? -ne "0" ]; then
30+
RET=1
31+
fi
2732
echo "Linting *.py DONE"
2833

2934
echo "Linting setup.py"
@@ -175,7 +180,7 @@ if [ "$LINT" ]; then
175180
RET=1
176181
fi
177182
echo "Check for old-style classes DONE"
178-
183+
179184
echo "Check for backticks incorrectly rendering because of missing spaces"
180185
grep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
181186

ci/script_single.sh

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ elif [ "$COVERAGE" ]; then
2828
echo pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas
2929
pytest -s -m "single" -r xXs --strict --cov=pandas --cov-report xml:/tmp/cov-single.xml --junitxml=/tmp/single.xml $TEST_ARGS pandas
3030

31+
echo pytest -s -r xXs --strict scripts
32+
pytest -s -r xXs --strict scripts
3133
else
3234
echo pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas
3335
pytest -m "single" -r xXs --junitxml=/tmp/single.xml --strict $TEST_ARGS pandas # TODO: doctest
File renamed without changes.

scripts/tests/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def pytest_addoption(parser):
2+
parser.addoption("--strict-data-files", action="store_true",
3+
help="Unused. For compat with setup.cfg.")

pandas/tests/scripts/test_validate_docstrings.py renamed to scripts/tests/test_validate_docstrings.py

+18-53
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import os
2-
import sys
3-
4-
import numpy as np
1+
import string
2+
import random
53
import pytest
4+
import numpy as np
5+
6+
import validate_docstrings
7+
validate_one = validate_docstrings.validate_one
68

79

810
class GoodDocStrings(object):
@@ -44,7 +46,7 @@ def sample(self):
4446
float
4547
Random number generated.
4648
"""
47-
return random.random() # noqa: F821
49+
return random.random()
4850

4951
def random_letters(self):
5052
"""
@@ -60,9 +62,8 @@ def random_letters(self):
6062
letters : str
6163
String of random letters.
6264
"""
63-
length = random.randint(1, 10) # noqa: F821
64-
letters = ''.join(random.choice(string.ascii_lowercase) # noqa: F821
65-
for i in range(length))
65+
length = random.randint(1, 10)
66+
letters = "".join(random.sample(string.ascii_lowercase, length))
6667
return length, letters
6768

6869
def sample_values(self):
@@ -78,7 +79,7 @@ def sample_values(self):
7879
Random number generated.
7980
"""
8081
while True:
81-
yield random.random() # noqa: F821
82+
yield random.random()
8283

8384
def head(self):
8485
"""
@@ -491,44 +492,6 @@ def no_punctuation(self):
491492

492493
class TestValidator(object):
493494

494-
@pytest.fixture(autouse=True, scope="class")
495-
def import_scripts(self):
496-
"""
497-
Import the validation scripts from the scripts directory.
498-
499-
Because the scripts directory is above the top level pandas package,
500-
we need to modify `sys.path` so that Python knows where to find it.
501-
502-
The code below traverses up the file system to find the scripts
503-
directory, adds the location to `sys.path`, and imports the required
504-
module into the global namespace before as part of class setup.
505-
506-
During teardown, those changes are reverted.
507-
"""
508-
509-
up = os.path.dirname
510-
global_validate_one = "validate_one"
511-
file_dir = up(os.path.abspath(__file__))
512-
513-
script_dir = os.path.join(up(up(up(file_dir))), "scripts")
514-
sys.path.append(script_dir)
515-
516-
try:
517-
from validate_docstrings import validate_one
518-
globals()[global_validate_one] = validate_one
519-
except ImportError:
520-
# Remove addition to `sys.path`
521-
sys.path.pop()
522-
523-
# Import will fail if the pandas installation is not inplace.
524-
raise pytest.skip("pandas/scripts directory does not exist")
525-
526-
yield
527-
528-
# Teardown.
529-
sys.path.pop()
530-
del globals()[global_validate_one]
531-
532495
def _import_path(self, klass=None, func=None):
533496
"""
534497
Build the required import path for tests in this module.
@@ -545,27 +508,29 @@ def _import_path(self, klass=None, func=None):
545508
str
546509
Import path of specified object in this module
547510
"""
548-
base_path = 'pandas.tests.scripts.test_validate_docstrings'
511+
base_path = "scripts.tests.test_validate_docstrings"
512+
549513
if klass:
550-
base_path = '.'.join([base_path, klass])
514+
base_path = ".".join([base_path, klass])
515+
551516
if func:
552-
base_path = '.'.join([base_path, func])
517+
base_path = ".".join([base_path, func])
553518

554519
return base_path
555520

556521
def test_good_class(self):
557-
assert validate_one(self._import_path( # noqa: F821
522+
assert validate_one(self._import_path(
558523
klass='GoodDocStrings')) == 0
559524

560525
@pytest.mark.parametrize("func", [
561526
'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1',
562527
'contains', 'mode'])
563528
def test_good_functions(self, func):
564-
assert validate_one(self._import_path( # noqa: F821
529+
assert validate_one(self._import_path(
565530
klass='GoodDocStrings', func=func)) == 0
566531

567532
def test_bad_class(self):
568-
assert validate_one(self._import_path( # noqa: F821
533+
assert validate_one(self._import_path(
569534
klass='BadGenericDocStrings')) > 0
570535

571536
@pytest.mark.parametrize("func", [

0 commit comments

Comments
 (0)