-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_errors.py
More file actions
156 lines (120 loc) · 4.07 KB
/
Copy pathtest_errors.py
File metadata and controls
156 lines (120 loc) · 4.07 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""Tests for the agentic_codebase.errors module.
Validates the error hierarchy and attributes.
"""
from __future__ import annotations
import pytest
from agentic_codebase.errors import (
AcbError,
CompileError,
GraphNotFoundError,
LibraryNotFoundError,
OverflowError,
StorageError,
UnitNotFoundError,
ValidationError,
)
class TestAcbError:
def test_base_error(self) -> None:
err = AcbError("test error")
assert str(err) == "test error"
assert err.code == -1
def test_custom_code(self) -> None:
err = AcbError("fail", code=-42)
assert err.code == -42
def test_is_exception(self) -> None:
assert issubclass(AcbError, Exception)
class TestGraphNotFoundError:
def test_stores_path(self) -> None:
err = GraphNotFoundError("/tmp/project.acb")
assert err.path == "/tmp/project.acb"
assert "/tmp/project.acb" in str(err)
assert err.code == -3
def test_is_acb_error(self) -> None:
assert issubclass(GraphNotFoundError, AcbError)
class TestUnitNotFoundError:
def test_stores_id(self) -> None:
err = UnitNotFoundError(42)
assert err.unit_id == 42
assert "42" in str(err)
assert err.code == -3
def test_is_acb_error(self) -> None:
assert issubclass(UnitNotFoundError, AcbError)
class TestCompileError:
def test_default(self) -> None:
err = CompileError()
assert "Compilation" in str(err)
assert err.code == -2
def test_custom(self) -> None:
err = CompileError("parse error in main.rs")
assert "parse error" in str(err)
def test_is_acb_error(self) -> None:
assert issubclass(CompileError, AcbError)
class TestStorageError:
def test_with_path(self) -> None:
err = StorageError("/tmp/project.acb")
assert err.path == "/tmp/project.acb"
assert "/tmp/project.acb" in str(err)
assert err.code == -1
def test_is_acb_error(self) -> None:
assert issubclass(StorageError, AcbError)
class TestLibraryNotFoundError:
def test_default(self) -> None:
err = LibraryNotFoundError()
assert "Native library not found" in str(err)
assert err.searched == []
assert err.code == -1
def test_with_locations(self) -> None:
err = LibraryNotFoundError(["/usr/lib", "/opt/lib"])
assert "/usr/lib" in str(err)
assert "/opt/lib" in str(err)
assert err.searched == ["/usr/lib", "/opt/lib"]
def test_is_acb_error(self) -> None:
assert issubclass(LibraryNotFoundError, AcbError)
class TestValidationError:
def test_default(self) -> None:
err = ValidationError()
assert "Validation" in str(err)
assert err.code == -6
def test_is_acb_error(self) -> None:
assert issubclass(ValidationError, AcbError)
def test_raise(self) -> None:
with pytest.raises(AcbError):
raise ValidationError("invalid query")
class TestOverflowError:
def test_default(self) -> None:
err = OverflowError()
assert "overflow" in str(err).lower()
assert err.code == -4
def test_is_acb_error(self) -> None:
assert issubclass(OverflowError, AcbError)
class TestHierarchy:
"""All errors should be subclasses of both AcbError and Exception."""
@pytest.mark.parametrize(
"cls",
[
GraphNotFoundError,
UnitNotFoundError,
CompileError,
StorageError,
LibraryNotFoundError,
ValidationError,
OverflowError,
],
)
def test_is_subclass_of_acb_error(self, cls: type) -> None:
assert issubclass(cls, AcbError)
@pytest.mark.parametrize(
"cls",
[
AcbError,
GraphNotFoundError,
UnitNotFoundError,
CompileError,
StorageError,
LibraryNotFoundError,
ValidationError,
OverflowError,
],
)
def test_is_subclass_of_exception(self, cls: type) -> None:
assert issubclass(cls, Exception)