|
1
|
"""Tests for boilerworks.console.""" |
|
2
|
|
|
3
|
from __future__ import annotations |
|
4
|
|
|
5
|
from io import StringIO |
|
6
|
|
|
7
|
from rich.console import Console |
|
8
|
|
|
9
|
from boilerworks.console import ( |
|
10
|
print_error, |
|
11
|
print_info, |
|
12
|
print_success, |
|
13
|
print_template_detail, |
|
14
|
print_template_table, |
|
15
|
print_warning, |
|
16
|
) |
|
17
|
from boilerworks.registry import Registry, TemplateInfo |
|
18
|
|
|
19
|
|
|
20
|
def _capture(fn, *args, **kwargs) -> str: |
|
21
|
"""Call fn with a capturing console and return the output.""" |
|
22
|
buf = StringIO() |
|
23
|
cap = Console(file=buf, highlight=False, markup=True) |
|
24
|
# Temporarily override the module-level console |
|
25
|
import boilerworks.console as _mod |
|
26
|
|
|
27
|
original = _mod.console |
|
28
|
_mod.console = cap |
|
29
|
try: |
|
30
|
fn(*args, **kwargs) |
|
31
|
finally: |
|
32
|
_mod.console = original |
|
33
|
return buf.getvalue() |
|
34
|
|
|
35
|
|
|
36
|
class TestPrintTemplateTable: |
|
37
|
def test_shows_all_templates(self) -> None: |
|
38
|
registry = Registry() |
|
39
|
templates = registry.list_all() |
|
40
|
output = _capture(print_template_table, templates) |
|
41
|
assert "django-nextjs" in output |
|
42
|
assert "astro-site" in output |
|
43
|
|
|
44
|
def test_shows_26_count(self) -> None: |
|
45
|
registry = Registry() |
|
46
|
templates = registry.list_all() |
|
47
|
output = _capture(print_template_table, templates) |
|
48
|
assert "26" in output |
|
49
|
|
|
50
|
def test_empty_list_shows_message(self) -> None: |
|
51
|
output = _capture(print_template_table, []) |
|
52
|
assert "No templates match" in output |
|
53
|
|
|
54
|
def test_filtered_table(self) -> None: |
|
55
|
registry = Registry() |
|
56
|
templates = registry.filter_by_size("micro") |
|
57
|
output = _capture(print_template_table, templates) |
|
58
|
assert "fastapi-micro" in output |
|
59
|
assert "django-nextjs" not in output |
|
60
|
|
|
61
|
|
|
62
|
class TestPrintTemplateDetail: |
|
63
|
def test_shows_template_fields(self) -> None: |
|
64
|
registry = Registry() |
|
65
|
template = registry.get_by_name("django-nextjs") |
|
66
|
assert template is not None |
|
67
|
output = _capture(print_template_detail, template) |
|
68
|
assert "django-nextjs" in output |
|
69
|
assert "python" in output.lower() |
|
70
|
assert "Django" in output |
|
71
|
|
|
72
|
def test_template_without_frontend(self) -> None: |
|
73
|
# Micro templates have no frontend |
|
74
|
t = TemplateInfo( |
|
75
|
name="test-micro", |
|
76
|
repo="ConflictHQ/test", |
|
77
|
size="micro", |
|
78
|
language="python", |
|
79
|
backend="FastAPI", |
|
80
|
frontend="", |
|
81
|
status="planned", |
|
82
|
description="Test", |
|
83
|
) |
|
84
|
output = _capture(print_template_detail, t) |
|
85
|
assert "test-micro" in output |
|
86
|
|
|
87
|
|
|
88
|
class TestPrintHelpers: |
|
89
|
def test_print_success(self) -> None: |
|
90
|
output = _capture(print_success, "All good") |
|
91
|
assert "All good" in output |
|
92
|
|
|
93
|
def test_print_error(self) -> None: |
|
94
|
output = _capture(print_error, "Something failed") |
|
95
|
assert "Something failed" in output |
|
96
|
|
|
97
|
def test_print_info(self) -> None: |
|
98
|
output = _capture(print_info, "Just FYI") |
|
99
|
assert "Just FYI" in output |
|
100
|
|
|
101
|
def test_print_warning(self) -> None: |
|
102
|
output = _capture(print_warning, "Be careful") |
|
103
|
assert "Be careful" in output |
|
104
|
|