Skip to content

Commit 33b585f

Browse files
committed
Enhance test environment configuration and CLI tests for consistent color output
Update the GitHub Actions workflow to set environment variables for color output during test execution. Modify CLI test cases to ensure consistent terminal color settings by passing the FORCE_COLOR and TERM variables to the CliRunner. Adjust snapshot files to reflect the updated color formatting in CLI help and error messages.
1 parent 000cd24 commit 33b585f

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626

2727
- name: Run tests
2828
run: uv run pytest
29+
env:
30+
FORCE_COLOR: 1
31+
TERM: xterm-256color
2932

3033
- name: Run linting
3134
run: |

tests/__snapshots__/test_md2term.ambr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# name: TestCLIInterface.test_cli_help
33
'''
44

5-
Usage: main [OPTIONS] [INPUT_FILE]
5+
Usage: main [OPTIONS] [INPUT_FILE]
66

77
Parse Markdown and turn it into nicely-formatted text for terminal display.
88
If no INPUT_FILE is provided, reads from stdin.
@@ -17,17 +17,17 @@
1717
Examples:
1818
md2term README.md # Render a markdown file
1919
echo "# Hello" | md2term # Render from stdin
20-
cat file.md | pv -qL 20 | md2term # Simulate streaming input
21-
md2term --width 60 README.md # Set custom width
20+
cat file.md | pv -qL 20 | md2term # Simulate streaming input
21+
md2term --width 60 README.md # Set custom width
2222

2323
The renderer automatically handles both complete files and streaming input,
2424
with intelligent backtracking when markdown syntax is incomplete.
2525

26-
╭─ Options ────────────────────────────────────────────────────────────────────╮
27-
--width -w INTEGER Override terminal width
28-
--version Show the version and exit.
29-
--help Show this message and exit.
30-
╰──────────────────────────────────────────────────────────────────────────────╯
26+
╭─ Options ────────────────────────────────────────────────────────────────────╮
27+
│ --width -w INTEGER Override terminal width │
28+
│ --version   Show the version and exit. │
29+
│ --help   Show this message and exit. │
30+
╰──────────────────────────────────────────────────────────────────────────────╯
3131

3232

3333
'''
@@ -76,13 +76,13 @@
7676
# name: TestEdgeCases.test_cli_nonexistent_file
7777
'''
7878

79-
Usage: main [OPTIONS] [INPUT_FILE]
79+
Usage: main [OPTIONS] [INPUT_FILE]
8080

81-
Try 'main --help' for help
82-
╭─ Error ──────────────────────────────────────────────────────────────────────╮
83-
Invalid value for '[INPUT_FILE]': 'nonexistent.md': No such file or
84-
directory
85-
╰──────────────────────────────────────────────────────────────────────────────╯
81+
 Try 'main --help' for help  
82+
╭─ Error ──────────────────────────────────────────────────────────────────────╮
83+
│ Invalid value for '[INPUT_FILE]': 'nonexistent.md': No such file or │
84+
│ directory │
85+
╰──────────────────────────────────────────────────────────────────────────────╯
8686

8787

8888
'''

tests/test_md2term.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
def create_test_console(output, width=80):
1717
"""Create a console with consistent settings for testing."""
18-
return Console(file=output, width=width, force_terminal=True, color_system="standard")
18+
return Console(file=output, width=width, force_terminal=True, color_system="256")
1919

2020

2121
class TestMarkdownFeatures:
@@ -282,7 +282,7 @@ class TestCLIInterface:
282282

283283
def test_cli_with_file_input(self, snapshot):
284284
"""Test CLI with file input."""
285-
runner = CliRunner()
285+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
286286
with runner.isolated_filesystem():
287287
# Create a test markdown file
288288
with open("test.md", "w") as f:
@@ -294,7 +294,7 @@ def test_cli_with_file_input(self, snapshot):
294294

295295
def test_cli_with_stdin(self, snapshot):
296296
"""Test CLI with stdin input."""
297-
runner = CliRunner()
297+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
298298
markdown_input = "# Test Header\n\nThis is a **test** paragraph with `code`."
299299

300300
result = runner.invoke(main, input=markdown_input)
@@ -303,7 +303,7 @@ def test_cli_with_stdin(self, snapshot):
303303

304304
def test_cli_with_width_option(self, snapshot):
305305
"""Test CLI with custom width option."""
306-
runner = CliRunner()
306+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
307307
markdown_input = "# Test Header\n\nThis is a very long paragraph that should wrap differently when the terminal width is changed to a smaller value."
308308

309309
result = runner.invoke(main, ["--width", "40"], input=markdown_input)
@@ -312,14 +312,14 @@ def test_cli_with_width_option(self, snapshot):
312312

313313
def test_cli_version(self, snapshot):
314314
"""Test CLI version option."""
315-
runner = CliRunner()
315+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
316316
result = runner.invoke(main, ["--version"])
317317
assert result.exit_code == 0
318318
assert result.output == snapshot
319319

320320
def test_cli_help(self, snapshot):
321321
"""Test CLI help option."""
322-
runner = CliRunner()
322+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
323323
result = runner.invoke(main, ["--help"])
324324
assert result.exit_code == 0
325325
assert result.output == snapshot
@@ -411,7 +411,7 @@ def test_very_narrow_width(self, snapshot):
411411

412412
def test_cli_nonexistent_file(self, snapshot):
413413
"""Test CLI with nonexistent file."""
414-
runner = CliRunner()
414+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
415415
result = runner.invoke(main, ["nonexistent.md"])
416416
assert result.exit_code != 0
417417
assert result.output == snapshot
@@ -463,7 +463,7 @@ def test_convert_basic():
463463

464464
def test_cli_basic():
465465
"""Test basic CLI functionality (legacy test)."""
466-
runner = CliRunner()
466+
runner = CliRunner(env={"FORCE_COLOR": "1", "TERM": "xterm-256color"})
467467
result = runner.invoke(main, input="# Test\n\nHello world!")
468468
# Note: CLI may have exit code 1 due to streaming processing, but output should be correct
469469
assert "Test" in result.output

0 commit comments

Comments
 (0)