Skip to content

Commit

Permalink
Exit bug (#102)
Browse files Browse the repository at this point in the history
* fix : EOFError handler added

* fix : get_input_standard function updated

* doc : CHANGELOG.md updated

* fix : minor bug in get_input_standard function fixed

* fix : import EXIT_MESSAGE

* fix : tests updated

* fix : tests updated
  • Loading branch information
sepandhaghighi authored Sep 25, 2024
1 parent 231322a commit 4508cde
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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
>>> input_data["program"] == 1
True
>>> input_data["level"] == 1
Expand Down

0 comments on commit 4508cde

Please sign in to comment.