Add isort pre-commit hook, sort imports in src and test directories

This commit is contained in:
Darren Burns
2023-02-09 13:28:08 +00:00
parent 67c2127e46
commit 9287f64a66
131 changed files with 268 additions and 297 deletions

View File

@@ -20,22 +20,35 @@ def test_sparkline_two_values_min_max():
def test_sparkline_expand_data_to_width():
assert render(Sparkline([2, 4],
width=4)) == f"{GREEN}{STOP}{GREEN}{STOP}{RED}{STOP}{RED}{STOP}"
assert (
render(Sparkline([2, 4], width=4))
== f"{GREEN}{STOP}{GREEN}{STOP}{RED}{STOP}{RED}{STOP}"
)
def test_sparkline_expand_data_to_width_non_divisible():
assert render(Sparkline([2, 4], width=3)) == f"{GREEN}{STOP}{GREEN}{STOP}{RED}{STOP}"
assert (
render(Sparkline([2, 4], width=3))
== f"{GREEN}{STOP}{GREEN}{STOP}{RED}{STOP}"
)
def test_sparkline_shrink_data_to_width():
assert render(Sparkline([2, 2, 4, 4, 6, 6], width=3)) == f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
assert (
render(Sparkline([2, 2, 4, 4, 6, 6], width=3))
== f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
)
def test_sparkline_shrink_data_to_width_non_divisible():
assert render(
Sparkline([1, 2, 3, 4, 5], width=3, summary_function=min)) == f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
assert (
render(Sparkline([1, 2, 3, 4, 5], width=3, summary_function=min))
== f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
)
def test_sparkline_color_blend():
assert render(Sparkline([1, 2, 3], width=3)) == f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
assert (
render(Sparkline([1, 2, 3], width=3))
== f"{GREEN}{STOP}{BLENDED}{STOP}{RED}{STOP}"
)

View File

@@ -14,7 +14,7 @@ def text():
def test_simple_text_opacity(text):
blended_red_on_green = "\x1b[38;2;127;127;0;48;2;0;255;0m"
assert render(TextOpacity(text, opacity=.5)) == (
assert render(TextOpacity(text, opacity=0.5)) == (
f"{blended_red_on_green}Hello, world!{STOP}"
)
@@ -31,19 +31,21 @@ def test_text_opacity_value_of_one_noop(text):
def test_ansi_colors_noop():
ansi_colored_text = Text("Hello, world!", style="red on green", end="")
assert render(TextOpacity(ansi_colored_text, opacity=.5)) == render(ansi_colored_text)
assert render(TextOpacity(ansi_colored_text, opacity=0.5)) == render(
ansi_colored_text
)
def test_text_opacity_no_style_noop():
text_no_style = Text("Hello, world!", end="")
assert render(TextOpacity(text_no_style, opacity=.2)) == render(text_no_style)
assert render(TextOpacity(text_no_style, opacity=0.2)) == render(text_no_style)
def test_text_opacity_only_fg_noop():
text_only_fg = Text("Hello, world!", style="#ff0000", end="")
assert render(TextOpacity(text_only_fg, opacity=.5)) == render(text_only_fg)
assert render(TextOpacity(text_only_fg, opacity=0.5)) == render(text_only_fg)
def test_text_opacity_only_bg_noop():
text_only_bg = Text("Hello, world!", style="on #ff0000", end="")
assert render(TextOpacity(text_only_bg, opacity=.5)) == render(text_only_bg)
assert render(TextOpacity(text_only_bg, opacity=0.5)) == render(text_only_bg)

View File

@@ -1,7 +1,6 @@
from unittest.mock import create_autospec
from rich.console import Console
from rich.console import ConsoleOptions
from rich.console import Console, ConsoleOptions
from rich.text import Text
from tests.utilities.render import render
@@ -21,16 +20,12 @@ def test_no_highlight():
def test_highlight_from_zero():
bar = UnderlineBar(highlight_range=(0, 2.5), width=6)
assert render(bar) == (
f"{MAGENTA}━━{STOP}{MAGENTA}{STOP}{GREY}━━━{STOP}"
)
assert render(bar) == (f"{MAGENTA}━━{STOP}{MAGENTA}{STOP}{GREY}━━━{STOP}")
def test_highlight_from_zero_point_five():
bar = UnderlineBar(highlight_range=(0.5, 2), width=6)
assert render(bar) == (
f"{MAGENTA}╺━{STOP}{GREY}{STOP}{GREY}━━━{STOP}"
)
assert render(bar) == (f"{MAGENTA}╺━{STOP}{GREY}{STOP}{GREY}━━━{STOP}")
def test_highlight_middle():
@@ -47,10 +42,7 @@ def test_highlight_middle():
def test_highlight_half_start():
bar = UnderlineBar(highlight_range=(2.5, 4), width=6)
assert render(bar) == (
f"{GREY}━━{STOP}"
f"{MAGENTA}╺━{STOP}"
f"{GREY}{STOP}"
f"{GREY}{STOP}"
f"{GREY}━━{STOP}" f"{MAGENTA}╺━{STOP}" f"{GREY}{STOP}" f"{GREY}{STOP}"
)
@@ -68,42 +60,30 @@ def test_highlight_half_end():
def test_highlight_half_start_and_half_end():
bar = UnderlineBar(highlight_range=(2.5, 4.5), width=6)
assert render(bar) == (
f"{GREY}━━{STOP}"
f"{MAGENTA}╺━{STOP}"
f"{MAGENTA}{STOP}"
f"{GREY}{STOP}"
f"{GREY}━━{STOP}" f"{MAGENTA}╺━{STOP}" f"{MAGENTA}{STOP}" f"{GREY}{STOP}"
)
def test_highlight_to_near_end():
bar = UnderlineBar(highlight_range=(3, 5.5), width=6)
assert render(bar) == (
f"{GREY}━━{STOP}"
f"{GREY}{STOP}"
f"{MAGENTA}━━{STOP}"
f"{MAGENTA}{STOP}"
f"{GREY}━━{STOP}" f"{GREY}{STOP}" f"{MAGENTA}━━{STOP}" f"{MAGENTA}{STOP}"
)
def test_highlight_to_end():
bar = UnderlineBar(highlight_range=(3, 6), width=6)
assert render(bar) == (
f"{GREY}━━{STOP}{GREY}{STOP}{MAGENTA}━━━{STOP}"
)
assert render(bar) == (f"{GREY}━━{STOP}{GREY}{STOP}{MAGENTA}━━━{STOP}")
def test_highlight_out_of_bounds_start():
bar = UnderlineBar(highlight_range=(-2, 3), width=6)
assert render(bar) == (
f"{MAGENTA}━━━{STOP}{GREY}{STOP}{GREY}━━{STOP}"
)
assert render(bar) == (f"{MAGENTA}━━━{STOP}{GREY}{STOP}{GREY}━━{STOP}")
def test_highlight_out_of_bounds_end():
bar = UnderlineBar(highlight_range=(3, 9), width=6)
assert render(bar) == (
f"{GREY}━━{STOP}{GREY}{STOP}{MAGENTA}━━━{STOP}"
)
assert render(bar) == (f"{GREY}━━{STOP}{GREY}{STOP}{MAGENTA}━━━{STOP}")
def test_highlight_full_range_out_of_bounds_end():
@@ -117,7 +97,9 @@ def test_highlight_full_range_out_of_bounds_start():
def test_custom_styles():
bar = UnderlineBar(highlight_range=(2, 4), highlight_style="red", background_style="green", width=6)
bar = UnderlineBar(
highlight_range=(2, 4), highlight_style="red", background_style="green", width=6
)
assert render(bar) == (
f"{GREEN}{STOP}"
f"{GREEN}{STOP}"
@@ -128,7 +110,9 @@ def test_custom_styles():
def test_clickable_ranges():
bar = UnderlineBar(highlight_range=(0, 1), width=6, clickable_ranges={"foo": (0, 2), "bar": (4, 5)})
bar = UnderlineBar(
highlight_range=(0, 1), width=6, clickable_ranges={"foo": (0, 2), "bar": (4, 5)}
)
console = create_autospec(Console)
options = create_autospec(ConsoleOptions)
@@ -136,8 +120,8 @@ def test_clickable_ranges():
start, end, style = text.spans[-2]
assert (start, end) == (0, 2)
assert style.meta == {'@click': "range_clicked('foo')"}
assert style.meta == {"@click": "range_clicked('foo')"}
start, end, style = text.spans[-1]
assert (start, end) == (4, 5)
assert style.meta == {'@click': "range_clicked('bar')"}
assert style.meta == {"@click": "range_clicked('bar')"}