File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ """Console helpers.
2+
3+ PyStatsV1 aims to be beginner-friendly across Windows/macOS/Linux.
4+ Some Windows terminals still default to non-UTF-8 encodings (e.g., cp1252),
5+ so **runtime console output should stay ASCII-only by default**.
6+
7+ These helpers provide consistent, ASCII-safe status prefixes for scripts.
8+ """
9+
10+ from __future__ import annotations
11+
12+ from typing import Final
13+
14+ OK_TAG : Final [str ] = "[OK]"
15+ WARN_TAG : Final [str ] = "[WARN]"
16+ FAIL_TAG : Final [str ] = "NOT OK"
17+
18+
19+ def status_ok (message : str = "" ) -> str :
20+ """Return an ASCII-safe OK status line.
21+
22+ Prefer using this in scripts instead of emoji markers, e.g.:
23+
24+ print(status_ok("Wrote outputs/..."))
25+ """
26+
27+ if not message :
28+ return OK_TAG
29+ return f"{ OK_TAG } { message } "
30+
31+
32+ def status_warn (message : str = "" ) -> str :
33+ """Return an ASCII-safe WARN status line."""
34+
35+ if not message :
36+ return WARN_TAG
37+ return f"{ WARN_TAG } { message } "
38+
39+
40+ def status_fail (message : str = "" ) -> str :
41+ """Return an ASCII-safe FAIL status line."""
42+
43+ if not message :
44+ return FAIL_TAG
45+ return f"{ FAIL_TAG } { message } "
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+
4+ def test_status_helpers_are_ascii () -> None :
5+ from pystatsv1 .console import status_fail , status_ok , status_warn
6+
7+ assert status_ok ("hello" ).isascii ()
8+ assert status_warn ("hello" ).isascii ()
9+ assert status_fail ("hello" ).isascii ()
10+
11+
12+ def test_status_helpers_prefixes () -> None :
13+ from pystatsv1 .console import status_fail , status_ok , status_warn
14+
15+ assert status_ok ("Done" ).startswith ("[OK] " )
16+ assert status_warn ("Heads up" ).startswith ("[WARN] " )
17+ assert status_fail ("Nope" ).startswith ("NOT OK " )
You can’t perform that action at this time.
0 commit comments