Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit bug #102

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `clear_screen` function
### Changed
- Restart mode updated
- Exit bug fixed
## [0.7] - 2024-08-27
### Added
- `feature_request.yml` template
Expand Down
2 changes: 1 addition & 1 deletion nafas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ def main():
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
except (KeyboardInterrupt, EOFError):
print("\n" + EXIT_MESSAGE)
5 changes: 4 additions & 1 deletion nafas/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from nafas.params import NAFAS_DESCRIPTION, NAFAS_NOTICE, STANDARD_MENU, STANDARD_MENU_ORDER, STEP_MAP
from nafas.params import PROGRAMS, PROGRAM_DESCRIPTION, SOUND_MAP, STEP_TEMPLATE, CYCLE_TEMPLATE
from nafas.params import SOUND_WARNING_MESSAGE
from nafas.params import SOUND_WARNING_MESSAGE, EXIT_MESSAGE
import nava
import os
from warnings import warn
Expand Down Expand Up @@ -221,6 +221,9 @@ def get_input_standard(input_func=input):
try:
input_data[item] = int(input_func(""))
exit_flag = True
except KeyboardInterrupt:
print("\n" + EXIT_MESSAGE)
sys.exit()
except Exception:
print("[Error] Bad Input!")
return input_data
Expand Down
6 changes: 6 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
True
>>> input_data["level"] == 1
True
>>> def test_keyboard_interrupt(i):
... raise KeyboardInterrupt
>>> input_data = get_input_standard(lambda x: "1")
- Please choose a program :
<BLANKLINE>
Expand All @@ -70,6 +72,10 @@
1- Beginner
2- Medium
3- Advanced
>>> get_input_standard(test_keyboard_interrupt)
Traceback (most recent call last):
...
SystemExit
Comment on lines +75 to +78
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also have EXIT_MESSAGE content here?
That's not a big deal, just to make sure everything is tested as much as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than that, it's good. If you don't think adding such a thing is necessary you can merge it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test system behavior is a bit weird here. I think it's because of the sys.exit().

>>> input_data["program"] == 1
True
>>> input_data["level"] == 1
Expand Down
Loading