Skip to content

Commit

Permalink
Fix printed inputs and make panel titles bold
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Jun 7, 2024
1 parent 0084775 commit dad5dac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
19 changes: 19 additions & 0 deletions examples/recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pysvt import test

d = {
"i": [[[1, 2, 3]], [[1, 4, 3, 2]]],
"o": [[3, 2, 1], [2, 3, 4, 1]],
}


def reverse(xs: list, acc: list = []) -> list:
if xs == []:
return acc
print(f"xs: {xs}, acc: {acc}")
el = xs.pop()
return reverse(xs, [*acc, el])


@test(data=d)
def reverseArray(a: list):
return reverse(a)
7 changes: 6 additions & 1 deletion pysvt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import tomllib as toml
from contextlib import redirect_stdout
from copy import deepcopy
from functools import partial, wraps
from io import StringIO
from pathlib import Path
Expand Down Expand Up @@ -136,6 +137,8 @@ def __call__(self, obj: object) -> Any:
# with self._printer.init_normal() as _:
failures = 0

print(self._data.data)

for index, data in enumerate(self._data.data):
partial_method = partial(method, obj(*self._data.init[index]))
with Timer() as timer:
Expand Down Expand Up @@ -343,7 +346,8 @@ def _validate(self, data: _FuncModel, func: Callable[..., Any]) -> Result:
if data.inputs is not None:
if not isinstance(data.inputs, list):
raise ValidationError("Inputs must be nested within a list")
partial_fn = partial(func, *data.inputs)
# deepcopy to avoid inconsistent inputs being printed due to mutations
partial_fn = partial(func, *deepcopy(data.inputs))

if self._pretty_print_errors:
try:
Expand All @@ -353,6 +357,7 @@ def _validate(self, data: _FuncModel, func: Callable[..., Any]) -> Result:
stdout = f.getvalue()
else:
result = partial_fn()
print(partial_fn.__)
except Exception:
console.print_exception(show_locals=True)
else:
Expand Down
21 changes: 19 additions & 2 deletions pysvt/utils/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ def post_validation_normal(
time_taken (float): The time taken for the validation.
show_error_only (bool): Flag indicating whether to show only the error panel.
"""
out_str = f"Input - {data.inputs}\nExpected output - {data.output}\nActual output - {res.data}"
input_str = f"{Printer.bold("Input")} - {data.inputs}"
exp_out_str = f"{Printer.bold("Expected output")} - {data.output}"
act_out_str = f"{Printer.bold("Actual output")} - {res.data}"

out_str = f"{input_str}\n{exp_out_str}\n{act_out_str}"

if res.stdout is not None and res.stdout.strip() != "":
out_str += f"\n\nStdout -\n{res.stdout.strip()}"
out_str += f"\n\n{Printer.bold("Stdout")} -\n{res.stdout.strip()}"

emoji = ":white_check_mark:" if res.valid else ":cross_mark:"
time_str = (
Expand Down Expand Up @@ -203,6 +207,19 @@ def traceback(self):
"""
self._console.print_exception(show_locals=True)

@staticmethod
def bold(data: str) -> str:
"""
Formats the given data in bold font weight.
Args:
data (str): The data to be formatted.
Returns:
str: The formatted message.
"""
return f"[bold]{data}[/bold]"

@staticmethod
def success(data: str) -> str:
"""
Expand Down

0 comments on commit dad5dac

Please sign in to comment.