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