Compare commits

...

5 Commits

Author SHA1 Message Date
Adam Hopkins
44bf7ba79a
Cleanup tests 2023-08-21 22:54:04 +03:00
Adam Hopkins
9e7ca10c52
Cleanup tests 2023-08-21 21:37:45 +03:00
Adam Hopkins
fe32f4eb74
Fix border character 2023-08-21 20:10:47 +03:00
Adam Hopkins
ebe29d3d26
Make pretty 2023-08-21 16:40:22 +03:00
Adam Hopkins
f651f7436f
Fix MOTD for extra data 2023-08-21 16:37:55 +03:00
4 changed files with 19 additions and 8 deletions

View File

@ -73,6 +73,14 @@ class MOTDTTY(MOTD):
self.value_width = min(
max(map(len, self.data.values())), self.max_value_width
)
if self.extra:
self.key_width = max(
self.key_width, max(map(len, self.extra.keys()))
)
self.value_width = min(
max((*map(len, self.extra.values()), self.value_width)),
self.max_value_width,
)
self.logo_lines = self.logo.split("\n") if self.logo else []
self.logo_line_length = 24
self.centering_length = (
@ -104,7 +112,7 @@ class MOTDTTY(MOTD):
self._render_data(lines, self.data, 0)
if self.extra:
logo_part = self._get_logo_part(len(lines) - 4)
lines.append(f"| {logo_part}{display_filler}")
lines.append(f" {logo_part}{display_filler}")
self._render_data(lines, self.extra, len(lines) - 4)
self._render_fill(lines)

View File

@ -90,6 +90,7 @@ else: # no cov
class StartupMixin(metaclass=SanicMeta):
_app_registry: ClassVar[Dict[str, Sanic]]
name: str
config: Config
listeners: Dict[str, List[ListenerType[Any]]]
state: ApplicationState
@ -605,6 +606,7 @@ class StartupMixin(metaclass=SanicMeta):
server = "ASGI" if self.asgi else "unknown" # type: ignore
display = {
"app": self.name,
"mode": " ".join(mode),
"server": server,
"python": platform.python_version(),

View File

@ -31,10 +31,11 @@ def test_motd_with_expected_info(app, run_startup):
logs = run_startup(app)
assert logs[1][2] == f"Sanic v{__version__}"
assert logs[3][2] == "mode: debug, single worker"
assert logs[4][2] == "server: sanic, HTTP/1.1"
assert logs[5][2] == f"python: {platform.python_version()}"
assert logs[6][2] == f"platform: {platform.platform()}"
assert logs[3][2] == "app: test_motd_with_expected_info"
assert logs[4][2] == "mode: debug, single worker"
assert logs[5][2] == "server: sanic, HTTP/1.1"
assert logs[6][2] == f"python: {platform.python_version()}"
assert logs[7][2] == f"platform: {platform.platform()}"
def test_motd_init():
@ -61,7 +62,7 @@ def test_motd_display(caplog):
foobar one: 1
|
two: 2
"""

View File

@ -517,7 +517,7 @@ def test_stack_trace_on_not_found(app, static_file_directory, caplog):
counter = Counter([(r[0], r[1]) for r in caplog.record_tuples])
assert response.status == 404
assert counter[("sanic.root", logging.INFO)] == 9
assert counter[("sanic.root", logging.INFO)] == 10
assert counter[("sanic.root", logging.ERROR)] == 0
assert counter[("sanic.error", logging.ERROR)] == 0
assert counter[("sanic.server", logging.INFO)] == 2
@ -536,7 +536,7 @@ def test_no_stack_trace_on_not_found(app, static_file_directory, caplog):
counter = Counter([(r[0], r[1]) for r in caplog.record_tuples])
assert response.status == 404
assert counter[("sanic.root", logging.INFO)] == 9
assert counter[("sanic.root", logging.INFO)] == 10
assert counter[("sanic.root", logging.ERROR)] == 0
assert counter[("sanic.error", logging.ERROR)] == 0
assert counter[("sanic.server", logging.INFO)] == 2