Skip to content

Commit 8621794

Browse files
committedSep 14, 2021
Add test to test adequate exception handling
1 parent 3f13b80 commit 8621794

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed
 

‎tests/unit/test_isort.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from isort.settings import Config
2020

2121
from isort.utils import exists_case_sensitive
22-
from isort.exceptions import FileSkipped, ExistingSyntaxErrors
22+
from isort.exceptions import FileSkipped, ExistingSyntaxErrors, MissingSection
2323
from .utils import as_stream, UnreadableStream
2424

2525
if TYPE_CHECKING:
@@ -2037,6 +2037,41 @@ def test_custom_sections() -> None:
20372037
)
20382038

20392039

2040+
def test_custom_sections_exception_handling() -> None:
2041+
"""Ensure that appropriate exception is raised for missing sections"""
2042+
test_input = "import requests\n"
2043+
2044+
with pytest.raises(MissingSection):
2045+
isort.code(
2046+
code=test_input,
2047+
default_section="THIRDPARTY",
2048+
sections=[
2049+
"FUTURE",
2050+
"STDLIB",
2051+
"DJANGO",
2052+
"PANDAS",
2053+
"FIRSTPARTY",
2054+
"LOCALFOLDER",
2055+
],
2056+
)
2057+
2058+
test_input = "from requests import get, post\n"
2059+
2060+
with pytest.raises(MissingSection):
2061+
isort.code(
2062+
code=test_input,
2063+
default_section="THIRDPARTY",
2064+
sections=[
2065+
"FUTURE",
2066+
"STDLIB",
2067+
"DJANGO",
2068+
"PANDAS",
2069+
"FIRSTPARTY",
2070+
"LOCALFOLDER",
2071+
],
2072+
)
2073+
2074+
20402075
def test_glob_known() -> None:
20412076
"""Ensure that most specific placement control match wins"""
20422077
test_input = (

0 commit comments

Comments
 (0)
Please sign in to comment.