Debian Codegraph @

tests/unit/test_exceptions.py

raw
1 import pickle
2
3 from isort import exceptions
4
5
6 class TestISortError:
7 def setup_class(self) -> None:
8 self.instance = exceptions.ISortError()
9
10 def test_init(self) -> None:
11 assert isinstance(self.instance, exceptions.ISortError)
12
13 def test_pickleable(self) -> None:
14 assert isinstance(pickle.loads(pickle.dumps(self.instance)), exceptions.ISortError)
15
16
17 class TestExistingSyntaxErrors(TestISortError):
18 def setup_class(self) -> None:
19 self.instance: exceptions.ExistingSyntaxErrors = exceptions.ExistingSyntaxErrors(
20 "file_path"
21 )
22
23 def test_variables(self) -> None:
24 assert self.instance.file_path == "file_path"
25
26
27 class TestIntroducedSyntaxErrors(TestISortError):
28 def setup_class(self) -> None:
29 self.instance: exceptions.IntroducedSyntaxErrors = exceptions.IntroducedSyntaxErrors(
30 "file_path"
31 )
32
33 def test_variables(self) -> None:
34 assert self.instance.file_path == "file_path"
35
36
37 class TestFileSkipped(TestISortError):
38 def setup_class(self) -> None:
39 self.instance: exceptions.FileSkipped = exceptions.FileSkipped("message", "file_path")
40
41 def test_variables(self) -> None:
42 assert self.instance.file_path == "file_path"
43 assert str(self.instance) == "message"
44
45
46 class TestFileSkipComment(TestISortError):
47 def setup_class(self) -> None:
48 self.instance: exceptions.FileSkipComment = exceptions.FileSkipComment("file_path")
49
50 def test_variables(self) -> None:
51 assert self.instance.file_path == "file_path"
52
53
54 class TestFileSkipSetting(TestISortError):
55 def setup_class(self) -> None:
56 self.instance: exceptions.FileSkipSetting = exceptions.FileSkipSetting("file_path")
57
58 def test_variables(self) -> None:
59 assert self.instance.file_path == "file_path"
60
61
62 class TestProfileDoesNotExist(TestISortError):
63 def setup_class(self) -> None:
64 self.instance: exceptions.ProfileDoesNotExist = exceptions.ProfileDoesNotExist("profile")
65
66 def test_variables(self) -> None:
67 assert self.instance.profile == "profile"
68
69
70 class TestSortingFunctionDoesNotExist(TestISortError):
71 def setup_class(self) -> None:
72 self.instance: exceptions.SortingFunctionDoesNotExist = (
73 exceptions.SortingFunctionDoesNotExist("round", ["square", "peg"])
74 )
75
76 def test_variables(self) -> None:
77 assert self.instance.sort_order == "round"
78 assert self.instance.available_sort_orders == ["square", "peg"]
79
80
81 class TestLiteralParsingFailure(TestISortError):
82 def setup_class(self) -> None:
83 self.instance: exceptions.LiteralParsingFailure = exceptions.LiteralParsingFailure(
84 "x = [", SyntaxError
85 )
86
87 def test_variables(self) -> None:
88 assert self.instance.code == "x = ["
89 assert self.instance.original_error is SyntaxError
90
91
92 class TestLiteralSortTypeMismatch(TestISortError):
93 def setup_class(self) -> None:
94 self.instance: exceptions.LiteralSortTypeMismatch = exceptions.LiteralSortTypeMismatch(
95 tuple, list
96 )
97
98 def test_variables(self) -> None:
99 assert self.instance.kind is tuple
100 assert self.instance.expected_kind is list
101
102
103 class TestAssignmentsFormatMismatch(TestISortError):
104 def setup_class(self) -> None:
105 self.instance: exceptions.AssignmentsFormatMismatch = exceptions.AssignmentsFormatMismatch(
106 "print x"
107 )
108
109 def test_variables(self) -> None:
110 assert self.instance.code == "print x"
111
112
113 class TestUnsupportedSettings(TestISortError):
114 def setup_class(self) -> None:
115 self.instance: exceptions.UnsupportedSettings = exceptions.UnsupportedSettings(
116 {"apply": {"value": "true", "source": "/"}}
117 )
118
119 def test_variables(self) -> None:
120 assert self.instance.unsupported_settings == {"apply": {"value": "true", "source": "/"}}
121
122
123 class TestUnsupportedEncoding(TestISortError):
124 def setup_class(self) -> None:
125 self.instance: exceptions.UnsupportedEncoding = exceptions.UnsupportedEncoding("file.py")
126
127 def test_variables(self) -> None:
128 assert self.instance.filename == "file.py"