@@ -21,79 +21,6 @@ def _run(script_path: str, args: list[str]) -> subprocess.CompletedProcess:
2121 )
2222
2323
24- # ---------------------------------------------------------------------------
25- # examples/hello_cli.py
26- # ---------------------------------------------------------------------------
27-
28-
29- class TestHelloCli (unittest .TestCase ):
30- """examples/hello_cli.py — minimal single-command CLI."""
31-
32- SCRIPT = "examples/hello_cli.py"
33-
34- def test_greet_with_name (self ):
35- """uv run python examples/hello_cli.py greet Alice"""
36- r = _run (self .SCRIPT , ["greet" , "Alice" ])
37- self .assertEqual (r .returncode , 0 )
38- self .assertEqual (r .stdout .strip (), "Hello, Alice!" )
39-
40- def test_greet_default (self ):
41- """uv run python examples/hello_cli.py greet"""
42- r = _run (self .SCRIPT , ["greet" ])
43- self .assertEqual (r .returncode , 0 )
44- self .assertEqual (r .stdout .strip (), "Hello, World!" )
45-
46- def test_greet_help (self ):
47- """uv run python examples/hello_cli.py greet --help"""
48- r = _run (self .SCRIPT , ["greet" , "--help" ])
49- self .assertEqual (r .returncode , 0 )
50- self .assertIn ("Say hello" , r .stdout )
51- self .assertIn ("Name to greet" , r .stdout )
52-
53-
54- # ---------------------------------------------------------------------------
55- # examples/calculator.py
56- # ---------------------------------------------------------------------------
57-
58-
59- class TestCalculator (unittest .TestCase ):
60- """examples/calculator.py — multi-command calculator."""
61-
62- SCRIPT = "examples/calculator.py"
63-
64- def test_add (self ):
65- """uv run python examples/calculator.py add 10 20"""
66- r = _run (self .SCRIPT , ["add" , "10" , "20" ])
67- self .assertEqual (r .returncode , 0 )
68- self .assertIn ("10 + 20 = 30" , r .stdout )
69-
70- def test_multiply (self ):
71- """uv run python examples/calculator.py multiply 2.5 4.0"""
72- r = _run (self .SCRIPT , ["multiply" , "2.5" , "4.0" ])
73- self .assertEqual (r .returncode , 0 )
74- self .assertIn ("2.5 * 4.0 = 10.0" , r .stdout )
75-
76- def test_divide (self ):
77- """uv run python examples/calculator.py divide 100 3"""
78- r = _run (self .SCRIPT , ["divide" , "100" , "3" ])
79- self .assertEqual (r .returncode , 0 )
80- self .assertIn ("100.0 / 3.0 =" , r .stdout )
81-
82- def test_divide_by_zero (self ):
83- """division by zero should print an error, not crash"""
84- r = _run (self .SCRIPT , ["divide" , "1" , "0" ])
85- self .assertEqual (r .returncode , 0 )
86- self .assertIn ("division by zero" , r .stdout )
87-
88- def test_help (self ):
89- """uv run python examples/calculator.py --help"""
90- r = _run (self .SCRIPT , ["--help" ])
91- self .assertEqual (r .returncode , 0 )
92- self .assertIn ("add" , r .stdout )
93- self .assertIn ("multiply" , r .stdout )
94- self .assertIn ("divide" , r .stdout )
95-
96-
9724# ---------------------------------------------------------------------------
9825# examples/server_cli.py
9926# ---------------------------------------------------------------------------
@@ -146,126 +73,6 @@ def test_help(self):
14673 self .assertIn ("--verbose" , r .stdout )
14774
14875
149- # ---------------------------------------------------------------------------
150- # examples/deploy_tool.py
151- # ---------------------------------------------------------------------------
152-
153-
154- class TestDeployTool (unittest .TestCase ):
155- """examples/deploy_tool.py — real-world-ish deploy CLI with styled output."""
156-
157- SCRIPT = "examples/deploy_tool.py"
158-
159- def test_push_staging (self ):
160- """uv run python examples/deploy_tool.py push staging"""
161- r = _run (self .SCRIPT , ["push" , "staging" ])
162- self .assertEqual (r .returncode , 0 )
163- self .assertIn ("Deploying" , r .stdout )
164- self .assertIn ("staging" , r .stdout )
165- self .assertIn ("Deployed" , r .stdout )
166-
167- def test_push_dry_run (self ):
168- """deploy_tool.py push production --tag v1.2.3 --dry-run"""
169- r = _run (self .SCRIPT , ["push" , "production" , "--tag" , "v1.2.3" , "--dry-run" ])
170- self .assertEqual (r .returncode , 0 )
171- self .assertIn ("DRY RUN" , r .stdout )
172- self .assertIn ("v1.2.3" , r .stdout )
173- self .assertIn ("production" , r .stdout )
174- self .assertIn ("Dry run complete" , r .stdout )
175-
176- def test_rollback (self ):
177- """uv run python examples/deploy_tool.py rollback production --steps 2"""
178- r = _run (self .SCRIPT , ["rollback" , "production" , "--steps" , "2" ])
179- self .assertEqual (r .returncode , 0 )
180- self .assertIn ("Rolling back" , r .stdout )
181- self .assertIn ("production" , r .stdout )
182- self .assertIn ("2" , r .stdout )
183-
184- def test_logs (self ):
185- """uv run python examples/deploy_tool.py logs staging --lines 50 --follow"""
186- r = _run (self .SCRIPT , ["logs" , "staging" , "--lines" , "50" , "--follow" ])
187- self .assertEqual (r .returncode , 0 )
188- self .assertIn ("Fetching" , r .stdout )
189- self .assertIn ("staging" , r .stdout )
190- self .assertIn ("streaming" , r .stdout )
191-
192- def test_logs_static (self ):
193- """logs without --follow should be static"""
194- r = _run (self .SCRIPT , ["logs" , "staging" ])
195- self .assertEqual (r .returncode , 0 )
196- self .assertIn ("static" , r .stdout )
197-
198- def test_help (self ):
199- """uv run python examples/deploy_tool.py --help"""
200- r = _run (self .SCRIPT , ["--help" ])
201- self .assertEqual (r .returncode , 0 )
202- self .assertIn ("push" , r .stdout )
203- self .assertIn ("rollback" , r .stdout )
204- self .assertIn ("logs" , r .stdout )
205-
206-
207- # ---------------------------------------------------------------------------
208- # examples/styled_output.py
209- # ---------------------------------------------------------------------------
210-
211-
212- class TestStyledOutput (unittest .TestCase ):
213- """examples/styled_output.py — styled text + tables demo."""
214-
215- SCRIPT = "examples/styled_output.py"
216-
217- def test_demo (self ):
218- """uv run python examples/styled_output.py demo"""
219- r = _run (self .SCRIPT , ["demo" ])
220- self .assertEqual (r .returncode , 0 , r .stderr )
221- output = r .stdout
222- # Text attributes
223- self .assertIn ("\x1b [1mBold text\x1b [0m" , output )
224- self .assertIn ("\x1b [3mItalic text\x1b [0m" , output )
225- self .assertIn ("\x1b [31mRed text\x1b [0m" , output )
226- self .assertIn ("\x1b [4mUnderlined text\x1b [0m" , output )
227- # Compound tag
228- self .assertIn ("\x1b [1m\x1b [31mBold red text\x1b [0m" , output )
229- # More attributes
230- self .assertIn ("\x1b [2mDim text\x1b [0m" , output )
231- self .assertIn ("\x1b [9mStrikethrough text\x1b [0m" , output )
232- # Compound with bg
233- self .assertIn ("\x1b [3m" , output ) # italic
234- self .assertIn ("\x1b [96m" , output ) # bright_cyan
235- self .assertIn ("\x1b [44m" , output ) # on_blue
236- # 256-color
237- self .assertIn ("\x1b [38;5;208m" , output )
238- # Hex
239- self .assertIn ("\x1b [38;2;255;128;0m" , output )
240- # RGB
241- self .assertIn ("\x1b [38;2;100;200;50m" , output )
242- # Table present
243- self .assertIn ("Feature" , output )
244- self .assertIn ("Stable" , output )
245-
246- def test_users_list (self ):
247- """uv run python examples/styled_output.py users"""
248- r = _run (self .SCRIPT , ["users" ])
249- self .assertEqual (r .returncode , 0 )
250- output = r .stdout
251- self .assertIn ("alice" , output )
252- self .assertIn ("bob" , output )
253- self .assertIn ("charlie" , output )
254- self .assertIn ("alice@example.com" , output )
255-
256- def test_users_table (self ):
257- """uv run python examples/styled_output.py users --format table"""
258- r = _run (self .SCRIPT , ["users" , "--format" , "table" ])
259- self .assertEqual (r .returncode , 0 , r .stderr )
260- output = r .stdout
261- # Table structure
262- self .assertIn ("Name" , output )
263- self .assertIn ("Email" , output )
264- self .assertIn ("Role" , output )
265- # Styled admin role
266- self .assertIn ("\x1b [31madmin\x1b [0m" , output )
267-
268-
26976# ---------------------------------------------------------------------------
27077# examples/formatted_help.py
27178# ---------------------------------------------------------------------------
@@ -317,5 +124,45 @@ def test_top_help_contains_ansi(self):
317124 self .assertIn ("\x1b [1m" , r .stdout )
318125
319126
127+ # ---------------------------------------------------------------------------
128+ # examples/combined.py
129+ # ---------------------------------------------------------------------------
130+
131+
132+ class TestCombined (unittest .TestCase ):
133+ """examples/combined.py — colors, bold, tables, and CLI in one script."""
134+
135+ SCRIPT = "examples/combined.py"
136+
137+ def test_show_defaults (self ):
138+ """combined.py show — default project and env."""
139+ r = _run (self .SCRIPT , ["show" ])
140+ self .assertEqual (r .returncode , 0 )
141+ self .assertIn ("turboterm" , r .stdout )
142+ self .assertIn ("staging" , r .stdout )
143+
144+ def test_show_custom_project (self ):
145+ """combined.py show --project myapp"""
146+ r = _run (self .SCRIPT , ["show" , "--project" , "myapp" ])
147+ self .assertEqual (r .returncode , 0 )
148+ self .assertIn ("myapp" , r .stdout )
149+
150+ def test_show_verbose (self ):
151+ """combined.py show --verbose includes full benchmark table."""
152+ r = _run (self .SCRIPT , ["show" , "--verbose" ])
153+ self .assertEqual (r .returncode , 0 )
154+ self .assertIn ("Import time" , r .stdout )
155+ self .assertIn ("Styled output" , r .stdout )
156+ self .assertIn ("Table render" , r .stdout )
157+
158+ def test_show_help (self ):
159+ """combined.py show --help"""
160+ r = _run (self .SCRIPT , ["show" , "--help" ])
161+ self .assertEqual (r .returncode , 0 )
162+ self .assertIn ("Project Overview" , r .stdout )
163+ self .assertIn ("--project" , r .stdout )
164+ self .assertIn ("--verbose" , r .stdout )
165+
166+
320167if __name__ == "__main__" :
321168 unittest .main ()
0 commit comments