-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor crash handling in pylinter and add tests
- Loading branch information
1 parent
6b36245
commit fdcc9d2
Showing
3 changed files
with
98 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pylint.lint.utils import get_fatal_error_message, prepare_crash_report | ||
|
||
|
||
def test_prepare_crash_report(tmp_path): | ||
exception_content = "Exmessage" | ||
python_file = tmp_path / "myfile.py" | ||
python_content = "from shadok import MagicFaucet" | ||
with open(python_file, "w", encoding="utf8") as f: | ||
f.write(python_content) | ||
try: | ||
raise Exception(exception_content) | ||
except Exception as ex: # pylint: disable=broad-except | ||
template_path = prepare_crash_report(ex, python_file, tmp_path) | ||
assert str(tmp_path) in str(template_path) | ||
with open(template_path, encoding="utf8") as f: | ||
template_content = f.read() | ||
assert python_content in template_content | ||
assert exception_content in template_content | ||
assert "in test_prepare_crash_report" in template_content | ||
assert "raise Exception(exception_content)" in template_content | ||
|
||
|
||
def test_get_fatal_error_message(): | ||
python_path = "mypath.py" | ||
crash_path = "crash.txt" | ||
msg = get_fatal_error_message(python_path, crash_path) | ||
assert python_path in msg | ||
assert crash_path in msg | ||
assert "open an issue" in msg |