From 86217946108682b95a4014a701dfbf53387a0c5e Mon Sep 17 00:00:00 2001 From: Aniruddha Date: Tue, 14 Sep 2021 11:02:24 +0530 Subject: Add test to test adequate exception handling --- tests/unit/test_isort.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tests') 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 = ( -- cgit v1.2.1