Skip to content

Commit bbb8a25

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Update comments and typing
1 parent 675b46c commit bbb8a25

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

tests/primer/primer_clone_external.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
def _lazy_git_clone(data: PackageToLint, target_directory: str) -> None:
1212
"""Clones a repository while checking if it hasn't already been cloned"""
1313
if os.path.exists(target_directory):
14+
# Get SHA1 hash of latest commit on remote branch
1415
remote_sha1_commit = (
1516
git.cmd.Git().ls_remote(data.url, data.branch).split("\t")[0]
1617
)
18+
# Get SHA1 hash of latest commit on locally downloaded branch
1719
local_sha1_commit = git.Repo(target_directory).head.object.hexsha
20+
1821
if remote_sha1_commit != local_sha1_commit:
22+
# Remove directory and all its files
1923
shutil.rmtree(target_directory)
2024
git.Repo.clone_from(
2125
data.url,

tests/primer/primer_external_packages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ class PackageToLint(NamedTuple):
3030
"https://github.com/numpy/numpy.git", "main", None, "/numpy/numpy", "numpy"
3131
),
3232
}
33+
"""Dictionary of external packages used during the primer test"""

tests/primer/test_primer_external.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@
55

66
import pytest
77
from tests.primer.primer_clone_external import clone_primer_packages
8-
from tests.primer.primer_external_packages import PACKAGES_TO_LINT, PRIMER_DIRECTORY
8+
from tests.primer.primer_external_packages import (
9+
PACKAGES_TO_LINT,
10+
PRIMER_DIRECTORY,
11+
PackageToLint,
12+
)
913

1014

1115
class TestPrimer:
1216
@staticmethod
1317
@pytest.mark.primer
14-
@pytest.mark.parametrize(("package"), PACKAGES_TO_LINT)
15-
def test_primer_external_packages_no_crash(package: str) -> None:
18+
@pytest.mark.parametrize(
19+
("package"), PACKAGES_TO_LINT.values(), ids=PACKAGES_TO_LINT
20+
)
21+
def test_primer_external_packages_no_crash(package: PackageToLint) -> None:
1622
"""Runs pylint over external packages to check for crashes and fatal messages
1723
1824
We only check for crashes (bit-encoded exit code 32) and
1925
fatal messages (bit-encoded exit code 1). We assume that these external repositories
2026
do not have any fatal errors in their code so that any fatal errors are pylint false
2127
positives
2228
"""
23-
package_data = PACKAGES_TO_LINT[package]
24-
2529
# Clone the packages repository
26-
clone_primer_packages(package_data)
30+
clone_primer_packages(package)
2731

2832
try:
2933
subprocess.run(
3034
["pylint"]
3135
+ [
32-
f"{PRIMER_DIRECTORY}{package_data.clone_directory}/{i}"
33-
for i in package_data.directories.split(" ")
36+
f"{PRIMER_DIRECTORY}{package.clone_directory}/{i}"
37+
for i in package.directories.split(" ")
3438
]
3539
+ ["--errors-only", "--rcfile=./pylintrc"],
3640
check=True,

tests/primer/test_primer_stdlib.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import pylint.lint
1212

1313

14-
def is_module(filename):
14+
def is_module(filename: str) -> bool:
1515
return filename.endswith(".py")
1616

1717

18-
def is_package(filename, location):
18+
def is_package(filename: str, location: str) -> bool:
1919
return os.path.exists(os.path.join(location, filename, "__init__.py"))
2020

2121

@@ -42,11 +42,12 @@ def _patch_stdout(out):
4242
@pytest.mark.parametrize(
4343
("test_module_location", "test_module_name"), MODULES_TO_CHECK, ids=MODULES_NAMES
4444
)
45-
def test_lib_module_no_crash(test_module_location, test_module_name):
45+
def test_lib_module_no_crash(test_module_location: str, test_module_name: str) -> None:
46+
"""Test that pylint does not produces any crashes on stdlib modules"""
4647
os.chdir(test_module_location)
48+
4749
with _patch_stdout(io.StringIO()):
4850
try:
4951
pylint.lint.Run([test_module_name, "--enable=all", "--ignore=test"])
5052
except SystemExit as ex:
5153
assert ex.code != 32
52-
return

0 commit comments

Comments
 (0)