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 CubeTests(unittest.TestCase): def test_default_case(self): function = main.cube with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout: function() output = fake_stdout.getvalue().strip() source_code = inspect.getsource(function) correct = "125" in output message = "You don't have the correct number for the volume." self.assertTrue(correct, message) correct = "side = 5" in source_code message = "It looks like you modified the first line." self.assertTrue(correct, message) correct = 'print("The volume of a cube with sides of length", side, "is", volume)' in source_code message = "It looks like you modified the last line." self.assertTrue(correct, message) correct = output == "The volume of a cube with sides of length 5 is 125" message = "You're not printing the correct statement." self.assertTrue(correct, message) if __name__ == "__main__": tests = CubeTests() tests.test_default_case()