Skip to content

Commit

Permalink
still missing node from dom
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Jun 9, 2024
1 parent 705725e commit e1c92ac
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
15 changes: 8 additions & 7 deletions sksmithy/tui/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def on_input_change(self: Self, event: Input.Changed) -> None:
timeout=5,
)
else:
output_file = self.app.query_one("#output_file", Input)
output_file.value = f"{event.value.lower()}.py"
output_file = self.app.query_one("#output-file", Input)
if not output_file.value:
output_file.value = f"{event.value.lower()}.py"


class Estimator(Container):
Expand Down Expand Up @@ -210,8 +211,8 @@ class DestinationFile(Container):
"""Destination file input component."""

def compose(self: Self) -> ComposeResult:
yield Prompt(PROMPT_OUTPUT, classes="label", id="output_prompt")
yield Input(placeholder="mightyestimator.py", id="output_file")
yield Prompt(PROMPT_OUTPUT, classes="label")
yield Input(placeholder="mightyestimator.py", id="output-file")


class ForgeButton(Container):
Expand All @@ -220,10 +221,10 @@ class ForgeButton(Container):
def compose(self: Self) -> ComposeResult:
yield Button.success(
label="Forge ⚒️",
id="forge_btn",
id="forge-btn",
)

@on(Button.Pressed, "#forge_btn")
@on(Button.Pressed, "#forge-btn")
def on_forge(self: Self, _: Button.Pressed) -> None: # noqa: C901
errors = []

Expand All @@ -237,7 +238,7 @@ def on_forge(self: Self, _: Button.Pressed) -> None: # noqa: C901
predict_proba = self.app.query_one("#predict_proba", Switch).value
decision_function = self.app.query_one("#decision_function", Switch).value

output_file = self.app.query_one("#output_file", Input).value
output_file = self.app.query_one("#output-file", Input).value

match name_parser(name_input):
case Ok(name):
Expand Down
2 changes: 1 addition & 1 deletion sksmithy/tui/_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def action_toggle_sidebar(self: Self) -> None:

def action_forge(self: Self) -> None:
"""Press forge button."""
forge_btn = self.query_one("#forge_btn", Button)
forge_btn = self.query_one("#forge-btn", Button)
forge_btn.press()


Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ def required(request: pytest.FixtureRequest) -> list[str]:
return request.param


@pytest.fixture(
params=[
("a,a", "Found repeated parameters!"),
("a-a", "The following parameters are invalid python identifiers: ('a-a',)"),
]
)
def invalid_required(request: pytest.FixtureRequest) -> tuple[str, str]:
return request.param


@pytest.fixture(
params=[
("b,b", "Found repeated parameters!"),
("b b", "The following parameters are invalid python identifiers: ('b b',)"),
]
)
def invalid_optional(request: pytest.FixtureRequest) -> tuple[str, str]:
return request.param


@pytest.fixture(params=[["mu", "sigma"], []])
def optional(request: pytest.FixtureRequest) -> list[str]:
return request.param
Expand Down
85 changes: 43 additions & 42 deletions tests/test_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async def test_smoke() -> None:
await pilot.pause()
assert pilot is not None

await pilot.pause()
await pilot.exit(0)


Expand All @@ -29,11 +30,9 @@ async def test_name(name_: str, err_msg: str) -> None:
"""Test `name` text_input component."""
app = ForgeTUI()
async with app.run_test(size=None) as pilot:
await pilot.pause()
name_comp = pilot.app.query_one("#name", Input)
name_comp.value = name_

await pilot.pause(0.01)
await pilot.pause()

assert (not name_comp.is_valid) == bool(err_msg)

Expand All @@ -43,6 +42,7 @@ async def test_name(name_: str, err_msg: str) -> None:
if notifications:
assert notifications[0].message == err_msg

await pilot.pause()
await pilot.exit(0)


Expand Down Expand Up @@ -72,23 +72,15 @@ async def test_estimator_interaction(estimator: EstimatorType) -> None:
await pilot.pause()
assert pilot.app.query_one("#decision_function", Switch).disabled

await pilot.pause()
await pilot.exit(0)


@pytest.mark.parametrize(
("required_", "optional_", "err_msg"),
[
("a,b", "c,d", ""),
("a,a", "", "Found repeated parameters!"),
("", "b,b", "Found repeated parameters!"),
("a-a", "", "The following parameters are invalid python identifiers: ('a-a',)"),
("", "b b", "The following parameters are invalid python identifiers: ('b b',)"),
("a,b", "a", "The following parameters are duplicated between required and optional: {'a'}"),
],
)
async def test_params(required_: str, optional_: str, err_msg: str) -> None:
async def test_valid_params() -> None:
"""Test required and optional params interaction."""
app = ForgeTUI()
required_ = "a,b"
optional_ = "c,d"
async with app.run_test(size=None) as pilot:
required_comp = pilot.app.query_one("#required", Input)
optional_comp = pilot.app.query_one("#optional", Input)
Expand All @@ -101,60 +93,63 @@ async def test_params(required_: str, optional_: str, err_msg: str) -> None:
await pilot.pause(0.01)

notifications = list(pilot.app._notifications) # noqa: SLF001
assert int(bool(notifications)) == int(bool(err_msg))

if notifications:
assert err_msg in "".join(n.message for n in notifications)
assert not notifications

await pilot.pause()
await pilot.exit(0)


@pytest.mark.parametrize(
("required_", "optional_", "err_msg"),
[
("a,a", "", "Found repeated parameters!"),
("", "b,b", "Found repeated parameters!"),
("a-a", "", "The following parameters are invalid python identifiers: ('a-a',)"),
("", "b b", "The following parameters are invalid python identifiers: ('b b',)"),
("a,b", "a", "The following parameters are duplicated between required and optional: {'a'}"),
],
)
async def test_forge_raise(required_: str, optional_: str, err_msg: str) -> None:
async def test_forge_raise() -> None:
"""Test forge button and all of its interactions."""
app = ForgeTUI()
async with app.run_test(size=None) as pilot:
await pilot.pause()

pilot.app.query_one("#required", Input).value = required_
pilot.app.query_one("#optional", Input).value = optional_
required_comp = pilot.app.query_one("#required", Input)
optional_comp = pilot.app.query_one("#optional", Input)

required_comp.value = "a,a"
optional_comp.value = "b b"

await required_comp.action_submit()
await optional_comp.action_submit()
await pilot.pause()

forge_btn = pilot.app.query_one("#forge_btn", Button)
forge_btn = pilot.app.query_one("#forge-btn", Button)
forge_btn.action_press()
await pilot.pause()

notification_msg = list(pilot.app._notifications)[-1].message # noqa: SLF001
assert "Name cannot be empty!" in notification_msg
assert "Estimator cannot be empty!" in notification_msg
assert "Outfile file cannot be empty!" in notification_msg
assert err_msg in notification_msg
m1, m2, m3 = (n.message for n in pilot.app._notifications) # noqa: SLF001

assert "Found repeated parameters!" in m1
assert "The following parameters are invalid python identifiers: ('b b',)" in m2

assert "Name cannot be empty!" in m3
assert "Estimator cannot be empty!" in m3
assert "Outfile file cannot be empty!" in m3
assert "Found repeated parameters!" in m3
assert "The following parameters are invalid python identifiers: ('b b',)" in m3

await pilot.pause()
await pilot.exit(0)


async def test_forge(tmp_path: Path, name: str, estimator: EstimatorType) -> None:
async def test_forge(tmp_path: Path) -> None:
"""Test forge button and all of its interactions."""
app = ForgeTUI()
name = "MightyEstimator"
estimator = "classifier"
async with app.run_test(size=None) as pilot:
await pilot.pause()

name_comp = pilot.app.query_one("#name", Input)
estimator_comp = pilot.app.query_one("#estimator", Select)
output_file_comp = pilot.app.query_one("#output_file", Input)
await pilot.pause()

output_file_comp = pilot.app.query_one("#output-file", Input)

name_comp.value = name
estimator_comp.value = estimator.value
estimator_comp.value = estimator

await pilot.pause()

Expand All @@ -163,7 +158,7 @@ async def test_forge(tmp_path: Path, name: str, estimator: EstimatorType) -> Non
await output_file_comp.action_submit()
await pilot.pause()

forge_btn = pilot.app.query_one("#forge_btn", Button)
forge_btn = pilot.app.query_one("#forge-btn", Button)
forge_btn.action_press()
await pilot.pause()

Expand All @@ -172,7 +167,13 @@ async def test_forge(tmp_path: Path, name: str, estimator: EstimatorType) -> Non
assert f"Template forged at {output_file!s}" in notification.message
assert output_file.exists()

await pilot.pause()
await pilot.exit(0)


def test_bindings() -> None: ...


def test_duplicated_params() -> None:
# values: ("a,b", "a", "The following parameters are duplicated between required and optional: {'a'}"),
...

0 comments on commit e1c92ac

Please sign in to comment.