Skip to content

Commit

Permalink
add tests for style
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 10, 2020
1 parent a236d8f commit 4310bc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rich/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def show(self, content: str) -> None:
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
Expand Down
20 changes: 20 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
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

Expand Down Expand Up @@ -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

0 comments on commit 4310bc8

Please sign in to comment.