def test_unused_validator_fails_validation(): source = LocalFile('vladiate/examples/vampires.csv') validators = { 'Column A': [UniqueValidator()], 'Column B': [SetValidator(['Vampire', 'Not A Vampire'])], 'Column C': [FloatValidator()] } assert not Vlad(source=source, validators=validators).validate()
def test_unused_validator_fails_validation(): source = LocalFile("vladiate/examples/vampires.csv") validators = { "Column A": [UniqueValidator()], "Column B": [SetValidator(["Vampire", "Not A Vampire"])], "Column C": [FloatValidator()], } assert not Vlad(source=source, validators=validators).validate()
def perform_batch_validation(filename): validators = { 'FILENAME': [NotEmptyValidator()], 'SEQ': [SetValidator(valid_set=["*..*", "*.*"])], 'COMPOUND_NAME': [NotEmptyValidator()], 'MOLECULEMASS': [FloatValidator()], 'INSTRUMENT': [ SetValidator(valid_set=[ "qTof", "QQQ", "Ion Trap", "Hybrid FT", "Orbitrap", "ToF" ]) ], 'IONSOURCE': [SetValidator(valid_set=["LC-ESI", "DI-ESI", "EI", "APCI", "ESI"])], 'EXTRACTSCAN': [IntValidator()], 'SMILES': [], 'INCHI': [], 'INCHIAUX': [], 'CHARGE': [IntValidator()], 'IONMODE': [SetValidator(valid_set=["Positive", "Negative"])], 'PUBMED': [NotEmptyValidator()], 'ACQUISITION': [ SetValidator(valid_set=[ "Crude", "Lysate", "Commercial", "Isolated", "Other" ]) ], 'EXACTMASS': [FloatValidator()], 'DATACOLLECTOR': [NotEmptyValidator()], 'ADDUCT': [NotEmptyValidator()], 'INTEREST': [], 'LIBQUALITY': [SetValidator(valid_set=["1", "2", "3"])], 'GENUS': [], 'SPECIES': [], 'STRAIN': [], 'CASNUMBER': [NotEmptyValidator()], 'PI': [NotEmptyValidator()] } my_validator = Vlad(source=LocalFile(filename), delimiter="\t", ignore_missing_validators=True, validators=validators) passes_validation = my_validator.validate() errors_list = [] for column in my_validator.failures: for line_number in my_validator.failures[column]: error_dict = {} error_dict["header"] = column error_dict[ "line_number"] = line_number + 1 #0 Indexed with 0 being the header row error_dict["error_string"] = str( my_validator.failures[column][line_number]) errors_list.append(error_dict) for missing_field in my_validator.missing_fields: error_dict = {} error_dict["header"] = "Missing Header" error_dict["line_number"] = "N/A" error_dict["error_string"] = "Missing column %s" % (missing_field) errors_list.append(error_dict) valid_rows = [] row_count = 0 #Read in the good rows try: no_validation_lines = [ int(error["line_number"]) for error in errors_list ] row_count = 0 with open(filename) as csvfile: reader = csv.DictReader(csvfile, delimiter="\t") for row in reader: row_count += 1 if row_count in no_validation_lines: continue valid_rows.append(row) except: #raise print("error reading file") return passes_validation, my_validator.failures, errors_list, valid_rows, row_count
def test_float_validator_fails(field): with pytest.raises(ValidationException): FloatValidator().validate(field)
def test_float_validator_works(field): FloatValidator().validate(field)