def process_block(self, block): if block.type == block_pb2.BODY: return conformance_validators.validate_node( self.node, block.rows, 0, block.number, block.file_number) else: # For now we do not validate the header return 0
def test_validate_node_valid(self): one_valid_row = [RowTest('c', 4)] two_valid_rows = [RowTest('a', 1), RowTest('b', 2)] three_valid_rows = [RowTest('a', 1), RowTest('b', 2), RowTest('c', 3)] self.assertEquals( conformance_validators.validate_node( self.root, one_valid_row, index=0, block_number=4, file_number=3), 1) self.assertEquals( conformance_validators.validate_node( self.root, two_valid_rows, 0, 3, 2), 2) self.assertEquals( conformance_validators.validate_node( self.root, three_valid_rows, index=0, block_number=5, file_number=1), 3)
def test_validate_node_invalid_row(self): one_invalid_rows = [RowTest('a', 5)] expected_error = textwrap.dedent(r""" Block 4 starting on row 5 in file number 8 is non-conformant\. First invalid row: 1 \(row 6 in input file\). Expected structure: \[Sequence \(a and b\) or c\]\+ Actual structure: \['a'\] """).lstrip() with six.assertRaisesRegex(self, error.BlockConformanceFailure, expected_error): conformance_validators.validate_node(self.root, one_invalid_rows, 0, 4, 8)
def test_validate_node_valid(self): one_valid_row = [RowTest('c', 4)] two_valid_rows = [RowTest('a', 1), RowTest('b', 2)] three_valid_rows = [RowTest('a', 1), RowTest('b', 2), RowTest('c', 3)] self.assertEqual( conformance_validators.validate_node(self.root, one_valid_row, index=0, block_number=4, file_number=3), 1) self.assertEqual( conformance_validators.validate_node(self.root, two_valid_rows, 0, 3, 2), 2) self.assertEqual( conformance_validators.validate_node(self.root, three_valid_rows, index=0, block_number=5, file_number=1), 3)