From 136e07bffb55657de88e31476c800457fec5fc27 Mon Sep 17 00:00:00 2001 From: phase06 Date: Mon, 5 Oct 2020 18:19:41 +0800 Subject: [PATCH] update and add test to increase coverage --- tests/test_syntax.py | 54 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 6d314f00..7c79c16b 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -8,7 +8,14 @@ from .render import render from rich.panel import Panel from rich.style import Style -from rich.syntax import Syntax, ANSISyntaxTheme, PygmentsSyntaxTheme +from rich.syntax import ( + Syntax, + ANSISyntaxTheme, + PygmentsSyntaxTheme, + Color, + Console, + ConsoleOptions, +) CODE = ''' @@ -46,20 +53,11 @@ def test_python_render(): assert rendered_syntax == expected -def test_get_theme(): - syntax = Syntax( - CODE, - lexer_name="python", - line_numbers=True, - line_range=(2, 10), - theme="foo", - code_width=60, - word_wrap=True, - ) +def test_pygments_syntax_theme_non_str(): from pygments.style import Style as PygmentsStyle - style = PygmentsStyle() - assert syntax.get_theme(style).get_background_style().bgcolor.name == "#ffffff" + style = PygmentsSyntaxTheme(PygmentsStyle()) + assert style.get_background_style().bgcolor == Color.parse("#ffffff") def test_pygments_syntax_theme(): @@ -67,6 +65,23 @@ def test_pygments_syntax_theme(): assert style.get_style_for_token("abc") == Style.parse("none") +def test_get_line_color_none(): + style = PygmentsSyntaxTheme("default") + style._background_style = Style(bgcolor=None) + syntax = Syntax( + CODE, + lexer_name="python", + line_numbers=True, + line_range=(2, 10), + theme=style, + code_width=60, + word_wrap=True, + background_color="red", + ) + + assert syntax._get_line_numbers_color() == Color.default() + + def test_highlight_background_color(): syntax = Syntax( CODE, @@ -78,8 +93,17 @@ def test_highlight_background_color(): word_wrap=True, background_color="red", ) - text = syntax.highlight(CODE) - assert syntax.highlight(CODE) == text + assert syntax.highlight(CODE).style == Style.parse("on red") + + +def test_get_number_styles(): + syntax = Syntax(CODE, "python", theme="monokai", line_numbers=True) + console = Console(color_system="windows") + assert syntax._get_number_styles(console=console) == ( + Style.parse("on #272822"), + Style.parse("dim on #272822"), + Style.parse("not dim on #272822"), + ) def test_ansi_theme():