17
17
from pylint .testutils import TestReporter as Reporter
18
18
19
19
20
- class TempdirGuard :
21
- """ creates and deletes a tmp-dir compatible with python2 and 3 """
22
-
23
- def __init__ (self , prefix ):
24
- self .path = tempfile .mkdtemp (prefix = prefix + "_" )
25
-
26
- def __enter__ (self ):
27
- return self
28
-
29
- def __exit__ (self , x_type , x_value , x_traceback ):
30
- shutil .rmtree (self .path ) # always clean up on exit
31
-
32
-
33
20
def _get_py_files (scanpath ):
34
21
assert os .path .exists (scanpath ), "Dir not found %s" % scanpath
35
22
@@ -53,21 +40,22 @@ def _get_py_files(scanpath):
53
40
@pytest .mark .parametrize (
54
41
"name,git_repo" , [("numpy" , "https://github.com/numpy/numpy.git" )]
55
42
)
56
- def test_run (name , git_repo ):
43
+ def test_run (tmp_path , name , git_repo ):
57
44
""" Runs pylint against external sources """
58
- with TempdirGuard ( prefix = name ) as checkoutdir :
59
- os . system (
60
- "git clone --depth=1 {git_repo} {checkoutdir}" . format (
61
- git_repo = git_repo , checkoutdir = checkoutdir . path
62
- )
45
+ checkoutdir = tmp_path / name
46
+ checkoutdir . mkdir ()
47
+ os . system (
48
+ "git clone --depth=1 { git_repo} { checkoutdir}" . format (
49
+ git_repo = git_repo , checkoutdir = str ( checkoutdir )
63
50
)
64
- filepaths = _get_py_files (scanpath = checkoutdir .path )
65
- print ("Have %d files" % len (filepaths ))
51
+ )
52
+ filepaths = _get_py_files (scanpath = str (checkoutdir ))
53
+ print ("Have %d files" % len (filepaths ))
66
54
67
- runner = Run (filepaths , reporter = Reporter (), do_exit = False )
55
+ runner = Run (filepaths , reporter = Reporter (), do_exit = False )
68
56
69
- print (
70
- "Had %d files with %d messages"
71
- % (len (filepaths ), len (runner .linter .reporter .messages ))
72
- )
73
- pprint .pprint (runner .linter .reporter .messages )
57
+ print (
58
+ "Had %d files with %d messages"
59
+ % (len (filepaths ), len (runner .linter .reporter .messages ))
60
+ )
61
+ pprint .pprint (runner .linter .reporter .messages )
0 commit comments