Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 5, 2021
1 parent 8105943 commit 8411f00
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 60 deletions.
95 changes: 36 additions & 59 deletions rich/segment.py
Expand Up @@ -154,7 +154,7 @@ def apply_style(
apply = style.__add__
result_segments = (
cls(text, None if control else apply(_style), control)
for text, _style, control in segments
for text, _style, control in result_segments
)
if post_style:
result_segments = (
Expand All @@ -167,7 +167,7 @@ def apply_style(
),
control,
)
for text, _style, control in segments
for text, _style, control in result_segments
)
return result_segments

Expand Down Expand Up @@ -567,60 +567,37 @@ def __rich_console__(

if __name__ == "__main__":

from rich import print

print(Segment("foo").split_cells(0))
print(Segment("foo").split_cells(1))
print(Segment("foo").split_cells(2))
print(Segment("foo").split_cells(3))
print(Segment("foo").split_cells(4))

print()
print(Segment("💩").split_cells(0))
print(Segment("💩").split_cells(1))
print(Segment("💩").split_cells(2))

print()
print(Segment("💩💩").split_cells(0))
print(Segment("💩💩").split_cells(1))
print(Segment("💩💩").split_cells(2))
print(Segment("💩💩").split_cells(3))
print(Segment("💩💩").split_cells(4))

segment = Segment("💩X" * 10)

for n in range(30):
print(segment.split_cells(n))

# if __name__ == "__main__": # pragma: no cover
# from rich.syntax import Syntax
# from rich.text import Text
# from rich.console import Console

# code = """from rich.console import Console
# console = Console()
# text = Text.from_markup("Hello, [bold magenta]World[/]!")
# console.print(text)"""

# text = Text.from_markup("Hello, [bold magenta]World[/]!")

# console = Console()

# console.rule("rich.Segment")
# console.print(
# "A Segment is the last step in the Rich render process before generating text with ANSI codes."
# )
# console.print("\nConsider the following code:\n")
# console.print(Syntax(code, "python", line_numbers=True))
# console.print()
# console.print(
# "When you call [b]print()[/b], Rich [i]renders[/i] the object in to the the following:\n"
# )
# fragments = list(console.render(text))
# console.print(fragments)
# console.print()
# console.print("The Segments are then processed to produce the following output:\n")
# console.print(text)
# console.print(
# "\nYou will only need to know this if you are implementing your own Rich renderables."
# )
if __name__ == "__main__": # pragma: no cover
from rich.syntax import Syntax
from rich.text import Text
from rich.console import Console

code = """from rich.console import Console
console = Console()
text = Text.from_markup("Hello, [bold magenta]World[/]!")
console.print(text)"""

text = Text.from_markup("Hello, [bold magenta]World[/]!")

console = Console()

console.rule("rich.Segment")
console.print(
"A Segment is the last step in the Rich render process before generating text with ANSI codes."
)
console.print("\nConsider the following code:\n")
console.print(Syntax(code, "python", line_numbers=True))
console.print()
console.print(
"When you call [b]print()[/b], Rich [i]renders[/i] the object in to the the following:\n"
)
fragments = list(console.render(text))
console.print(fragments)
console.print()
console.print(
"The Segments are then processed to produce the following output:\n"
)
console.print(text)
console.print(
"\nYou will only need to know this if you are implementing your own Rich renderables."
)
20 changes: 19 additions & 1 deletion tests/test_tree.py
Expand Up @@ -59,7 +59,7 @@ def encoding(self):


@pytest.mark.skipif(sys.platform == "win32", reason="different on Windows")
def test_render():
def test_render_tree_non_win32():
tree = Tree("foo")
tree.add("bar", style="italic")
baz_tree = tree.add("baz", guide_style="bold red", style="on blue")
Expand All @@ -76,6 +76,24 @@ def test_render():
assert result == expected


@pytest.mark.skipif(sys.platform != "win32", reason="Windows specific")
def test_render_tree_win32():
tree = Tree("foo")
tree.add("bar", style="italic")
baz_tree = tree.add("baz", guide_style="bold red", style="on blue")
baz_tree.add("1")
baz_tree.add("2")
tree.add("egg")

console = Console(width=20, force_terminal=True, color_system="standard")
console.begin_capture()
console.print(tree)
result = console.end_capture()
print(repr(result))
expected = "foo \n├── \x1b[3mbar\x1b[0m\x1b[3m \x1b[0m\n\x1b[44m├── \x1b[0m\x1b[44mbaz\x1b[0m\x1b[44m \x1b[0m\n\x1b[44m│ \x1b[0m\x1b[31;44m├── \x1b[0m\x1b[44m1\x1b[0m\x1b[44m \x1b[0m\n\x1b[44m│ \x1b[0m\x1b[31;44m└── \x1b[0m\x1b[44m2\x1b[0m\x1b[44m \x1b[0m\n└── egg \n"
assert result == expected


def test_tree_measure():
tree = Tree("foo")
tree.add("bar")
Expand Down

0 comments on commit 8411f00

Please sign in to comment.