def test_write(self): analyzer = TestRunsAnalyzer(self.input_path[0], self.input_path[1], self.input_path[2]) analyzer.write_output(self.output_path) test_logs = read_file(self.output_path) self.assertEqual(len(test_logs[logs]), 2) validate(test_logs, schema_output)
def test_parse(self): analyzer = TestRunsAnalyzer(self.input_path[0], self.input_path[1], self.input_path[2]) test_logs = analyzer.test_runs self.assertEqual(len(test_logs), 2) self.assertTrue( validate({logs: list(test_logs.values())}, schema_output))
def __init__(self, path1, path2, path3): inputs = [read_file(path1), read_file(path2), read_file(path3)] # validating input according to schemas for i in range(0, len(inputs)): if not validate(inputs[i], schema_input[i]): print('Invalid input schema') return if inputs is not None: self.parse_first_file(inputs[0]) self.parse_second_file(inputs[1]) self.parse_third_file(inputs[2])
def write_output(self, path: str): """ Validate output to output object schema and write it to file :param path: Path to file """ if len(self.test_runs) == 0: print('Empty input') return with open(path, 'w') as file: output_str = {logs: list(self.test_runs.values())} if not validate(output_str, schema_output): print('Invalid output schema!') return file.write(json.dumps(output_str))
def test_validate(self): # Test if values are successfully validated. self.assertTrue(app.validate("01/01/2019", datetime)) self.assertTrue(app.validate("1", int)) self.assertTrue(app.validate("string", str)) # The following inputs are needed to confirm the error messages. self.test_values = (value for value in ["x", "x", "x"]) with patch("builtins.input", self.mock_input): self.assertFalse(app.validate("x", int)) self.assertFalse(app.validate("x", datetime)) self.assertFalse(app.validate(5, int, (1, 2)))
def test_validate(): print("hello") result = validate("2018-06-25") assert result == True
def test_validate(): # only validating the date result = validate('2018-06-24') assert result == true