8 FILE_PATH = os.path.dirname(os.path.realpath(__file__))
9 INTEGRATION_TEST_DIRECTORY_PATH = os.path.join(FILE_PATH, 'integration_tests')
12 integration_test_file_names = [
14 for fn in os.listdir(INTEGRATION_TEST_DIRECTORY_PATH) \
15 if fn.endswith('.stt')
18 C_SOURCE_FILE_PATH = os.path.join(FILE_PATH, 'a.c')
19 BINARY_PATH = os.path.join(FILE_PATH, 'a.out')
21 def generate_test(input_file_name):
22 input_file_path = os.path.join(INTEGRATION_TEST_DIRECTORY_PATH, input_file_name)
23 expected_output_file_path = input_file_path[:-4] + '.txt'
26 c_source = subprocess.check_output(['python','stutter.py',input_file_path])
28 self.assertIsNotNone(c_source)
29 self.assertNotEqual(0, len(c_source))
31 with open(C_SOURCE_FILE_PATH,'wb') as c_source_file:
32 c_source_file.write(c_source)
34 cc_result = subprocess.call([CC, C_SOURCE_FILE_PATH])
36 self.assertEqual(0, cc_result)
38 with open(expected_output_file_path, 'rb') as expected_output_file:
39 expected_output = expected_output_file.read()
41 actual_output = subprocess.check_output(BINARY_PATH)
43 self.assertEqual(expected_output, actual_output)
47 class IntegrationTests(unittest.TestCase):
50 os.remove(C_SOURCE_FILE_PATH)
53 if e.errno != errno.ENOENT:
57 os.remove(BINARY_PATH)
60 if e.errno != errno.ENOENT:
63 for integration_test_file_name in integration_test_file_names:
64 test = generate_test(integration_test_file_name)
65 test_name = 'test_{}'.format(integration_test_file_name[:-4])
66 setattr(IntegrationTests, test_name, test)