1
- import os
2
- import sys
3
-
4
- import numpy as np
5
1
import 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
6
8
7
9
8
10
class GoodDocStrings (object ):
@@ -44,7 +46,7 @@ def sample(self):
44
46
float
45
47
Random number generated.
46
48
"""
47
- return random .random () # noqa: F821
49
+ return random .random ()
48
50
49
51
def random_letters (self ):
50
52
"""
@@ -60,9 +62,9 @@ def random_letters(self):
60
62
letters : str
61
63
String of random letters.
62
64
"""
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 ))
66
68
return length , letters
67
69
68
70
def sample_values (self ):
@@ -78,7 +80,7 @@ def sample_values(self):
78
80
Random number generated.
79
81
"""
80
82
while True :
81
- yield random .random () # noqa: F821
83
+ yield random .random ()
82
84
83
85
def head (self ):
84
86
"""
@@ -491,44 +493,6 @@ def no_punctuation(self):
491
493
492
494
class TestValidator (object ):
493
495
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
-
532
496
def _import_path (self , klass = None , func = None ):
533
497
"""
534
498
Build the required import path for tests in this module.
@@ -545,27 +509,29 @@ def _import_path(self, klass=None, func=None):
545
509
str
546
510
Import path of specified object in this module
547
511
"""
548
- base_path = 'pandas.tests.scripts.test_validate_docstrings'
512
+ base_path = "scripts.tests.test_validate_docstrings"
513
+
549
514
if klass :
550
- base_path = '.' .join ([base_path , klass ])
515
+ base_path = "." .join ([base_path , klass ])
516
+
551
517
if func :
552
- base_path = '.' .join ([base_path , func ])
518
+ base_path = "." .join ([base_path , func ])
553
519
554
520
return base_path
555
521
556
522
def test_good_class (self ):
557
- assert validate_one (self ._import_path ( # noqa: F821
523
+ assert validate_one (self ._import_path (
558
524
klass = 'GoodDocStrings' )) == 0
559
525
560
526
@pytest .mark .parametrize ("func" , [
561
527
'plot' , 'sample' , 'random_letters' , 'sample_values' , 'head' , 'head1' ,
562
528
'contains' , 'mode' ])
563
529
def test_good_functions (self , func ):
564
- assert validate_one (self ._import_path ( # noqa: F821
530
+ assert validate_one (self ._import_path (
565
531
klass = 'GoodDocStrings' , func = func )) == 0
566
532
567
533
def test_bad_class (self ):
568
- assert validate_one (self ._import_path ( # noqa: F821
534
+ assert validate_one (self ._import_path (
569
535
klass = 'BadGenericDocStrings' )) > 0
570
536
571
537
@pytest .mark .parametrize ("func" , [
0 commit comments