|
| 1 | +""" Profiles basic -jX functionality """ |
| 2 | +# Copyright (c) 2020 Frank Harrison <[email protected]> |
| 3 | + |
| 4 | +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 5 | +# For details: https://github.com/PyCQA/pylint/blob/master/COPYING |
| 6 | + |
| 7 | +# pylint: disable=protected-access,missing-function-docstring,no-self-use |
| 8 | + |
| 9 | +import os |
| 10 | +import pprint |
| 11 | +import shutil |
| 12 | +import tempfile |
| 13 | + |
| 14 | +import pytest |
| 15 | + |
| 16 | +from pylint.lint import Run |
| 17 | +from pylint.testutils import TestReporter as Reporter |
| 18 | + |
| 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 | +def _get_py_files(scanpath): |
| 34 | + assert os.path.exists(scanpath), "Dir not found %s" % scanpath |
| 35 | + |
| 36 | + filepaths = [] |
| 37 | + for dirpath, dirnames, filenames in os.walk(scanpath): |
| 38 | + dirnames[:] = [dirname for dirname in dirnames if dirname != "__pycache__"] |
| 39 | + filepaths.extend( |
| 40 | + [ |
| 41 | + os.path.join(dirpath, filename) |
| 42 | + for filename in filenames |
| 43 | + if filename.endswith(".py") |
| 44 | + ] |
| 45 | + ) |
| 46 | + return filepaths |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.skipif( |
| 50 | + not os.environ.get("PYTEST_PROFILE_EXTERNAL", False), |
| 51 | + reason="PYTEST_PROFILE_EXTERNAL, not set, assuming not a profile run", |
| 52 | +) |
| 53 | +@pytest.mark.parametrize( |
| 54 | + "name,git_repo", [("numpy", "https://github.com/numpy/numpy.git")] |
| 55 | +) |
| 56 | +def test_run(name, git_repo): |
| 57 | + """ 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 | + ) |
| 63 | + ) |
| 64 | + filepaths = _get_py_files(scanpath=checkoutdir.path) |
| 65 | + print("Have %d files" % len(filepaths)) |
| 66 | + |
| 67 | + runner = Run(filepaths, reporter=Reporter(), do_exit=False) |
| 68 | + |
| 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) |
| 74 | + |
| 75 | + # one day: assert runner.linter.msg_status == 0, ( |
| 76 | + # one day: "Expected no errors to be thrown: %s" |
| 77 | + # one day: % pprint.pformat(runner.linter.reporter.messages) |
| 78 | + # one day: ) |
0 commit comments