Skip to content

Commit

Permalink
keep the tests but move them to valid place
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Nov 1, 2024
1 parent 00fe50f commit 115a5c9
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions tests/units/components/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,26 +908,12 @@ def test_invalid_event_handler_args(component2, test_state):
# EventHandler args must match
with pytest.raises(EventFnArgMismatch):
component2.create(on_click=test_state.do_something_arg)
# Does not raise because event handlers are allowed to have less args than the spec.
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_open=test_state.do_something)
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_prop_event=test_state.do_something)

# Multiple EventHandler args: all must match
with pytest.raises(EventFnArgMismatch):
component2.create(
on_click=[test_state.do_something_arg, test_state.do_something]
)
# Same as above
# with pytest.raises(EventFnArgMismatch):
# component2.create(
# on_open=[test_state.do_something_arg, test_state.do_something]
# )
# with pytest.raises(EventFnArgMismatch):
# component2.create(
# on_prop_event=[test_state.do_something_arg, test_state.do_something]
# )

# Enable when 0.7.0 happens
# # Event Handler types must match
Expand Down Expand Up @@ -958,18 +944,10 @@ def test_invalid_event_handler_args(component2, test_state):
# lambda signature must match event trigger.
with pytest.raises(EventFnArgMismatch):
component2.create(on_click=lambda _: test_state.do_something_arg(1))
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_open=lambda: test_state.do_something)
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_prop_event=lambda: test_state.do_something)

# lambda returning EventHandler must match spec
with pytest.raises(EventFnArgMismatch):
component2.create(on_click=lambda: test_state.do_something_arg)
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_open=lambda _: test_state.do_something)
# with pytest.raises(EventFnArgMismatch):
# component2.create(on_prop_event=lambda _: test_state.do_something)

# Mixed EventSpec and EventHandler must match spec.
with pytest.raises(EventFnArgMismatch):
Expand All @@ -979,17 +957,6 @@ def test_invalid_event_handler_args(component2, test_state):
test_state.do_something_arg,
]
)
# with pytest.raises(EventFnArgMismatch):
# component2.create(
# on_open=lambda _: [test_state.do_something_arg(1), test_state.do_something]
# )
# with pytest.raises(EventFnArgMismatch):
# component2.create(
# on_prop_event=lambda _: [
# test_state.do_something_arg(1),
# test_state.do_something,
# ]
# )


def test_valid_event_handler_args(component2, test_state):
Expand All @@ -1003,6 +970,10 @@ def test_valid_event_handler_args(component2, test_state):
component2.create(on_click=test_state.do_something)
component2.create(on_click=test_state.do_something_arg(1))

# Does not raise because event handlers are allowed to have less args than the spec.
component2.create(on_open=test_state.do_something)
component2.create(on_prop_event=test_state.do_something)

# Controlled event handlers should take args.
component2.create(on_open=test_state.do_something_arg)
component2.create(on_prop_event=test_state.do_something_arg)
Expand All @@ -1011,10 +982,20 @@ def test_valid_event_handler_args(component2, test_state):
component2.create(on_open=test_state.do_something())
component2.create(on_prop_event=test_state.do_something())

# Multiple EventHandler args: all must match
component2.create(on_open=[test_state.do_something_arg, test_state.do_something])
component2.create(
on_prop_event=[test_state.do_something_arg, test_state.do_something]
)

# lambda returning EventHandler is okay if the spec matches.
component2.create(on_click=lambda: test_state.do_something)
component2.create(on_open=lambda _: test_state.do_something_arg)
component2.create(on_prop_event=lambda _: test_state.do_something_arg)
component2.create(on_open=lambda: test_state.do_something)
component2.create(on_prop_event=lambda: test_state.do_something)
component2.create(on_open=lambda _: test_state.do_something)
component2.create(on_prop_event=lambda _: test_state.do_something)

# lambda can always return an EventSpec.
component2.create(on_click=lambda: test_state.do_something_arg(1))
Expand Down Expand Up @@ -1047,6 +1028,15 @@ def test_valid_event_handler_args(component2, test_state):
component2.create(
on_prop_event=lambda _: [test_state.do_something_arg, test_state.do_something()]
)
component2.create(
on_open=lambda _: [test_state.do_something_arg(1), test_state.do_something]
)
component2.create(
on_prop_event=lambda _: [
test_state.do_something_arg(1),
test_state.do_something,
]
)


def test_get_hooks_nested(component1, component2, component3):
Expand Down

0 comments on commit 115a5c9

Please sign in to comment.