Skip to content

Commit

Permalink
Ensuring legacy Windows tests only run on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Mar 1, 2022
1 parent 04e67f0 commit 18614b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions rich/_win32_console.py
Expand Up @@ -10,6 +10,7 @@
else:
raise ImportError(f"{__name__} can only be imported on Windows")
except:
windll = None
raise
else:
import time
Expand Down
8 changes: 4 additions & 4 deletions rich/_windows_renderer.py
@@ -1,4 +1,4 @@
from typing import Iterable, Sequence, cast
from typing import Iterable, Sequence, Tuple, cast

from rich._win32_console import LegacyWindowsTerm, WindowsCoordinates
from rich.segment import ControlCode, ControlType, Segment
Expand All @@ -18,7 +18,7 @@ def legacy_windows_render(buffer: Iterable[Segment], term: LegacyWindowsTerm) ->
for control_code in control_codes:
control_type = control_code[0]
if control_type == ControlType.CURSOR_MOVE_TO:
_, x, y = cast(tuple[ControlType, int, int], control_code)
_, x, y = cast(Tuple[ControlType, int, int], control_code)
term.move_cursor_to(WindowsCoordinates(row=y - 1, col=x - 1))
elif control_type == ControlType.CARRIAGE_RETURN:
term.write_text("\r")
Expand All @@ -33,14 +33,14 @@ def legacy_windows_render(buffer: Iterable[Segment], term: LegacyWindowsTerm) ->
elif control_type == ControlType.CURSOR_BACKWARD:
term.move_cursor_backward()
elif control_type == ControlType.CURSOR_MOVE_TO_COLUMN:
_, column = cast(tuple[ControlType, int], control_code)
_, column = cast(Tuple[ControlType, int], control_code)
term.move_cursor_to_column(column - 1)
elif control_type == ControlType.HIDE_CURSOR:
term.hide_cursor()
elif control_type == ControlType.SHOW_CURSOR:
term.show_cursor()
elif control_type == ControlType.ERASE_IN_LINE:
_, mode = cast(tuple[ControlType, int], control_code)
_, mode = cast(Tuple[ControlType, int], control_code)
if mode == 0:
term.erase_end_of_line()
elif mode == 1:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_windows_renderer.py
@@ -1,12 +1,18 @@
import sys
from unittest.mock import call, create_autospec

import pytest

from rich._win32_console import LegacyWindowsTerm, WindowsCoordinates
from rich._windows_renderer import legacy_windows_render
try:
from rich._win32_console import LegacyWindowsTerm, WindowsCoordinates
from rich._windows_renderer import legacy_windows_render
except:
pass
from rich.segment import ControlType, Segment
from rich.style import Style

pytestmark = pytest.mark.skipif(sys.platform != "win32", reason="windows only")


@pytest.fixture
def legacy_term_mock():
Expand Down

0 comments on commit 18614b5

Please sign in to comment.