-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
healthmanagementsystem:added test cases
- Loading branch information
1 parent
e724679
commit e1d85ca
Showing
15 changed files
with
127 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Gender: Female | ||
Height: 160 cm | ||
Weight: 50 kg |
Empty file.
Empty file.
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 @@ | ||
2024-06-07 16:52:53.482257: Done 30 minutes running |
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 @@ | ||
2024-06-07 16:52:00.267295: Vegeterian only |
Empty file.
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 @@ | ||
2024-06-07 22:42:33.603290: Test log entry |
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,3 @@ | ||
Gender: Female | ||
Height: 160 cm | ||
Weight: 50 kg |
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,16 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
from ..src import health | ||
|
||
|
||
class TestLogEntry(unittest.TestCase): | ||
|
||
@patch('builtins.input', side_effect=["Test log entry"]) | ||
def test_log_entry(self, mock_input): | ||
with patch('sys.stdout', new_callable=StringIO) as mock_stdout: | ||
health.log_entry("anu", 1) | ||
self.assertEqual(mock_stdout.getvalue(), "Written successfully\n") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
16 changes: 16 additions & 0 deletions
16
projects/healthmanagementsystem/test/test_log_personal_info.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,16 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
from ..src import health | ||
|
||
|
||
class TestLogPersonalInfo(unittest.TestCase): | ||
|
||
@patch('builtins.input', side_effect=["Female", "160", "50"]) | ||
def test_log_personal_info(self, mock_input): | ||
with patch('sys.stdout', new_callable=StringIO) as mock_stdout: | ||
health.log_personal_info("anu") | ||
self.assertEqual(mock_stdout.getvalue(), "Personal information logged successfully\n") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
15 changes: 15 additions & 0 deletions
15
projects/healthmanagementsystem/test/test_log_wrong_entry.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,15 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from ..src import health | ||
|
||
class TestLogWrongEntry(unittest.TestCase): | ||
@patch('builtins.input', side_effect=['exercise', 'value']) | ||
@patch('builtins.print') | ||
def test_invalid_entry_type(self, mock_print, mock_input): | ||
health.log_entry("person", 3) | ||
|
||
mock_print.assert_called_once_with("Invalid entry type.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
19 changes: 19 additions & 0 deletions
19
projects/healthmanagementsystem/test/test_retrieve_entry.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,19 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
from ..src import health | ||
|
||
|
||
class TestRetrieveEntry(unittest.TestCase): | ||
|
||
def test_no_records_found(self): | ||
# Simulate FileNotFoundError by mocking the open function | ||
with patch('builtins.open', side_effect=FileNotFoundError): | ||
with patch('sys.stdout', new_callable=StringIO) as mock_stdout: | ||
health.retrieve_entry("Anna", 1) | ||
expected_output = "No records found for Anna's 1\n" | ||
self.assertEqual(mock_stdout.getvalue(), expected_output) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
15 changes: 15 additions & 0 deletions
15
projects/healthmanagementsystem/test/test_retrieve_personal_info.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,15 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
from ..src import health | ||
|
||
|
||
class TestRetrievePersonalInfo(unittest.TestCase): | ||
|
||
def test_retrieve_personal_info(self): | ||
with patch('sys.stdout', new_callable=StringIO) as mock_stdout: | ||
health.retrieve_personal_info("anu") | ||
self.assertEqual(mock_stdout.getvalue(), "Gender: Female\nHeight: 160 cm\nWeight: 50 kg\n\n") | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
17 changes: 17 additions & 0 deletions
17
projects/healthmanagementsystem/test/test_retrieve_wrong_entry.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,17 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
|
||
from ..src import health | ||
|
||
|
||
class TestRetrieveWrongEntry(unittest.TestCase): | ||
@patch('sys.stdout', new_callable=StringIO) | ||
def test_retrieve_wrong_entry(self, mock_stdout): | ||
health.retrieve_entry("Smith", 3) | ||
|
||
self.assertEqual(mock_stdout.getvalue().strip(), "Invalid entry type.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
20 changes: 20 additions & 0 deletions
20
projects/healthmanagementsystem/test/test_retrieve_wrong_person_info.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,20 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from io import StringIO | ||
import sys | ||
|
||
# Import the function to be tested | ||
from ..src import health | ||
|
||
|
||
class TestInputWrongPersonInfo(unittest.TestCase): | ||
@patch('builtins.input', side_effect=['1']) | ||
@patch('sys.stdout', new_callable=StringIO) | ||
def test_invalid_person_number(self, mock_stdout, mock_input): | ||
health.input_person_data(4) | ||
|
||
self.assertEqual(mock_stdout.getvalue().strip(), "Invalid person number.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |