summaryrefslogtreecommitdiff
path: root/tests/unit/test_exceptions.py
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-08-23 00:09:37 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2020-08-23 00:09:37 -0700
commit180bdf9abc91223eb9d7b9e713ead7451095c5da (patch)
tree810a40912008a048765afe83964cfb5d50793781 /tests/unit/test_exceptions.py
parent19221a3e3c4e17e51056d1e70cd565b16f149cea (diff)
downloadisort-180bdf9abc91223eb9d7b9e713ead7451095c5da.tar.gz
Start work to separate integration and unit testsseparate-integration-test
Diffstat (limited to 'tests/unit/test_exceptions.py')
-rw-r--r--tests/unit/test_exceptions.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
new file mode 100644
index 00000000..8a6f60fc
--- /dev/null
+++ b/tests/unit/test_exceptions.py
@@ -0,0 +1,84 @@
+from isort import exceptions
+
+
+class TestISortError:
+ def setup_class(self):
+ self.instance = exceptions.ISortError()
+
+ def test_init(self):
+ assert isinstance(self.instance, exceptions.ISortError)
+
+
+class TestExistingSyntaxErrors(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.ExistingSyntaxErrors("file_path")
+
+ def test_variables(self):
+ assert self.instance.file_path == "file_path"
+
+
+class TestIntroducedSyntaxErrors(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.IntroducedSyntaxErrors("file_path")
+
+ def test_variables(self):
+ assert self.instance.file_path == "file_path"
+
+
+class TestFileSkipped(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.FileSkipped("message", "file_path")
+
+ def test_variables(self):
+ assert self.instance.file_path == "file_path"
+ assert str(self.instance) == "message"
+
+
+class TestFileSkipComment(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.FileSkipComment("file_path")
+
+ def test_variables(self):
+ assert self.instance.file_path == "file_path"
+
+
+class TestFileSkipSetting(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.FileSkipSetting("file_path")
+
+ def test_variables(self):
+ assert self.instance.file_path == "file_path"
+
+
+class TestProfileDoesNotExist(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.ProfileDoesNotExist("profile")
+
+ def test_variables(self):
+ assert self.instance.profile == "profile"
+
+
+class TestLiteralParsingFailure(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.LiteralParsingFailure("x = [", SyntaxError)
+
+ def test_variables(self):
+ assert self.instance.code == "x = ["
+ assert self.instance.original_error == SyntaxError
+
+
+class TestLiteralSortTypeMismatch(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.LiteralSortTypeMismatch(tuple, list)
+
+ def test_variables(self):
+ assert self.instance.kind == tuple
+ assert self.instance.expected_kind == list
+
+
+class TestAssignmentsFormatMismatch(TestISortError):
+ def setup_class(self):
+ self.instance = exceptions.AssignmentsFormatMismatch("print x")
+
+ def test_variables(self):
+ assert self.instance.code == "print x"