# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os import platform import signal import subprocess import sys import time from itertools import chain
import mozunit import pytest
from mozlint.errors import LintersNotConfigured, NoValidLinter from mozlint.result import Issue, ResultSummary from mozlint.roller import LintRoller
here = os.path.abspath(os.path.dirname(__file__))
def test_roll_no_linters_configured(lint, files): with pytest.raises(LintersNotConfigured):
lint.roll(files)
# Path relative to cwd works
result = lint.roll("foobar.js") assert len(result.issues) == 1 assert len(result.failed) == 0 assert result.returncode == 1
# Path relative to root doesn't work
result = lint.roll(os.path.join("files", "foobar.js")) assert len(result.issues) == 0 assert len(result.failed) == 0 assert result.returncode == 0
# Paths from vcs are always joined to root instead of cwd
lint.mock_vcs([os.path.join("files", "foobar.js")])
result = lint.roll(outgoing=True) assert len(result.issues) == 1 assert len(result.failed) == 0 assert result.returncode == 1
@pytest.mark.skipif(
platform.system() == "Windows",
reason="signal.CTRL_C_EVENT isn't causing a KeyboardInterrupt on Windows",
) def test_keyboard_interrupt(): # We use two linters so we'll have two jobs. One (string.yml) will complete # quickly. The other (slow.yml) will run slowly. This way the first worker # will be be stuck blocking on the ProcessPoolExecutor._call_queue when the # signal arrives and the other still be doing work.
cmd = [sys.executable, "runcli.py", "-l=string", "-l=slow", "files/foobar.js"]
env = os.environ.copy()
env["PYTHONPATH"] = os.pathsep.join(sys.path)
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=here,
env=env,
universal_newlines=True,
)
time.sleep(1)
proc.send_signal(signal.SIGINT)
out = proc.communicate()[0]
print(out) assert"warning: not all files were linted"in out assert"2 problems"in out assert"Traceback"notin out
def test_support_files(lint, linters, filedir, monkeypatch, files):
jobs = []
# Replace the original _generate_jobs with a new one that simply # adds jobs to a list (and then doesn't return anything).
orig_generate_jobs = lint._generate_jobs
def fake_generate_jobs(*args, **kwargs):
jobs.extend([job[1] for job in orig_generate_jobs(*args, **kwargs)]) return []
# Modified support files only lint entire root if --outgoing or --workdir # are used.
path = os.path.join(filedir, "foobar.js")
vcs_path = os.path.join(filedir, "foobar.py")
jobs = []
lint.roll(path, rev='draft() and keyword("dummy revset expression")')
actual_files = sorted(chain(*jobs)) assert actual_files == expected_files
# Lint config file is implicitly added as a support file
lint.mock_vcs([linter_path])
jobs = []
lint.roll(path, outgoing=True, workdir=True)
actual_files = sorted(chain(*jobs)) assert actual_files == expected_files
# Avoid linting the entire root when `--fix` is passed.
lint.mock_vcs([vcs_path])
lint.lintargs["fix"] = True
jobs = []
lint.roll(path, outgoing=True)
actual_files = sorted(chain(*jobs)) assert actual_files == sorted([path, vcs_path]), ( "`--fix` with `--outgoing` on a `support-files` change should " "avoid linting the entire root."
)
jobs = []
lint.roll(path, workdir=True)
actual_files = sorted(chain(*jobs)) assert actual_files == sorted([path, vcs_path]), ( "`--fix` with `--workdir` on a `support-files` change should " "avoid linting the entire root."
)
jobs = []
lint.roll(path, rev='draft() and keyword("dummy revset expression")')
actual_files = sorted(chain(*jobs)) assert actual_files == sorted([path, vcs_path]), ( "`--fix` with `--rev` on a `support-files` change should " "avoid linting the entire root."
)
def test_setup(lint, linters, filedir, capfd): with pytest.raises(NoValidLinter):
lint.setup()
lint.read(linters("setup", "setupfailed", "setupraised"))
lint.setup()
out, err = capfd.readouterr() assert"setup passed"in out assert"setup failed"in out assert"setup raised"in out assert"error: problem with lint setup, skipping"in out assert lint.result.failed_setup == set(["SetupFailedLinter", "SetupRaisedLinter"])
if __name__ == "__main__":
mozunit.main()
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.