test_validation.py (1317B)
1 from ratchets import validate 2 import os 3 4 5 def test_validate_regex(): 6 current_file_directory = os.path.dirname(os.path.abspath(__file__)) 7 toml_file_directory_valid = os.path.abspath( 8 os.path.join(current_file_directory, "..", "toml_files/regexp/valid") 9 ) 10 toml_file_directory_invalid = os.path.abspath( 11 os.path.join(current_file_directory, "..", "toml_files/regexp/invalid") 12 ) 13 14 for filename in os.listdir(toml_file_directory_valid): 15 full_path = os.path.abspath(os.path.join(toml_file_directory_valid, filename)) 16 if os.path.isfile(full_path): 17 try: 18 # Throws if not valid 19 validate.validate(full_path) 20 except Exception as e: 21 assert False, f"{full_path}, was deemed to be invalid \n {e}" 22 23 for filename in os.listdir(toml_file_directory_invalid): 24 full_path = os.path.abspath(os.path.join(toml_file_directory_invalid, filename)) 25 26 if os.path.isfile(full_path): 27 try: 28 validate.validate(full_path) 29 except Exception: 30 pass 31 else: 32 assert ( 33 False 34 ), f"Expected validation to fail for {full_path}, but it passed" 35 36 37 if __name__ == "__main__": 38 test_validate_regex()