Skip to content

Commit

Permalink
review fixes| Uses pytest's tmp_path fixture instead of custom contex…
Browse files Browse the repository at this point in the history
…t man
  • Loading branch information
doublethefish committed Oct 21, 2020
1 parent 187f133 commit 899156a
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions tests/profile/test_profile_against_externals.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@
from pylint.testutils import TestReporter as Reporter


class TempdirGuard:
""" creates and deletes a tmp-dir compatible with python2 and 3 """

def __init__(self, prefix):
self.path = tempfile.mkdtemp(prefix=prefix + "_")

def __enter__(self):
return self

def __exit__(self, x_type, x_value, x_traceback):
shutil.rmtree(self.path) # always clean up on exit


def _get_py_files(scanpath):
assert os.path.exists(scanpath), "Dir not found %s" % scanpath

Expand All @@ -53,21 +40,22 @@ def _get_py_files(scanpath):
@pytest.mark.parametrize(
"name,git_repo", [("numpy", "https://github.com/numpy/numpy.git")]
)
def test_run(name, git_repo):
def test_run(tmp_path, name, git_repo):
""" Runs pylint against external sources """
with TempdirGuard(prefix=name) as checkoutdir:
os.system(
"git clone --depth=1 {git_repo} {checkoutdir}".format(
git_repo=git_repo, checkoutdir=checkoutdir.path
)
checkoutdir = tmp_path / name
checkoutdir.mkdir()
os.system(
"git clone --depth=1 {git_repo} {checkoutdir}".format(
git_repo=git_repo, checkoutdir=str(checkoutdir)
)
filepaths = _get_py_files(scanpath=checkoutdir.path)
print("Have %d files" % len(filepaths))
)
filepaths = _get_py_files(scanpath=str(checkoutdir))
print("Have %d files" % len(filepaths))

runner = Run(filepaths, reporter=Reporter(), do_exit=False)
runner = Run(filepaths, reporter=Reporter(), do_exit=False)

print(
"Had %d files with %d messages"
% (len(filepaths), len(runner.linter.reporter.messages))
)
pprint.pprint(runner.linter.reporter.messages)
print(
"Had %d files with %d messages"
% (len(filepaths), len(runner.linter.reporter.messages))
)
pprint.pprint(runner.linter.reporter.messages)

0 comments on commit 899156a

Please sign in to comment.