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