-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from da-h/event_register_in_event
Dynamic Event Registration
- Loading branch information
Showing
5 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
21 changes: 21 additions & 0 deletions
21
tests/test_event/modules/register_event_during_event/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
def test(i): | ||
print("test", i) | ||
|
||
|
||
def add_test(mf): | ||
def add_test_print(i): | ||
print("added to test", i) | ||
mf.register_event("test", add_test_print) | ||
|
||
|
||
def main(event): | ||
event.test(0) | ||
event.add_test() | ||
event.test(1) | ||
|
||
|
||
def register(mf): | ||
mf.register_event("test", test) | ||
mf.register_event("add_test", add_test) | ||
mf.register_event("main", main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
import miniflask # noqa: E402 | ||
|
||
|
||
def init_mf(): | ||
return miniflask.init(module_dirs=str(Path(__file__).parent / "modules"), debug=True) | ||
|
||
|
||
def test_register_event_during_event(capsys): | ||
mf = init_mf() | ||
mf.run(argv=[], modules=["register_event_during_event"]) | ||
captured = capsys.readouterr() | ||
out = """ | ||
test 0 | ||
test 1 | ||
added to test 1 | ||
""" | ||
assert out in captured.out |