import unittest import io import re from unittest import mock import math import student_X as main #Replace student_X with your filename import sys import io from io import StringIO class PrintMinutesHandTests(unittest.TestCase): def test_default_case(self): function = main.print_minutes_hand try: docstring = function.__doc__ docstring = docstring.strip() except: docstring = "" correct = docstring != "" message = "docstring is blank." self.assertTrue(correct, message) with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: function(17) output = fake_stdout.getvalue().strip() regex = "17.*" test = re.match(regex, output) feedback = "Doesn't print the parameter at the beginning of the output." self.assertTrue(test, feedback) regex = ".* minutes after noon, the big hand is pointing to.*minutes" test = re.match(regex, output) feedback = "Doesn't include the correct words in the correct order." self.assertTrue(test, feedback) correct = output.endswith(".") feedback = "The output doesn't end with a period." self.assertTrue(correct, feedback) correct = "17 minutes after noon, the big hand is pointing to 17 minutes." test = output == correct feedback = "Doesn't print out the correct sentence when given 17 minutes. Is your spacing okay?" self.assertTrue(test, feedback) with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: function(213) output = fake_stdout.getvalue().strip() correct = "213 minutes after noon, the big hand is pointing to 33 minutes." test = output == correct feedback = "Doesn't print out the correct sentence when given 213 minutes." self.assertTrue(test, feedback) if __name__ == "__main__": tests = PrintMinutesHandTests() tests.test_default_case()