import unittest import subprocess import interweave # TestInterweave is a class that inherits from unittest.TestCase class TestInterweave(unittest.TestCase): # setUp is a method that is run before each test def setUp(self): #add files paths for the fixture files self.file1 = "fixtures/file1.txt" self.file2 = "fixtures/file2.txt" self.file3 = "fixtures/file3.txt" self.file4 = "fixtures/file4.txt" self.output_file = "output.txt" self.expected_file = "expected.txt" #set the maximum difference to None, big file self.maxDiff = None # test_interweave is a method that tests the interweave function def test_interweave(self): #run the test self.run_test() #compare the output to the expected output self.compare_output() # run_test is a method that runs the command to interweave the files def run_test(self): #run the command to interweave the files subprocess.call(["python3", "interweave.py", self.file1, self.file2, self.file3, self.file4, self.output_file]) # compare_output is a method that compares the output file to the expected output file def compare_output(self): #open the output file output = open(self.output_file, "r") output_contents = output.read() #close the output file output.close() #open the expected output file expected = open(self.expected_file, "r") expected_contents = expected.read() #close the expected output file expected.close() #compare the output to the expected output self.assertEqual(output_contents, expected_contents) # run the tests if __name__ == '__main__': unittest.main()