Add die.py tests (#1042)

* created tests for die.py

* updated

* migrate to pytest

* Update deps

* Revert poetry.lock

---------

Signed-off-by: Achintya Jai <153343775+pUrGe12@users.noreply.github.com>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
This commit is contained in:
Achintya Jai 2025-06-12 05:50:17 +05:30 committed by GitHub
parent 04c2097fbe
commit e419d227c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 0 deletions

25
tests/core/test_die.py Normal file
View File

@ -0,0 +1,25 @@
from io import StringIO
from unittest.mock import patch
from nettacker.core.die import die_success, die_failure
from nettacker.logger import TerminalCodes
@patch("sys.stdout", new_callable=StringIO)
@patch("sys.exit")
def test_die_success(mock_exit, mock_stdout):
reset_code = TerminalCodes.RESET.value
die_success()
success_message = mock_stdout.getvalue()
assert reset_code in success_message
mock_exit.assert_called_once_with(0)
@patch("sys.stdout", new_callable=StringIO)
@patch("sys.exit")
def test_die_failure(mock_exit, mock_stdout):
test_message = "Test error message"
die_failure(test_message)
error_message = mock_stdout.getvalue()
assert test_message in error_message
mock_exit.assert_called_once_with(1)