Skip to content

Commit

Permalink
Add tests for crash on inference of __len__
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Nov 6, 2021
1 parent 0a1ebd4 commit 45433cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/regrtest_data/numpy_crash_tester/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Test package for the crash reported in #5244
https://github.com/PyCQA/pylint/issues/5244"""
18 changes: 18 additions & 0 deletions tests/regrtest_data/numpy_crash_tester/test_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Module docstring"""


class MyClass:
"""Class to test crash reported in:
https://github.com/PyCQA/pylint/issues/5244
"""

def __init__(self, array):
self.array = array

def __len__(self):
"""Initially reported crash crashed on this function def"""
return len(self.array)

def public_method(self):
"""docstring"""
print(self.array)
8 changes: 8 additions & 0 deletions tests/test_regr.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@ def test_hang(
) -> None:
with timeout(timeout_s):
finalize_linter.check(file_names)


def test_numpy_regression_crash(finalize_linter: PyLinter) -> None:
# Test for a crash on packages whose name start with `numpy`
# See: https://github.com/PyCQA/pylint/issues/5244
finalize_linter.check([join(REGR_DATA, "numpy_crash_tester/test_file.py")])
# Check that we do not issue any (fatal) messages
assert finalize_linter.msg_status == 0

0 comments on commit 45433cf

Please sign in to comment.