forked from kenzuya/unshackle
fix(console): print all console output at the terminal width when wide_output is on
This commit is contained in:
@@ -77,6 +77,12 @@ def no_worker_handlers(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(console, "_notice_handler", None)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixed_console_width(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Hold the shared console at 80 columns, whatever the terminal and the user's ``wide_output``."""
|
||||
monkeypatch.setattr(console.console, "_width", 80)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fresh_proxy_catalogues() -> None:
|
||||
"""Fetch each proxy provider catalogue again, so one test's stub never answers another test."""
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
SCRIPT = """
|
||||
from unshackle.core.config import config
|
||||
config.wide_output = {wide}
|
||||
from rich.padding import Padding
|
||||
from rich.table import Table
|
||||
from unshackle.core.console import console
|
||||
from unshackle.core.tracks import Audio, Tracks, Video
|
||||
print(console.width)
|
||||
tracks = Tracks([Video(url="https://example.test/v.mpd", language="en"), Audio(url="https://example.test/a.mpd", language="en")])
|
||||
tree, (video, audio) = tracks.tree(add_progress=True)
|
||||
video(downloaded="Downloaded")
|
||||
audio(total=None, downloaded="1 MB/s")
|
||||
grid = Table.grid()
|
||||
grid.add_row(tree)
|
||||
for line in console.render_lines(Padding(grid, (1, 5)), pad=False):
|
||||
text = "".join(s.text for s in line)
|
||||
if "━" in text:
|
||||
print(text.count("━"), text.rfind("━"))
|
||||
"""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("wide", "width"), [(True, 120), (False, 80)])
|
||||
def test_console_follows_wide_output(wide: bool, width: int) -> None:
|
||||
"""With wide_output the console takes the terminal width and track bars fill the line to one right edge.
|
||||
|
||||
Without it the console holds 80 columns and each bar 40 cells. Both are read at import, hence the subprocess.
|
||||
"""
|
||||
out = subprocess.run(
|
||||
[sys.executable, "-c", SCRIPT.format(wide=wide)],
|
||||
env={**os.environ, "COLUMNS": "120"},
|
||||
cwd=Path(__file__).parents[2],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
check=True,
|
||||
timeout=60,
|
||||
)
|
||||
console_width, *bars = out.stdout.strip().splitlines()[-3:]
|
||||
(full, full_end), (pulse, pulse_end) = (map(int, bar.split()) for bar in bars)
|
||||
assert int(console_width) == width
|
||||
if wide:
|
||||
assert full > 40 and pulse > 40 and full_end == pulse_end
|
||||
else:
|
||||
assert full == pulse == 40
|
||||
Reference in New Issue
Block a user