Skip to content

Commit 06a681c

Browse files
committed
Fix lint
1 parent ea78ef3 commit 06a681c

3 files changed

Lines changed: 51 additions & 37 deletions

File tree

bowtie/_cli.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,16 +1399,18 @@ async def _tui(start: Any, dialect: Dialect, **kwargs: Any):
13991399
except UnsupportedDialect as error:
14001400
STDERR.print(error)
14011401
continue
1402-
runners.append((
1403-
impl_id,
1404-
implementation.info.version or "?",
1405-
runner,
1406-
))
1402+
runners.append(
1403+
(
1404+
impl_id,
1405+
implementation.info.version or "?",
1406+
runner,
1407+
)
1408+
)
14071409

14081410
if not runners:
14091411
STDERR.print(
14101412
"[bold red]No implementation started successfully![/]",
1411-
)
1413+
)
14121414
return EX.CONFIG
14131415
session = TuiSession(
14141416
runners=runners,

bowtie/_tui.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ class TuiSession:
3535
"""
3636

3737
def __init__(
38-
self,
39-
runners: list[tuple[str, str, DialectRunner]],
40-
dialect: Dialect,
41-
console: Console,
42-
prompt: Callable[[str], str],
43-
) -> None:
38+
self,
39+
runners: list[tuple[str, str, DialectRunner]],
40+
dialect: Dialect,
41+
console: Console,
42+
prompt: Callable[[str], str],
43+
) -> None:
4444
self._runners = runners
4545
self._dialect = dialect
4646
self._console = console
4747
self._prompt = prompt
4848
self._seq = 0
4949

5050
async def run_once(
51-
self,
52-
schema: Any,
53-
instance: Any,
51+
self,
52+
schema: Any,
53+
instance: Any,
5454
) -> list[tuple[str, str, bool | None]]:
5555
"""
5656
Validate one instance against one schema across all runners.
@@ -63,10 +63,7 @@ async def run_once(
6363
)
6464
seq_case = SeqCase(seq=self._seq, case=case)
6565

66-
tasks = [
67-
seq_case.run(runner=runner)
68-
for _, _, runner in self._runners
69-
]
66+
tasks = [seq_case.run(runner=runner) for _, _, runner in self._runners]
7067

7168
raw_results = await asyncio.gather(*tasks)
7269

@@ -80,8 +77,8 @@ async def run_once(
8077
return output
8178

8279
def show_results(
83-
self,
84-
results: list[tuple[str, str, bool | None]],
80+
self,
81+
results: list[tuple[str, str, bool | None]],
8582
) -> None:
8683
table = Table(show_header=True, header_style="bold")
8784
table.add_column("Implementation")
@@ -107,13 +104,15 @@ async def repl(self) -> None:
107104
impl_count = len(self._runners)
108105
impl_word = "implementation" if impl_count == 1 else "implementations"
109106

110-
self._console.print(Panel(
111-
f"Dialect: [bold]{self._dialect.pretty_name}[/bold] "
112-
f"Running: [bold]{impl_count}[/bold] {impl_word}\n\n"
113-
"[dim]Enter a JSON schema, then one instance to validate.\n"
114-
"Type [bold]q[/bold] to quit.[/dim]",
115-
title="bowtie tui",
116-
))
107+
self._console.print(
108+
Panel(
109+
f"Dialect: [bold]{self._dialect.pretty_name}[/bold] "
110+
f"Running: [bold]{impl_count}[/bold] {impl_word}\n\n"
111+
"[dim]Enter a JSON schema, then one instance to validate.\n"
112+
"Type [bold]q[/bold] to quit.[/dim]",
113+
title="bowtie tui",
114+
)
115+
)
117116

118117
while True:
119118
try:
@@ -127,7 +126,7 @@ async def repl(self) -> None:
127126
except ValueError as e:
128127
self._console.print(
129128
f"[red]Invalid JSON for schema: {e}[/red]",
130-
)
129+
)
131130
continue
132131

133132
if not _is_schema_like(schema):
@@ -148,7 +147,7 @@ async def repl(self) -> None:
148147
except ValueError as e:
149148
self._console.print(
150149
f"[red]Invalid JSON for instance: {e}[/red]",
151-
)
150+
)
152151
continue
153152

154153
results = await self.run_once(schema=schema, instance=instance)

bowtie/tests/test_tui.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def _silent_console() -> Console:
1414
return Console(file=io.StringIO(), highlight=False)
1515

16+
1617
def _test_prompt(inputs: list[str]):
1718
it = iter(inputs)
1819

@@ -24,18 +25,23 @@ def prompt(msg: str) -> str:
2425

2526
return prompt
2627

28+
2729
def test_parse_json_invalid_raises_value_error():
2830
with pytest.raises(ValueError, match="Expecting property name"):
2931
_parse_json("{not valid json")
3032

33+
3134
def test_is_schema_like_rejects_string():
3235
assert _is_schema_like("hello") is False
3336

37+
3438
@pytest.fixture
3539
def dialect():
3640
from bowtie._core import Dialect
41+
3742
return Dialect.by_short_name()["draft2020-12"]
3843

44+
3945
@pytest_asyncio.fixture
4046
async def session(dialect):
4147
"""
@@ -55,6 +61,7 @@ async def session(dialect):
5561
prompt=lambda _: (_ for _ in ()).throw(EOFError()),
5662
)
5763

64+
5865
@pytest.mark.asyncio
5966
async def test_run_once_valid_instance(session):
6067
results = await session.run_once(
@@ -66,6 +73,7 @@ async def test_run_once_valid_instance(session):
6673
assert valid is True
6774
assert "jsonschema" in impl_id
6875

76+
6977
@pytest.mark.asyncio
7078
async def test_run_once_invalid_instance(session):
7179
results = await session.run_once(
@@ -76,23 +84,28 @@ async def test_run_once_invalid_instance(session):
7684
_, _, valid = results[0]
7785
assert valid is False
7886

87+
7988
@pytest.mark.asyncio
8089
async def test_repl_exits_on_q(session):
8190
session._prompt = _test_prompt(["q"])
8291
await session.repl()
8392

93+
8494
@pytest.mark.asyncio
8595
async def test_repl_non_schema_json_continues(session):
8696
session._prompt = _test_prompt(['"just a string"', "q"])
8797
await session.repl()
8898

99+
89100
@pytest.mark.asyncio
90101
async def test_repl_validates_and_continues(session):
91-
session._prompt = _test_prompt([
92-
'{"type": "integer"}',
93-
"42",
94-
'{"type": "integer"}',
95-
'"hello"',
96-
"q",
97-
])
102+
session._prompt = _test_prompt(
103+
[
104+
'{"type": "integer"}',
105+
"42",
106+
'{"type": "integer"}',
107+
'"hello"',
108+
"q",
109+
]
110+
)
98111
await session.repl()

0 commit comments

Comments
 (0)