Skip to content

Commit

Permalink
Merge branch 'typing-filepath-tests' of https://github.com/DanielNoor…
Browse files Browse the repository at this point in the history
…d/pylint into typing-filepath
  • Loading branch information
DanielNoord committed Sep 15, 2021
2 parents fa5d6f3 + 56b1061 commit 3269364
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tests/checkers/unittest_variables.py
Expand Up @@ -368,7 +368,7 @@ def test_package_all() -> None:

sys.path.insert(0, REGR_DATA_DIR)
try:
linter.check(os.path.join(REGR_DATA_DIR, "package_all"))
linter.check([os.path.join(REGR_DATA_DIR, "package_all")])
got = linter.reporter.finalize().strip()
assert got == "E: 3: Undefined variable name 'missing' in __all__"
finally:
Expand Down
3 changes: 2 additions & 1 deletion tests/extensions/test_broad_try_clause.py
Expand Up @@ -13,6 +13,7 @@
"""Tests for the pylint checker in :mod:`pylint.extensions.broad_try_clause`"""
import unittest
from os import path as osp
from typing import Optional

from pylint import checkers
from pylint.extensions.broad_try_clause import BroadTryClauseChecker
Expand All @@ -21,7 +22,7 @@


class BroadTryClauseTestReporter(BaseReporter):
def on_set_current_module(self, module: str, filepath: str) -> None:
def on_set_current_module(self, module: str, filepath: Optional[str]) -> None:
self.messages = []

def _display(self, layout):
Expand Down
3 changes: 2 additions & 1 deletion tests/extensions/test_comparetozero.py
Expand Up @@ -14,6 +14,7 @@

import os
import unittest
from typing import Optional

from pylint import checkers
from pylint.extensions.comparetozero import CompareToZeroChecker
Expand All @@ -22,7 +23,7 @@


class CompareToZeroTestReporter(BaseReporter):
def on_set_current_module(self, module: str, filepath: str) -> None:
def on_set_current_module(self, module: str, filepath: Optional[str]) -> None:
self.messages = []

def _display(self, layout):
Expand Down
6 changes: 3 additions & 3 deletions tests/lint/test_utils.py
@@ -1,4 +1,4 @@
from pathlib import PosixPath
from pathlib import Path, PosixPath

from pylint.lint.utils import get_fatal_error_message, prepare_crash_report

Expand All @@ -13,7 +13,7 @@ def test_prepare_crash_report(tmp_path: PosixPath) -> None:
raise Exception(exception_content)
except Exception as ex: # pylint: disable=broad-except
template_path = prepare_crash_report(
ex, python_file, tmp_path / "pylint-crash-%Y.txt"
ex, str(python_file), str(tmp_path / "pylint-crash-%Y.txt")
)
assert str(tmp_path) in str(template_path)
with open(template_path, encoding="utf8") as f:
Expand All @@ -27,7 +27,7 @@ def test_prepare_crash_report(tmp_path: PosixPath) -> None:
def test_get_fatal_error_message() -> None:
python_path = "mypath.py"
crash_path = "crash.txt"
msg = get_fatal_error_message(python_path, crash_path)
msg = get_fatal_error_message(python_path, Path(crash_path))
assert python_path in msg
assert crash_path in msg
assert "open an issue" in msg
10 changes: 5 additions & 5 deletions tests/lint/unittest_lint.py
Expand Up @@ -269,7 +269,7 @@ def visit_class(self, _):
linter.open()
out = StringIO()
linter.set_reporter(text.TextReporter(out))
linter.check("abc")
linter.check(["abc"])


def test_enable_message(init_linter: PyLinter) -> None:
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_init_hooks_called_before_load_plugins() -> None:

def test_analyze_explicit_script(linter: PyLinter) -> None:
linter.set_reporter(testutils.GenericTestReporter())
linter.check(os.path.join(DATA_DIR, "ascript"))
linter.check([os.path.join(DATA_DIR, "ascript")])
assert ["C: 2: Line too long (175/100)"] == linter.reporter.messages


Expand Down Expand Up @@ -826,15 +826,15 @@ def test_filename_with__init__(init_linter: PyLinter) -> None:
def test_by_module_statement_value(init_linter: PyLinter) -> None:
"""Test "statement" for each module analized of computed correctly."""
linter = init_linter
linter.check(os.path.join(os.path.dirname(__file__), "data"))
linter.check([os.path.join(os.path.dirname(__file__), "data")])

for module, module_stats in linter.stats["by_module"].items():

linter2 = init_linter
if module == "data":
linter2.check(os.path.join(os.path.dirname(__file__), "data/__init__.py"))
linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")])
else:
linter2.check(os.path.join(os.path.dirname(__file__), module))
linter2.check([os.path.join(os.path.dirname(__file__), module)])

# Check that the by_module "statement" is equal to the global "statement"
# computed for that module
Expand Down
12 changes: 8 additions & 4 deletions tests/test_check_parallel.py
Expand Up @@ -178,7 +178,7 @@ def test_worker_initialize(self) -> None:
def test_worker_check_single_file_uninitialised(self) -> None:
pylint.lint.parallel._worker_linter = None
with pytest.raises( # Objects that do not match the linter interface will fail
AttributeError, match="'NoneType' object has no attribute 'open'"
Exception, match="Worker linter not yet initialised"
):
worker_check_single_file(_gen_file_data())

Expand Down Expand Up @@ -290,7 +290,9 @@ def test_sequential_checkers_work(self) -> None:

# Invoke the lint process in a multiprocess way, although we only specify one
# job.
check_parallel(linter, jobs=1, files=single_file_container, arguments=None)
check_parallel(
linter, jobs=1, files=iter(single_file_container), arguments=None
)
assert len(linter.get_checkers()) == 2, (
"We should only have the 'master' and 'sequential-checker' "
"checkers registered"
Expand Down Expand Up @@ -319,7 +321,7 @@ def test_sequential_checkers_work(self) -> None:

# now run the regular mode of checking files and check that, in this proc, we
# collect the right data
filepath = single_file_container[0][1] # get the filepath element
filepath = [single_file_container[0][1]] # get the filepath element
linter.check(filepath)
assert {
"by_module": {
Expand Down Expand Up @@ -357,7 +359,9 @@ def test_invoke_single_job(self) -> None:

# Invoke the lint process in a multiprocess way, although we only specify one
# job.
check_parallel(linter, jobs=1, files=single_file_container, arguments=None)
check_parallel(
linter, jobs=1, files=iter(single_file_container), arguments=None
)

assert {
"by_module": {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_import_graph.py
Expand Up @@ -106,7 +106,7 @@ def test_checker_dep_graphs(linter: PyLinter) -> None:
linter.global_set_option("int-import-graph", "int_import.dot")
# ignore this file causing spurious MemoryError w/ some python version (>=2.3?)
linter.global_set_option("ignore", ("func_unknown_encoding.py",))
linter.check("input")
linter.check(["input"])
linter.generate_reports()
assert exists("import.dot")
assert exists("ext_import.dot")
Expand Down
26 changes: 13 additions & 13 deletions tests/test_regr.py
Expand Up @@ -61,15 +61,15 @@ def Equals(expected):
@pytest.mark.parametrize(
"file_name, check",
[
("package.__init__", Equals("")),
("precedence_test", Equals("")),
("import_package_subpackage_module", Equals("")),
("pylint.checkers.__init__", lambda x: "__path__" not in x),
(join(REGR_DATA, "classdoc_usage.py"), Equals("")),
(join(REGR_DATA, "module_global.py"), Equals("")),
(join(REGR_DATA, "decimal_inference.py"), Equals("")),
(join(REGR_DATA, "absimp", "string.py"), Equals("")),
(join(REGR_DATA, "bad_package"), lambda x: "Unused import missing" in x),
(["package.__init__"], Equals("")),
(["precedence_test"], Equals("")),
(["import_package_subpackage_module"], Equals("")),
(["pylint.checkers.__init__"], lambda x: "__path__" not in x),
([join(REGR_DATA, "classdoc_usage.py")], Equals("")),
([join(REGR_DATA, "module_global.py")], Equals("")),
([join(REGR_DATA, "decimal_inference.py")], Equals("")),
([join(REGR_DATA, "absimp", "string.py")], Equals("")),
([join(REGR_DATA, "bad_package")], lambda x: "Unused import missing" in x),
],
)
def test_package(finalize_linter, file_name, check):
Expand All @@ -94,7 +94,7 @@ def test_crash(finalize_linter, file_name):
"fname", [x for x in os.listdir(REGR_DATA) if x.endswith("_crash.py")]
)
def test_descriptor_crash(fname: str, finalize_linter: PyLinter) -> None:
finalize_linter.check(join(REGR_DATA, fname))
finalize_linter.check([join(REGR_DATA, fname)])
finalize_linter.reporter.finalize().strip()


Expand All @@ -109,13 +109,13 @@ def modify_path() -> Iterator:

@pytest.mark.usefixtures("modify_path")
def test_check_package___init__(finalize_linter: PyLinter) -> None:
filename = "package.__init__"
filename = ["package.__init__"]
finalize_linter.check(filename)
checked = list(finalize_linter.stats["by_module"].keys())
assert checked == [filename]
assert checked == filename

os.chdir(join(REGR_DATA, "package"))
finalize_linter.check("__init__")
finalize_linter.check(["__init__"])
checked = list(finalize_linter.stats["by_module"].keys())
assert checked == ["__init__"]

Expand Down

0 comments on commit 3269364

Please sign in to comment.