mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-19 09:34:18 +01:00
introduce test theme
This commit is contained in:
@@ -4,7 +4,14 @@ from rich.theme import Theme
|
|||||||
from rich.style import Style
|
from rich.style import Style
|
||||||
|
|
||||||
|
|
||||||
custom_theme = Theme({"info": "bold blue", "error": "bold red", "debug": "bold blue"})
|
custom_theme = Theme(
|
||||||
|
{
|
||||||
|
"info": "bold blue",
|
||||||
|
"error": "bold red",
|
||||||
|
"debug": "bold blue",
|
||||||
|
"test": "bold green",
|
||||||
|
}
|
||||||
|
)
|
||||||
console = Console(theme=custom_theme, force_terminal=True)
|
console = Console(theme=custom_theme, force_terminal=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -87,3 +94,29 @@ def debug(
|
|||||||
log_locals=log_locals,
|
log_locals=log_locals,
|
||||||
_stack_offset=_stack_offset + 1,
|
_stack_offset=_stack_offset + 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test(
|
||||||
|
*objects: Any,
|
||||||
|
sep: str = " ",
|
||||||
|
end: str = "\n",
|
||||||
|
style: Optional[Union[str, Style]] = None,
|
||||||
|
justify: Optional[JustifyMethod] = None,
|
||||||
|
emoji: Optional[bool] = None,
|
||||||
|
markup: Optional[bool] = None,
|
||||||
|
highlight: Optional[bool] = None,
|
||||||
|
log_locals: bool = False,
|
||||||
|
_stack_offset: int = 1,
|
||||||
|
):
|
||||||
|
console.log(
|
||||||
|
"[test]TEST[/test]",
|
||||||
|
*objects,
|
||||||
|
sep=sep,
|
||||||
|
end=end,
|
||||||
|
style=style,
|
||||||
|
justify=justify,
|
||||||
|
emoji=emoji,
|
||||||
|
markup=markup,
|
||||||
|
highlight=highlight,
|
||||||
|
log_locals=log_locals,
|
||||||
|
_stack_offset=_stack_offset + 1,
|
||||||
|
)
|
||||||
@@ -132,7 +132,7 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
|
|||||||
self.shell.quit()
|
self.shell.quit()
|
||||||
|
|
||||||
def run_test(self, name: str, sql: str, expected: str) -> None:
|
def run_test(self, name: str, sql: str, expected: str) -> None:
|
||||||
console.info(f"Running test: {name}", _stack_offset=2)
|
console.test(f"Running test: {name}", _stack_offset=2)
|
||||||
actual = self.shell.execute(sql)
|
actual = self.shell.execute(sql)
|
||||||
assert actual == expected, (
|
assert actual == expected, (
|
||||||
f"Test failed: {name}\n"
|
f"Test failed: {name}\n"
|
||||||
@@ -152,7 +152,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
|
# Print the test that is executing before executing the sql command
|
||||||
# Printing later confuses the user of the code what test has actually failed
|
# Printing later confuses the user of the code what test has actually failed
|
||||||
if desc:
|
if desc:
|
||||||
console.info(f"Testing: {desc}", _stack_offset=2)
|
console.test(f"Testing: {desc}", _stack_offset=2)
|
||||||
actual = self.shell.execute(sql)
|
actual = self.shell.execute(sql)
|
||||||
assert validate(actual), f"Test failed\nSQL: {sql}\nActual:\n{repr(actual)}"
|
assert validate(actual), f"Test failed\nSQL: {sql}\nActual:\n{repr(actual)}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user