77
88import pytest
99
10+ from cmd2 import rich_utils as ru
1011from cmd2 .string_utils import quote
1112
1213from .conftest import (
1314 odd_file_names ,
1415 run_cmd ,
16+ with_ansi_style ,
1517)
1618
1719
@@ -209,17 +211,19 @@ def test_run_pyscript_app_echo(base_app, request) -> None:
209211 assert out [0 ] == "Usage: edit [-h] [file_path]"
210212
211213
214+ @with_ansi_style (ru .AllowStyle .ALWAYS )
212215def test_run_pyscript_print (base_app , request , capsys ) -> None :
213216 """Verify that py_print() (the print() replacement in pyscripts) works correctly."""
214217 test_dir = os .path .dirname (request .module .__file__ )
215218 python_script = os .path .join (test_dir , "pyscript" , "test_print.py" )
216219 out , err = run_cmd (base_app , f"run_pyscript { python_script } " )
217220
218221 # Verify contents of self.stdout
219- assert len (out ) == 3
222+ assert len (out ) == 4
220223 assert out [0 ] == "hello-world"
221224 assert out [1 ] == "no newline here"
222225 assert out [2 ] == "1:2:3."
226+ assert out [3 ] == "\x1b [34mI am Rich Text\x1b [0m"
223227
224228 # Verify contents of sys.stderr
225229 assert len (err ) == 1
@@ -245,9 +249,11 @@ def test_run_pyscript_print_redirection(base_app, request, tmp_path, capsys) ->
245249 content = f .read ()
246250
247251 # Look for everything written to self.stdout
252+ assert len (content .splitlines ()) == 4
248253 assert "hello-world\n " in content
249254 assert "no newline here\n " in content
250255 assert "1:2:3.\n " in content
256+ assert "I am Rich Text\n " in content
251257
252258 # Nothing else should have been redirected
253259 assert "this goes to sys.stdout" not in content
0 commit comments