Overhaul in printing using rich

This commit is contained in:
pedrocarlo 2025-04-03 23:07:07 -03:00
parent b34e7e011e
commit d71029cda7
6 changed files with 58 additions and 23 deletions

View file

@ -5,6 +5,7 @@ from time import sleep
import subprocess
from pathlib import Path
from typing import Callable, List, Optional
from cli_tests import console
PIPE_BUF = 4096
@ -77,9 +78,9 @@ class LimboShell:
error_output = self.pipe.stderr.read(PIPE_BUF)
if error_output == b"":
return True
print(error_output.decode(), end="")
console.error(error_output.decode(), end="")
return False
@staticmethod
def _clean_output(output: str, marker: str) -> str:
output = output.rstrip().removesuffix(marker)
@ -128,7 +129,7 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
self.shell.quit()
def run_test(self, name: str, sql: str, expected: str) -> None:
print(f"Running test: {name}")
console.info(f"Running test: {name}")
actual = self.shell.execute(sql)
assert actual == expected, (
f"Test failed: {name}\n"
@ -138,9 +139,9 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
)
def debug_print(self, sql: str):
print(f"debugging: {sql}")
console.debug(f"debugging: {sql}")
actual = self.shell.execute(sql)
print(f"OUTPUT:\n{repr(actual)}")
console.debug(f"OUTPUT:\n{repr(actual)}")
def run_test_fn(
self, sql: str, validate: Callable[[str], bool], desc: str = ""
@ -148,7 +149,7 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
# Print the test that is executing before executing the sql command
# Printing later confuses the user of the code what test has actually failed
if desc:
print(f"Testing: {desc}")
console.info(f"Testing: {desc}")
actual = self.shell.execute(sql)
assert validate(actual), f"Test failed\nSQL: {sql}\nActual:\n{repr(actual)}"