def test_grammar(service_name): print('Testing grammar for service \'{0}\'...'.format(service_name)) try: grammar = get_grammar_for_service(service_name) except ValueError as e: print 'Error: {}'.format(e.args[0]) return all_examples = parse_examples() ex_total = 0 counter_ex_total = 0 hits = 0 misses = 0 for key, examples in all_examples.iteritems(): if key == service_name: ex_total += len(examples) for example in examples: parse_tree = parse(example, grammar) if parse_tree: # pprint(parse_tree) # print example hits += 1 else: print '>', example else: counter_ex_total += len(examples) for counterexample in examples: if parse(counterexample, grammar): misses += 1 print 'X', counterexample print('Success:\t\t{0}/{1}'.format(hits, ex_total)) print('False Positives:\t{0}/{1}'.format(misses, counter_ex_total))
def __init__(self): self.grammar = get_grammar_for_service(self.__class__.short_name()) self.cached_parse = None
def __init__(self): super(self.__class__, self).__init__() self.grammar = get_grammar_for_service(self.__class__.short_name()) self.cached_parse = None