@@ -106,7 +106,7 @@ def test_simple_console_exporter_no_colors_verbose(simple_spans: list[ReadableSp
106106 [
107107 '00:00:01.000 rootSpan' ,
108108 '00:00:02.000 childSpan 1' ,
109- ' │ testing.py:42 ' ,
109+ ' │ testing.py:42' ,
110110 ]
111111 )
112112
@@ -419,7 +419,7 @@ def test_verbose_attributes(exporter: TestExporter) -> None:
419419 assert out .getvalue ().splitlines () == snapshot (
420420 [
421421 '\x1b [32m00:00:01.000\x1b [0m Hello world!' ,
422- ' \x1b [34m│\x1b [0m \x1b [36mtest_console_exporter .py:123\x1b [0m info' ,
422+ ' \x1b [34m│\x1b [0m\x1b [36m test_console_exporter .py:123\x1b [0m info' ,
423423 " \x1b [34m│ \x1b [0m\x1b [34mname=\x1b [0m\x1b [93;49m'\x1b [0m\x1b [93;49mworld\x1b [0m\x1b [93;49m'\x1b [0m" ,
424424 ' \x1b [34m│ \x1b [0m\x1b [34md=\x1b [0m\x1b [97;49m{\x1b [0m ' ,
425425 " \x1b [34m│ \x1b [0m \x1b [97;49m \x1b [0m\x1b [93;49m'\x1b [0m\x1b [93;49ma\x1b [0m\x1b [93;49m'\x1b [0m\x1b [97;49m:\x1b [0m\x1b [97;49m \x1b [0m\x1b [37;49m1\x1b [0m\x1b [97;49m,\x1b [0m" ,
@@ -796,3 +796,39 @@ def test_exception(exporter: TestExporter) -> None:
796796 '\x1b [0m\x1b [97;49mby\x1b [0m\x1b [97;49m \x1b [0m\x1b [97;49mzero\x1b [0m' ,
797797 '' ,
798798 ]
799+
800+
801+ def test_console_exporter_invalid_text (capsys : pytest .CaptureFixture [str ]) -> None :
802+ logfire .configure (
803+ send_to_logfire = False ,
804+ console = ConsoleOptions (colors = 'always' , include_timestamps = False , verbose = True ),
805+ )
806+
807+ logfire .info ('hi' , ** {'code.filepath' : 3 , 'code.lineno' : None }) # type: ignore
808+ logfire .info ('hi' , ** {'code.filepath' : None , 'code.lineno' : 'foo' }) # type: ignore
809+ assert capsys .readouterr ().out .splitlines () == snapshot (
810+ [
811+ 'hi' ,
812+ '\x1b [34m│\x1b [0m\x1b [36m 3\x1b [0m info' ,
813+ 'hi' ,
814+ '\x1b [34m│\x1b [0m info' ,
815+ ]
816+ )
817+
818+
819+ def test_console_exporter_invalid_text_no_color (capsys : pytest .CaptureFixture [str ]) -> None :
820+ logfire .configure (
821+ send_to_logfire = False ,
822+ console = ConsoleOptions (colors = 'never' , include_timestamps = False , verbose = True ),
823+ )
824+
825+ logfire .info ('hi' , ** {'code.filepath' : 3 , 'code.lineno' : None }) # type: ignore
826+ logfire .info ('hi' , ** {'code.filepath' : None , 'code.lineno' : 'foo' }) # type: ignore
827+ assert capsys .readouterr ().out .splitlines () == snapshot (
828+ [
829+ 'hi' ,
830+ '│ 3 info' ,
831+ 'hi' ,
832+ '│ info' ,
833+ ]
834+ )
0 commit comments