Repository: sanic-org/sanic
Pull request #2803 (2023-08-21 13:39:46)

Fix MOTD for extra data
![image](https://github.com/sanic-org/sanic/assets/166269/9c76a1af-f572-482d-8d17-5f77026f0d10)

This one has bugged me for a while. In short, the problem was that the alignment of keys ignored the extras. Therefore you could end up with misalignment and weird spacing. Also, the values were not breaking properly.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/sanic-org/sanic/pull/2803?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sanic-org) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`7d93c10`)](https://app.codecov.io/gh/sanic-org/sanic/commit/7d93c106029d58bb43681ff93e39aa0aa9ec9f2b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sanic-org) 88.348% compared to head [(`1628b54`)](https://app.codecov.io/gh/sanic-org/sanic/pull/2803?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sanic-org) 88.354%.


<details><summary>Additional details and impacted files</summary>


```diff
@@              Coverage Diff              @@
##              main     #2803       +/-   ##
=============================================
+ Coverage   88.348%   88.354%   +0.006%     
=============================================
  Files           92        92               
  Lines         7175      7179        +4     
  Branches      1232      1233        +1     
=============================================
+ Hits          6339      6343        +4     
  Misses         581       581               
  Partials       255       255               
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/sanic-org/sanic/pull/2803?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sanic-org).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sanic-org).


Patch:
diff --git a/sanic/application/motd.py b/sanic/application/motd.py
index 0409bd06..f7dd1d29 100644
--- a/sanic/application/motd.py
+++ b/sanic/application/motd.py
@@ -91,6 +91,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 = (
@@ -131,7 +139,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)
diff --git a/sanic/mixins/startup.py b/sanic/mixins/startup.py
index 54428e7d..5e640fed 100644
--- a/sanic/mixins/startup.py
+++ b/sanic/mixins/startup.py
@@ -89,7 +89,7 @@ else:  # no cov
 
 class StartupMixin(metaclass=SanicMeta):
     _app_registry: ClassVar[Dict[str, Sanic]]
-
+    name: str
     asgi: bool
     config: Config
     listeners: Dict[str, List[ListenerType[Any]]]
@@ -790,6 +790,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(),


Test patch:
diff --git a/tests/test_motd.py b/tests/test_motd.py
index 2e9eeab7..5fe4a2f0 100644
--- a/tests/test_motd.py
+++ b/tests/test_motd.py
@@ -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 │
   └───────────────────────┴────────┘
 """
diff --git a/tests/test_static.py b/tests/test_static.py
index 925a81ae..a8df59ab 100644
--- a/tests/test_static.py
+++ b/tests/test_static.py
@@ -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