-
-
Notifications
You must be signed in to change notification settings - Fork 485
Output a more clear configuration error #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
582c66c
Output a more clear configuration error
snejus 09fc634
Performance related improvements in config read handling
snejus c044ad8
Check python 3.6 with travis
snejus 3a7b28e
Revert the .travis.yml py36 inclusion
snejus eeb5da3
Added tests for input error handling
snejus 6475537
Thanks isort, isorted it out
snejus b38dde2
Make exit() function a bit more aesthetic
snejus 05ff4e2
Single quote -> double quote docstrings
snejus 1e3bf1e
Whitespace removed
snejus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
[pytest] | ||
testpaths = ./test-data | ||
testpaths = | ||
./test-plugin | ||
./test-data | ||
addopts = | ||
--tb=native | ||
-s | ||
|
This file contains hidden or 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,73 @@ | ||
import tempfile | ||
import typing | ||
|
||
import pytest | ||
|
||
from mypy_django_plugin.main import extract_django_settings_module | ||
|
||
TEMPLATE = """usage: (config) | ||
... | ||
[mypy.plugins.django_stubs] | ||
django_settings_module: str (required) | ||
... | ||
(django-stubs) mypy: error: 'django_settings_module' is not set: {} | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'config_file_contents,message_part', | ||
[ | ||
pytest.param( | ||
None, | ||
'mypy config file is not specified or found', | ||
id='missing-file', | ||
), | ||
pytest.param( | ||
['[not-really-django-stubs]'], | ||
'no section [mypy.plugins.django-stubs]', | ||
id='missing-section', | ||
), | ||
pytest.param( | ||
['[mypy.plugins.django-stubs]', | ||
'\tnot_django_not_settings_module = badbadmodule'], | ||
'the setting is not provided', | ||
id='missing-settings-module', | ||
), | ||
pytest.param( | ||
['[mypy.plugins.django-stubs]'], | ||
'the setting is not provided', | ||
id='no-settings-given', | ||
), | ||
], | ||
) | ||
def test_misconfiguration_handling(capsys, config_file_contents, message_part): | ||
# type: (typing.Any, typing.List[str], str) -> None | ||
"""Invalid configuration raises `SystemExit` with a precise error message.""" | ||
with tempfile.NamedTemporaryFile(mode='w+') as config_file: | ||
if not config_file_contents: | ||
config_file.close() | ||
else: | ||
config_file.write('\n'.join(config_file_contents).expandtabs(4)) | ||
config_file.seek(0) | ||
|
||
with pytest.raises(SystemExit, match='2'): | ||
extract_django_settings_module(config_file.name) | ||
|
||
error_message = TEMPLATE.format(message_part) | ||
assert error_message == capsys.readouterr().err | ||
|
||
|
||
def test_correct_configuration() -> None: | ||
"""Django settings module gets extracted given valid configuration.""" | ||
config_file_contents = [ | ||
'[mypy.plugins.django-stubs]', | ||
'\tsome_other_setting = setting', | ||
'\tdjango_settings_module = my.module', | ||
] | ||
with tempfile.NamedTemporaryFile(mode='w+') as config_file: | ||
config_file.write('\n'.join(config_file_contents).expandtabs(4)) | ||
config_file.seek(0) | ||
|
||
extracted = extract_django_settings_module(config_file.name) | ||
|
||
assert extracted == 'my.module' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse this const from somewhere else? Looks like we should already have it somewhere.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like it - at least not anywhere in the source code:
