def main(data_file='examples/flat_data.dat', config_file='examples/config.json'): configuration = {} try: configuration = load_configuration(config_file) except IOError: logging.error("Cannot open file: %s" % config_file) exit() data = [] try: data = load_data_file(data_file) except IOError: logging.error("Cannot open file: %s" % data_file) exit() data_object = Data(data, configuration) validator = Validator() validator.validate_data(data_object)
def test_validate_data(self): # given def return_value(data): if data.get_fields()[0].get_value() == 'test': return False else: return True validator = Validator() validator.validate_record = MagicMock(side_effect=return_value) data = Data(['test', 'test2']) expected_calls = [call(record) for record in data.get_records()] # when result = validator.validate_data(data) # then self.assertFalse(result) validator.validate_record.assert_has_calls(expected_calls) self.assertEqual(validator.validate_record.call_count, 2)