-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_diagnostics.py
More file actions
101 lines (75 loc) · 2.62 KB
/
test_diagnostics.py
File metadata and controls
101 lines (75 loc) · 2.62 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
from databricks.bundles.core import (
Diagnostic,
Diagnostics,
Location,
Severity,
)
def test_catch_exceptions():
diagnostics = Diagnostics()
try:
diagnostics = diagnostics.extend(
Diagnostics.create_warning("foo is deprecated")
)
raise ValueError("foo is not available")
except ValueError as exc:
diagnostics = diagnostics.extend(
Diagnostics.from_exception(
exc=exc,
summary="failed to get foo",
)
)
assert len(diagnostics.items) == 2
assert diagnostics.items[0].summary == "foo is deprecated"
assert diagnostics.items[0].severity == Severity.WARNING
assert diagnostics.items[1].summary == "failed to get foo"
assert diagnostics.items[1].severity == Severity.ERROR
def test_extend():
diagnostics = Diagnostics.create_warning("foo is deprecated")
diagnostics = diagnostics.extend(Diagnostics.create_warning("bar is deprecated"))
assert diagnostics == Diagnostics(
items=(
Diagnostic(
severity=Severity.WARNING,
summary="foo is deprecated",
),
Diagnostic(
severity=Severity.WARNING,
summary="bar is deprecated",
),
),
)
def test_extend_tuple():
def foo() -> tuple[int, Diagnostics]:
return 42, Diagnostics.create_warning("bar is deprecated")
diagnostics = Diagnostics.create_warning("foo is deprecated")
value, diagnostics = diagnostics.extend_tuple(foo())
assert value == 42
assert diagnostics == Diagnostics(
items=(
Diagnostic(
severity=Severity.WARNING,
summary="foo is deprecated",
),
Diagnostic(
severity=Severity.WARNING,
summary="bar is deprecated",
),
),
)
def test_location_from_callable():
location = Location.from_callable(test_location_from_callable)
assert location
assert location.file == "databricks_tests/core/test_diagnostics.py"
assert location.line and location.line > 0
assert location.column and location.column > 0
def test_location_from_weird_callable():
location = Location.from_callable(print)
assert location is None
def test_has_error():
diagnostics = Diagnostics.create_error("foo is deprecated")
assert diagnostics.has_error()
assert not diagnostics.has_warning()
def test_has_warning():
diagnostics = Diagnostics.create_warning("foo is deprecated")
assert not diagnostics.has_error()
assert diagnostics.has_warning()