def atest_normalize_parse_tree(self): num_matches = 0 for parse_tree, s, e in NVDParser.entryRegion.scanString(self.nvd_data1): #pprint.pprint(parse_tree.asList()) num_matches = num_matches + 1 nparse_tree = NVDParser.normalizeParseTree(parse_tree.asList()) #pprint.pprint(nparse_tree) self.assertEqual(num_matches, 2) num_matches = 0 for parse_tree, s, e in NVDParser.nvdRegion.scanString(self.nvd_data1): #pprint.pprint(parse_tree.asList()) num_matches = num_matches + 1 nparse_tree = NVDParser.normalizeParseTree(parse_tree.asList()) #pprint.pprint(nparse_tree) self.assertEqual(num_matches, 1)
def test_get_region_id(self): # Write NVD tests for entry and cpss and score parser = NVDParser() expected_ids = {'score': ['1', '2'], 'entry': ['CVE-2012-0001', 'CVE-2012-0002']} for region_type in expected_ids.keys(): production = parser.getGrammarForUnit(region_type) match_forest = production.scanString(self.nvd_data1) ids = [] subtree_idx = 0 for subtree, s, e in match_forest: new_id = parser.getRegionID(subtree, region_type, subtree_idx) ids.append(new_id) subtree_idx = subtree_idx + 1 i = 0 for id in ids: self.assertEqual(id, expected_ids[region_type][i]) i = i + 1