forked from PrefectHQ/prefect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_highlighters.py
69 lines (58 loc) · 2.24 KB
/
test_highlighters.py
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
import pytest
from rich.text import Span, Text
from prefect.logging.highlighters import (
LevelHighlighter,
NameHighlighter,
PrefectConsoleHighlighter,
StateHighlighter,
UrlHighlighter,
)
@pytest.mark.parametrize("level", ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"])
def test_highlight_level(level):
text = Text(f"10:21:34.114 | {level} | Flow run 'polite-jackal' - Hello Marvin!")
highlighter = LevelHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(15, 15 + len(level), f"level.{level.lower()}_level"),
]
@pytest.mark.parametrize("url_kind", ["web", "local"])
def test_highlight_url(url_kind):
url = "https://www.prefect.io/" if url_kind == "web" else "file://tests.py"
text = Text(f"10:21:34.114 | INFO | Flow run 'polite-jackal' - {url}")
highlighter = UrlHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(52, 52 + len(url), f"url.{url_kind}_url"),
]
@pytest.mark.parametrize("name", ["flow_run", "flow", "task_run", "task"])
@pytest.mark.parametrize("lower", [True, False])
def test_highlight_name(name, lower):
keyword = name.replace("_", " ").strip()
keyword = keyword.lower() if lower else keyword.upper()
text = Text(f"10:21:34.114 | INFO | {keyword} 'polite-jackal'")
highlighter = NameHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(25 + len(keyword), 41 + len(keyword), f"name.{name}_name"),
]
@pytest.mark.parametrize("state", ["completed", "cancelled", "failed", "crashed"])
def test_highlight_state(state):
keyword = state.title()
text = Text(f"Flow run 'polite-jackal' - Finished in state {keyword}()")
highlighter = StateHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(45, 45 + len(keyword), f"state.{state}_state"),
]
def test_highlight_console():
text = Text(
"10:21:34.114 | INFO | Flow run 'polite-jackal' - Finished in state"
" Completed()"
)
highlighter = PrefectConsoleHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(15, 19, "log.info_level"),
Span(33, 49, "log.flow_run_name"),
Span(70, 79, "log.completed_state"),
]