clean up the tests to use a simple testing procedure

This commit is contained in:
Nathan Page 2020-11-01 11:46:55 -05:00
parent c4e9241c17
commit 58a824e775

View file

@ -1,261 +1,162 @@
# import io
# import os
# import random
# import sys
# import time
# from typing import List
# encoding=utf-8
import io
import time
from typing import Optional
# import pytest
# from rich.console import Console
# from rich.live import Live
# from rich.table import Table
# from rich.text import Text
# from tests.util import get_capture_text, set_capture_text
from rich.console import Console
from rich.live import Live
# def create_capture_console(*, width: int = 60, height: int = 80) -> Console:
# return Console(
# width=width,
# height=height,
# file=io.StringIO(),
# force_terminal=True,
# legacy_windows=False,
# color_system=None, # use no color system to reduce complexity of output
# )
def create_capture_console(
*, width: int = 60, height: int = 80, force_terminal: Optional[bool] = True
) -> Console:
return Console(
width=width,
height=height,
file=io.StringIO(),
force_terminal=force_terminal,
legacy_windows=False,
color_system=None, # use no color system to reduce complexity of output
)
# def create_base_table() -> Table:
# table = Table(title="test table", caption="table caption", expand=True)
# table.add_column("foo", footer=Text("total"), no_wrap=True, overflow="ellipsis")
# table.add_column("bar", justify="center")
# table.add_column("baz", justify="right")
def test_live_state() -> None:
# return table
with Live("") as live:
assert live._started
live.start()
assert live.renderable == ""
assert live._started
live.stop()
assert not live._started
assert not live._started
# def check_output(output_file: str, output: str) -> None:
# output = output.replace("\r", "")
# if os.getenv("CAPTURE") is not None: # adjust the correct output check
# set_capture_text("live", output_file, output=output)
# correct_output = get_capture_text("live", output_file).replace("\r", "")
# assert output == correct_output, "Console output differs from the correct output"
def test_growing_display() -> None:
console = create_capture_console()
console.begin_capture()
with Live(console=console, auto_refresh=False) as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h"
)
# def test_live_state() -> None:
# with Live("") as live:
# assert live.is_started
# live.start()
# assert live.item == ""
# assert live.is_started
# live.stop()
# assert not live.is_started
# assert not live.is_started
def test_growing_display_transient() -> None:
console = create_capture_console()
console.begin_capture()
with Live(console=console, auto_refresh=False, transient=True) as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h\r\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K"
)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table() -> None:
# """Test generating a table and adding more rows of data. No auto-refresh"""
# console = create_capture_console()
# table = create_base_table()
# with console.capture() as capture, Live(
# table, console=console, auto_refresh=False
# ) as live:
# for step in range(20):
# table.add_row(f"{step}", f"{step}", f"{step}")
# live.refresh()
# output = capture.get()
# check_output("growing_table.txt", output=output)
def test_growing_display_overflow_ellipsis() -> None:
console = create_capture_console(height=5)
console.begin_capture()
with Live(
console=console, auto_refresh=False, vertical_overflow="ellipsis"
) as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n...\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h"
)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_transient() -> None:
# """Test generating a table and adding more rows of data. Delete data at then end. No auto-refresh."""
# console = create_capture_console()
# table = create_base_table()
# with console.capture() as capture, Live(
# table, console=console, auto_refresh=False, transient=True
# ) as live:
# for step in range(20):
# table.add_row(f"{step}", f"{step}", f"{step}")
# live.refresh()
# output = capture.get()
# check_output("growing_table_transient.txt", output=output)
def test_growing_display_overflow_crop() -> None:
console = create_capture_console(height=5)
console.begin_capture()
with Live(console=console, auto_refresh=False, vertical_overflow="crop") as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h"
)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_overflow() -> None:
# """Test generating a table and adding more rows of data. No auto-refresh"""
# console = create_capture_console(height=20)
# table = create_base_table()
# with console.capture() as capture, Live(
# table, console=console, auto_refresh=False
# ) as live:
# for step in range(20):
# table.add_row(f"{step}", f"{step}", f"{step}")
# live.refresh()
# output = capture.get()
# check_output("growing_table_overflow.txt", output=output)
def test_growing_display_overflow_visible() -> None:
console = create_capture_console(height=5)
console.begin_capture()
with Live(console=console, auto_refresh=False, vertical_overflow="visible") as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h"
)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_autorefresh() -> None:
# """Test generating a table but using auto-refresh from threading"""
# console = create_capture_console()
# table = create_base_table()
def test_growing_display_autorefresh() -> None:
"""Test generating a table but using auto-refresh from threading"""
console = create_capture_console()
# with console.capture() as capture, Live(table, console=console):
# for step in range(20):
# table.add_row(f"{step}", f"{step}", f"{step}")
# time.sleep(0.2)
console = create_capture_console(height=5)
console.begin_capture()
with Live(console=console, auto_refresh=True, vertical_overflow="visible") as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display)
time.sleep(0.2)
# # no way to truly test w/ multithreading
# no way to truly test w/ multithreading, just make sure it doesn't crash
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_logging() -> None:
# """Test generating a table but also add in console logging."""
# console = create_capture_console()
# table = create_base_table()
# with console.capture() as capture, Live(table, console=console, auto_refresh=False):
# for step in range(20):
# console.print(f"Attempting Step #{step}")
# table.add_row(f"{step}", f"{step}", f"{step}")
# output = capture.get()
# check_output("growing_table_logging.txt", output=output)
def test_growing_display_console_redirect() -> None:
console = create_capture_console()
console.begin_capture()
with Live(console=console, auto_refresh=False) as live:
display = ""
for step in range(10):
console.print(f"Running step {step}")
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
assert (
output
== "\x1b[?25lRunning step 0\n\r\x1b[2KStep 0\n\r\x1b[2K\x1b[1A\x1b[2KRunning step 1\nStep 0\n\r\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 2\nStep 0\nStep 1\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 3\nStep 0\nStep 1\nStep 2\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 4\nStep 0\nStep 1\nStep 2\nStep 3\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 5\nStep 0\nStep 1\nStep 2\nStep 3\nStep 4\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 6\nStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 7\nStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 8\nStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KRunning step 9\nStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\r\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2K\x1b[1A\x1b[2KStep 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n\n\x1b[?25h"
)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_large() -> None:
# """Test generating a table but also add in console logging."""
# console = create_capture_console(height=1_000)
# table = create_base_table()
# with console.capture() as capture, Live(
# table, console=console, auto_refresh=False
# ) as live:
# for step in range(100):
# console.print(f"Attempting Step #{step}")
# table.add_row(f"{step}", f"{step}", f"{step}")
# if step % 20 == 0:
# live.refresh()
# output = capture.get()
# check_output("growing_table_large.txt", output=output)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_large_overflow() -> None:
# """Test generating a table but also add in console logging."""
# console = create_capture_console()
# table = create_base_table()
# with console.capture() as capture, Live(
# table, console=console, auto_refresh=False
# ) as live:
# for step in range(100):
# console.print(f"Attempting Step #{step}")
# table.add_row(f"{step}", f"{step}", f"{step}")
# if step % 20 == 0:
# live.refresh()
# output = capture.get()
# check_output("growing_table_large_overflow.txt", output=output)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_growing_table_file_console() -> None:
# console = Console(
# width=120,
# height=80,
# file=io.StringIO(),
# legacy_windows=False,
# color_system=None,
# )
# table = create_base_table()
# with console.capture() as capture, Live(table, console=console) as live:
# for step in range(20):
# console.print(f"step {step}")
# table.add_row(f"{step}", f"{step}", f"{step}")
# live.refresh()
# output = capture.get()
# check_output("growing_table_file_console.txt", output=output)
# def generate_random_data_table() -> Table:
# Data = List[List[int]]
# def generate_data() -> Data:
# rows = random.randint(0, 20)
# return [
# [random.randint(0, 20) for _ in range(rows)]
# for _ in range(random.randint(0, 20))
# ]
# table = Table()
# for data_row in generate_data():
# table.add_row(*[hex(data_cell) for data_cell in data_row])
# return table
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_random_data_table() -> None:
# """Test generating a data table whose height fluctuates."""
# console = create_capture_console()
# random.seed(123) # seed so that it always provides same values
# with console.capture() as capture, Live(
# console=console, auto_refresh=False
# ) as live:
# for _ in range(100):
# table = generate_random_data_table()
# live.update(table, refresh=True)
# output = capture.get()
# check_output("random_data_table.txt", output=output)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_random_data_table_overflow() -> None:
# """Test generating a data table whose height fluctuates."""
# console = create_capture_console(height=20)
# random.seed(123) # seed so that it always provides same values
# with console.capture() as capture, Live(
# console=console, auto_refresh=False
# ) as live:
# for _ in range(100):
# table = generate_random_data_table()
# live.update(table, refresh=True)
# output = capture.get()
# check_output("random_data_table_overflow.txt", output=output)
# @pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
# def test_random_data_table_logging() -> None:
# """Test generating a data table whose height fluctuates."""
# console = create_capture_console()
# random.seed(123) # seed so that it always provides same values
# with console.capture() as capture, Live(
# console=console, auto_refresh=False
# ) as live:
# for step in range(100):
# console.print(f"Step {step} start")
# table = generate_random_data_table()
# live.update(table, refresh=True)
# print(f"Step {step} end") # test redirect of stdout
# output = capture.get()
# check_output("random_data_table_logging.txt", output=output)
def test_growing_display_file_console() -> None:
console = create_capture_console(force_terminal=False)
console.begin_capture()
with Live(console=console, auto_refresh=False) as live:
display = ""
for step in range(10):
display += f"Step {step}\n"
live.update(display, refresh=True)
output = console.end_capture()
print(repr(output))
print(output)
assert (
output
== "Step 0\nStep 1\nStep 2\nStep 3\nStep 4\nStep 5\nStep 6\nStep 7\nStep 8\nStep 9\n"
)