Skip to content

Commit

Permalink
healthmanagementsystem:added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
miniedattu committed Jun 7, 2024
1 parent e724679 commit e1d85ca
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions projects/anu-info.txt
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.
1 change: 1 addition & 0 deletions projects/healthmanagementsystem/src/anu-exe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-06-07 16:52:53.482257: Done 30 minutes running
1 change: 1 addition & 0 deletions projects/healthmanagementsystem/src/anu-food.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-06-07 16:52:00.267295: Vegeterian only
Empty file.
1 change: 1 addition & 0 deletions projects/healthmanagementsystem/test/anu-exe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-06-07 22:42:33.603290: Test log entry
3 changes: 3 additions & 0 deletions projects/healthmanagementsystem/test/anu-info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Gender: Female
Height: 160 cm
Weight: 50 kg
16 changes: 16 additions & 0 deletions projects/healthmanagementsystem/test/test_log_entry.py
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 projects/healthmanagementsystem/test/test_log_personal_info.py
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 projects/healthmanagementsystem/test/test_log_wrong_entry.py
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 projects/healthmanagementsystem/test/test_retrieve_entry.py
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()
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 projects/healthmanagementsystem/test/test_retrieve_wrong_entry.py
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()
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()

0 comments on commit e1d85ca

Please sign in to comment.