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 import inspect class TwoPlusTwoStatementTests(unittest.TestCase): def test_default_case(self): function = main.two_plus_two_statement with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: function() output = fake_stdout.getvalue().strip() source_code = inspect.getsource(function) correct = source_code.count(",") >= 4 message = "It looks like you changed this into a print statement with fewer parts, but I want all the comma-separated parts in there so you can see how this works. (Sorry!)" self.assertTrue(correct, message) correct = "+" in source_code message = "I really want you to keep the plus sign in your code." self.assertTrue(correct, message) correct = "5" not in output message = "I don't think you changed the correct number yet." self.assertTrue(correct, message) correct = "4" in output message = "What does 2 + 2 equal?" self.assertTrue(correct, message) correct = output == "2 plus 2 is 4" message = "You're not printing the correct statement." self.assertTrue(correct, message) if __name__ == "__main__": tests = TwoPlusTwoStatementTests() tests.test_default_case()