test fixes

This commit is contained in:
Will McGugan 2020-08-25 17:17:46 +01:00
parent f0ab3f4fff
commit 9fefcc7830
3 changed files with 13 additions and 10 deletions

View File

@ -586,7 +586,7 @@ class Console:
_options = options or self.options
render_iterable: RenderResult
if hasattr(renderable, "__rich__"):
if isinstance(renderable, RichCast):
renderable = renderable.__rich__()
if isinstance(renderable, ConsoleRenderable):
render_iterable = renderable.__rich_console__(self, _options)
@ -1085,7 +1085,7 @@ class Console:
"""Generate text from console contents (requires record=True argument in constructor).
Args:
clear (bool, optional): Clear record buffer after exportint. Defaults to ``True``.
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
styles (bool, optional): If ``True``, ansi escape codes will be included. ``False`` for plain text.
Defaults to ``False``.
@ -1118,7 +1118,7 @@ class Console:
Args:
path (str): Path to write text files.
clear (bool, optional): Clear record buffer after exportint. Defaults to ``True``.
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
styles (bool, optional): If ``True``, ansi style codes will be included. ``False`` for plain text.
Defaults to ``False``.
@ -1139,7 +1139,7 @@ class Console:
Args:
theme (TerminalTheme, optional): TerminalTheme object containing console colors.
clear (bool, optional): Clear record buffer after exportint. Defaults to ``True``.
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
code_format (str, optional): Format string to render HTML, should contain {foreground}
{background} and {code}.
inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
@ -1220,7 +1220,7 @@ class Console:
Args:
path (str): Path to write html file.
theme (TerminalTheme, optional): TerminalTheme object containing console colors.
clear (bool, optional): Clear record buffer after exportint. Defaults to ``True``.
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
code_format (str, optional): Format string to render HTML, should contain {foreground}
{background} and {code}.
inline_styes (bool, optional): If ``True`` styles will be inlined in to spans, which makes files

View File

@ -61,12 +61,13 @@ class Measurement(NamedTuple):
Returns:
Measurement: Measurement object containing range of character widths required to render the object.
"""
from rich.console import RichCast
_max_width = console.width if max_width is None else max_width
if isinstance(renderable, str):
renderable = console.render_str(renderable)
if hasattr(renderable, "__rich__"):
if isinstance(renderable, RichCast):
renderable = renderable.__rich__()
if is_renderable(renderable):

View File

@ -86,7 +86,7 @@ class Pretty:
*,
indent_size: int = 4,
justify: "JustifyMethod" = None,
overflow: "OverflowMethod" = "crop",
overflow: Optional["OverflowMethod"] = "crop",
no_wrap: Optional[bool] = False,
) -> None:
self._object = _object
@ -222,11 +222,13 @@ class _Line:
start_length = (
len(self.whitespace) + cell_len(self.text) + cell_len(self.suffix)
)
assert self.node is not None
return self.node.check_length(start_length, max_length)
def expand(self, indent_size: int) -> Iterable["_Line"]:
"""Expand this line by adding children on their own line."""
node = self.node
assert node is not None
whitespace = self.whitespace
assert node.children
if node.key_repr:
@ -236,7 +238,7 @@ class _Line:
else:
yield _Line(text=node.open_brace, whitespace=whitespace)
child_whitespace = self.whitespace + " " * indent_size
for child in self.node.children:
for child in node.children:
line = _Line(
node=child,
whitespace=child_whitespace,
@ -293,13 +295,13 @@ def pretty_repr(
open_brace, close_brace, empty = _BRACES[type(obj)](obj)
if obj:
children: List[_Node] = []
node = _Node(
open_brace=open_brace,
close_brace=close_brace,
children=[],
children=children,
last=root,
)
children = node.children
append = children.append
if isinstance(obj, dict):
for last, (key, child) in loop_last(obj.items()):