diff options
| author | Aniruddha <aniruddha97bhatt@gmail.com> | 2021-09-14 11:02:24 +0530 |
|---|---|---|
| committer | Aniruddha <aniruddha97bhatt@gmail.com> | 2021-09-14 11:02:24 +0530 |
| commit | 86217946108682b95a4014a701dfbf53387a0c5e (patch) | |
| tree | b5c1690c9c3722126fe0abf2a536cb41ea58a0f0 /tests | |
| parent | 3f13b80d1dca23be18b1ac6a3859b91530b0d7db (diff) | |
| download | isort-86217946108682b95a4014a701dfbf53387a0c5e.tar.gz | |
Add test to test adequate exception handling
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_isort.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index f6f905fd..bf22d34b 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -19,7 +19,7 @@ from isort import api, sections, files from isort.settings import Config from isort.utils import exists_case_sensitive -from isort.exceptions import FileSkipped, ExistingSyntaxErrors +from isort.exceptions import FileSkipped, ExistingSyntaxErrors, MissingSection from .utils import as_stream, UnreadableStream if TYPE_CHECKING: @@ -2037,6 +2037,41 @@ def test_custom_sections() -> None: ) +def test_custom_sections_exception_handling() -> None: + """Ensure that appropriate exception is raised for missing sections""" + test_input = "import requests\n" + + with pytest.raises(MissingSection): + isort.code( + code=test_input, + default_section="THIRDPARTY", + sections=[ + "FUTURE", + "STDLIB", + "DJANGO", + "PANDAS", + "FIRSTPARTY", + "LOCALFOLDER", + ], + ) + + test_input = "from requests import get, post\n" + + with pytest.raises(MissingSection): + isort.code( + code=test_input, + default_section="THIRDPARTY", + sections=[ + "FUTURE", + "STDLIB", + "DJANGO", + "PANDAS", + "FIRSTPARTY", + "LOCALFOLDER", + ], + ) + + def test_glob_known() -> None: """Ensure that most specific placement control match wins""" test_input = ( |
