1- import os
2- import sys
3-
4- import numpy as np
51import pytest
2+ import string
3+ import random
4+ import numpy as np
5+
6+ validate_docstrings = pytest .importorskip ("validate_docstrings" )
7+ validate_one = validate_docstrings .validate_one
68
79
810class 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,9 @@ 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 .choice (string .ascii_lowercase )
67+ for _ in range (length ))
6668 return length , letters
6769
6870 def sample_values (self ):
@@ -78,7 +80,7 @@ def sample_values(self):
7880 Random number generated.
7981 """
8082 while True :
81- yield random .random () # noqa: F821
83+ yield random .random ()
8284
8385 def head (self ):
8486 """
@@ -491,44 +493,6 @@ def no_punctuation(self):
491493
492494class TestValidator (object ):
493495
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-
532496 def _import_path (self , klass = None , func = None ):
533497 """
534498 Build the required import path for tests in this module.
@@ -545,27 +509,29 @@ def _import_path(self, klass=None, func=None):
545509 str
546510 Import path of specified object in this module
547511 """
548- base_path = 'pandas.tests.scripts.test_validate_docstrings'
512+ base_path = "scripts.tests.test_validate_docstrings"
513+
549514 if klass :
550- base_path = '.' .join ([base_path , klass ])
515+ base_path = "." .join ([base_path , klass ])
516+
551517 if func :
552- base_path = '.' .join ([base_path , func ])
518+ base_path = "." .join ([base_path , func ])
553519
554520 return base_path
555521
556522 def test_good_class (self ):
557- assert validate_one (self ._import_path ( # noqa: F821
523+ assert validate_one (self ._import_path (
558524 klass = 'GoodDocStrings' )) == 0
559525
560526 @pytest .mark .parametrize ("func" , [
561527 'plot' , 'sample' , 'random_letters' , 'sample_values' , 'head' , 'head1' ,
562528 'contains' , 'mode' ])
563529 def test_good_functions (self , func ):
564- assert validate_one (self ._import_path ( # noqa: F821
530+ assert validate_one (self ._import_path (
565531 klass = 'GoodDocStrings' , func = func )) == 0
566532
567533 def test_bad_class (self ):
568- assert validate_one (self ._import_path ( # noqa: F821
534+ assert validate_one (self ._import_path (
569535 klass = 'BadGenericDocStrings' )) > 0
570536
571537 @pytest .mark .parametrize ("func" , [
0 commit comments