class PreprocessScopeParser: ####################################################### def __init__(self, file, pp_scope, parser, elem_parser_cls, parent): self.pp_scope = pp_scope self.file = file self.parser = parser self.container = TestScope(pp_scope.get_inst(), pp_scope.get_expr(), parent) self.elem_parser = elem_parser_cls(file, parser, self.container) self.elem_parser_cls = elem_parser_cls ####################################################### def parse_scope(self, scope): return PreprocessScopeParser(self.file, scope, self.parser, self.elem_parser_cls, self.container).parse() ####################################################### def parse(self): for line in self.pp_scope.get_lines(): self.elem_parser.parse_line(line) if self.elem_parser.incompleted_elem_def(): fatal( self.file, self.pp_scope.get_lines()[-1], "incompleted " + self.parser.get_type_name() + " definition" ) for scope in self.elem_parser.get_unhandled_sub_scopes(): self.container.add_sub_scope(self.parse_scope(scope)) for scope in self.pp_scope.get_elses(): self.container.add_sibling(self.parse_scope(scope)) return self.container
class PreprocessScopeParser: ####################################################### def __init__(self, file, pp_scope, parser, elem_parser_cls, parent): self.pp_scope = pp_scope self.file = file self.parser = parser self.container = TestScope(pp_scope.get_inst(), pp_scope.get_expr(), parent) self.elem_parser = elem_parser_cls(file, parser, self.container) self.elem_parser_cls = elem_parser_cls ####################################################### def parse_scope(self, scope): return PreprocessScopeParser(self.file, \ scope, self.parser, \ self.elem_parser_cls, \ self.container).parse() ####################################################### def parse(self): for line in self.pp_scope.get_lines(): self.elem_parser.parse_line(line) if self.elem_parser.incompleted_elem_def(): fatal(self.file, self.pp_scope.get_lines()[-1], \ "incompleted " + self.parser.get_type_name() + " definition") for scope in self.elem_parser.get_unhandled_sub_scopes(): self.container.add_sub_scope(self.parse_scope(scope)) for scope in self.pp_scope.get_elses(): self.container.add_sibling(self.parse_scope(scope)) return self.container
class Fixture: ######################################## def __init__(self, name, file, line, annotations): self.prefix = name[0] self.id = name[1] self.name = name[2] if self.name != None: self.name = escape_name(self.name) self.scope = TestScope("::", None, None) self.file = file self.line = line annotation = None if len(annotations) > 0 : annotation = annotations[0] self.annotations = AnnotationParser(annotation, {"memcheck":None, "tags":[]}).parse() self.annotations['tags'] = TagsParser(self.annotations['tags']).parse() ######################################## def find_data_provider(self, name): return self.scope.find_data_provider(name) ######################################## def get_tags(self): return self.annotations['tags'] ######################################## def get_memcheck_switch(self): return self.annotations['memcheck'] ######################################## def show(self): content = "FIXTURE("+self.get_name()+")" print content.encode('utf-8') self.scope.show() ######################################## def set_scope(self, scope): pass ######################################## def get_id(self): return self.prefix + self.id ######################################## def get_name(self): if self.name: return self.name return self.id ######################################## def merge(self, scope): self.scope.merge(scope) ######################################## def add_elem(self, testcase): self.scope.add_elem(testcase) ######################################## def add_sub_scope(self, scope): self.scope.add_sub_scope(scope) ######################################## def get_scope(self): return self.scope ######################################## def get_file_name(self): return self.file ######################################## def get_line_number(self): return self.line
class Fixture: ######################################## def __init__(self, name, file, line, tag): self.prefix = name[0] self.id = name[1] self.name = name[2] if self.name != None: self.name = escape_name(self.name) self.scope = TestScope("::", None, None) self.file = file self.line = line self.annotations = AnnotationParser(tag, {"tags": []}).parse() self.annotations["tags"] = TagsParser(self.annotations["tags"]).parse() ######################################## def get_tags(self): return self.annotations["tags"] ######################################## def show(self): content = "FIXTURE(" + self.get_name() + ")" print content.encode("utf-8") self.scope.show() ######################################## def set_scope(self, scope): pass ######################################## def get_id(self): return self.prefix + self.id ######################################## def get_name(self): if self.name: return self.name return self.id ######################################## def merge(self, scope): self.scope.merge(scope) ######################################## def add_elem(self, testcase): self.scope.add_elem(testcase) ######################################## def add_sub_scope(self, scope): self.scope.add_sub_scope(scope) ######################################## def get_scope(self): return self.scope ######################################## def get_file_name(self): return self.file ######################################## def get_line_number(self): return self.line