test_files.py (1633B)
1 from ratchets import run_tests 2 from ratchets import abstracted_tests 3 import os 4 import json 5 6 7 def test_files(): 8 """Tests the functionality of .toml and file specification.""" 9 10 proj_root = run_tests.find_project_root() 11 12 file1_path = [os.path.join(proj_root, "tests/file_spec_files/spec_file_1.py")] 13 file2_path = [os.path.join(proj_root, "tests/file_spec_files/spec_file_2.py")] 14 15 filtered1_file = str(abstracted_tests.get_python_files(proj_root, file1_path)[0]) 16 filtered2_file = str(abstracted_tests.get_python_files(proj_root, file2_path)[0]) 17 18 current_file_directory = os.path.dirname(os.path.abspath(__file__)) 19 toml_file_directory = os.path.abspath( 20 os.path.join(current_file_directory, "..", "toml_files") 21 ) 22 toml_file = os.path.join(toml_file_directory, "default.toml") 23 24 exceptions1 = run_tests.evaluate_tests( 25 toml_file, False, False, [filtered1_file], True 26 ) 27 28 exceptions2 = run_tests.evaluate_tests( 29 toml_file, False, False, [filtered2_file], True 30 ) 31 32 json1 = run_tests.results_to_json(exceptions1) 33 json2 = run_tests.results_to_json(exceptions2) 34 35 exception1_sum = 0 36 for key in json1: 37 exception1_sum += json1[key] 38 39 exception2_sum = 0 40 for key in json2: 41 exception2_sum += json2[key] 42 43 assert ( 44 exception2_sum == 8 45 ), f"Incorrect number of infractions counted for {filtered2_file}" 46 assert ( 47 exception1_sum == 6 48 ), f"Incorrect number of infractions counted for {filtered1_file}" 49 50 51 if __name__ == "__main__": 52 """Invoke all tests in the file when called directly.""" 53 test_files()