Skip to content
Snippets Groups Projects
Commit 24447185 authored by Urs Baumann's avatar Urs Baumann :bath:
Browse files

User rich for output

parent 77ae49bf
No related branches found
No related tags found
No related merge requests found
from logging import error
import sys
from click.termui import style
import typer
import httpx
from pathlib import Path
from rich import print
from rich.console import Console
from rich.panel import Panel
def upload_file(notebook: Path = typer.Argument(
console = Console()
def upload_file(
notebook: Path = typer.Argument(
...,
exists=True,
file_okay=True,
......@@ -11,10 +20,41 @@ def upload_file(notebook: Path = typer.Argument(
writable=False,
readable=True,
resolve_path=True,
)):
files = {'file': open(notebook, 'rb')}
r = httpx.post("http://localhost:5000/testbook", files=files, timeout=600.0)
print(r.json())
)
):
files = {"file": open(notebook, "rb")}
try:
with console.status("[bold green]Testing..."):
r = httpx.post("http://localhost:5000/testbook", files=files, timeout=600.0)
r.raise_for_status()
result = r.json()
test_result = result["tests"]
for status, style in [
("error", "bold red"),
("failed", "red"),
("passed", "green"),
("skipped", ""),
("xfailed", "red"),
("xpassed", ""),
]:
if test_result[status]:
console.print(
Panel(
"\n".join(
[
f" - test_{test['nodeid']:02d} {test['outcome']} at {test['when']}"
for test in test_result[status]
]
),
title=status.capitalize(),
subtitle=f"{len(test_result[status])}",
style=style,
)
)
except httpx.HTTPError as exc:
print(f"[red bold]{exc}[/]", file=sys.stderr)
typer.Exit(code=1)
def run():
......@@ -22,4 +62,4 @@ def run():
if __name__ == "__main__":
run()
\ No newline at end of file
run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment