add tests for style

This commit is contained in:
Will McGugan 2020-10-10 18:16:09 +01:00
parent a236d8fd63
commit 4310bc8ae8
2 changed files with 23 additions and 1 deletions

View File

@ -17,9 +17,11 @@ class Pager(ABC):
class SystemPager(Pager):
"""Uses the pager installed on the system."""
_pager = pydoc.pager
def show(self, content: str) -> None:
"""Use the same pager used by pydoc."""
pydoc.pager(content)
self._pager(content)
if __name__ == "__main__": # pragma: no cover

View File

@ -2,12 +2,14 @@ import io
import os
import sys
import tempfile
from threading import setprofile
import pytest
from rich.color import ColorSystem
from rich.console import CaptureError, Console, ConsoleOptions
from rich import errors
from rich.pager import SystemPager
from rich.panel import Panel
from rich.style import Style
@ -346,3 +348,21 @@ def test_bell() -> None:
console.begin_capture()
console.bell()
assert console.end_capture() == "\x07"
def test_pager() -> None:
console = Console()
pager_called = False
def mock_pager(content: str) -> None:
nonlocal pager_called
pager_called = True
pager = SystemPager()
pager._pager = dummy_pager
with console.pager(pager):
console.print("Hello World")
assert pager_called