def parse_data(cls, lines): """Give me some lines and I will parse it as data""" data = [] yaml_mode = False yaml_cache = u'' for line in lines: if line.strip() == '---': yaml_mode = True elif line.strip() == '...': data.append(YamlData(yamlish.load(yaml_cache))) yaml_cache = u'' yaml_mode = False else: if yaml_mode: yaml_cache += line + os.linesep else: line = line.rstrip('\r\n') if len(data) > 0 and isinstance(data[-1], basestring): data[-1] += line + os.linesep else: data.append(line + os.linesep) return data
def parse_data(cls, lines): """Give me some lines and I will parse it as data""" data = [] yaml_mode = False yaml_cache = "" for line in lines: if line.strip() == "---": yaml_mode = True elif line.strip() == "...": data.append(YamlData(yamlish.load(yaml_cache))) yaml_cache = "" yaml_mode = False else: if yaml_mode: yaml_cache += line + os.linesep else: line = line.rstrip("\r\n") if len(data) > 0 and isinstance(data[-1], str): data[-1] += line + os.linesep else: data.append(line + os.linesep) return data
def end(self): if not self.yaml: self.yaml = yamlish.load(self._yaml_buffer) self.reporter.end(self)
print("WARNING: {0}".format(msg), file=sys.stderr) def error(msg): global has_failures print("ERROR: {0}".format(msg), file=sys.stderr) has_failures = True # # MAIN # # Open up the test specification. This contains the commands we should run. with open(TEST_SPEC, "r") as spec_file: spec = yamlish.load(spec_file) print("TAP version 13") parser = tap.parser.Parser() test_number = 0 for cmd in spec["commands"]: # Run each command in the shell and capture the output. Standard error is # piped directly to this script's stderr descriptor. p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None) p.stdin.close() print("# << Begin stream for command `{0}`".format(cmd)) stream_end = False
def _parse(self, source): seek_version = True seek_plan = False seek_test = False in_test = False in_yaml = False for line in source: if not seek_version and RE_VERSION.match(line): # refack: breaking TAP13 spec, to allow multiple TAP headers seek_version = True seek_plan = False seek_test = False in_test = False in_yaml = False self.__tests_counter = 0 # raise ValueError("Bad TAP format, multiple TAP headers") if in_yaml: if RE_YAMLISH_END.match(line): self.tests[-1]._yaml_buffer.append(line.strip()) in_yaml = False self.tests[-1].yaml = yamlish.load( self.tests[-1]._yaml_buffer) else: self.tests[-1]._yaml_buffer.append(line.rstrip()) continue line = line.strip() if in_test: if RE_EXPLANATION.match(line): self.tests[-1].diagnostics.append(line) continue if RE_YAMLISH_START.match(line): self.tests[-1]._yaml_buffer = [line.strip()] in_yaml = True continue # this is "beginning" of the parsing, skip all lines until # version is found if seek_version: if RE_VERSION.match(line): seek_version = False seek_plan = True seek_test = True else: continue if seek_plan: m = RE_PLAN.match(line) if m: d = m.groupdict() self.tests_planned = int(d.get("end", 0)) seek_plan = False # Stop processing if tests were found before the plan # if plan is at the end, it must be last line -> stop processing if self.__tests_counter > 0: break if seek_test: m = RE_TEST_LINE.match(line) if m: self.__tests_counter += 1 t_attrs = m.groupdict() if t_attrs["id"] is None: t_attrs["id"] = self.__tests_counter t_attrs["id"] = int(t_attrs["id"]) if t_attrs["id"] < self.__tests_counter: raise ValueError("Descending test id on line: %r" % line) # according to TAP13 specs, missing tests must be handled as # 'not ok' so here we add the missing tests in sequence while t_attrs["id"] > self.__tests_counter: self.tests.append( Test( "not ok", self.__tests_counter, comment="DIAG: Test %s not present" % self.__tests_counter, )) self.__tests_counter += 1 t = Test(**t_attrs) if t.result == "Bail out!": t.result = "not ok" # according to TAP13 specs, everything after this is an # explanation of why testing must be stopped t.diagnostics = t.diagnostics or t.description t.description = "Bail out for Test %s" % self.__tests_counter self.tests.append(t) in_test = True continue if self.tests_planned is None: # TODO: raise better error than ValueError raise ValueError("Missing plan in the TAP source") if len(self.tests) != self.tests_planned: for i in range(len(self.tests), self.tests_planned): t = Test( "not ok", i + 1, description="Test %s missing" % (i + 1), comment="DIAG: Test %s not present" % (i + 1), ) t.yaml = {"severity": "missing", "exitcode": -1} self.tests.append(t)
def _parse(self, source): seek_version = True seek_plan = False seek_test = False in_test = False in_yaml = False for line in source: if not seek_version and RE_VERSION.match(line): # refack: breaking TAP13 spec, to allow multiple TAP headers seek_version = True seek_plan = False seek_test = False in_test = False in_yaml = False self.__tests_counter = 0 # raise ValueError("Bad TAP format, multiple TAP headers") if in_yaml: if RE_YAMLISH_END.match(line): self.tests[-1].yaml_buffer.append(line.strip()) in_yaml = False self.tests[-1].yaml = yamlish.load(self.tests[-1].yaml_buffer) else: self.tests[-1].yaml_buffer.append(line.rstrip()) continue line = line.strip() if in_test: if RE_EXPLANATION.match(line): self.tests[-1].diagnostics.append(line) continue if RE_YAMLISH_START.match(line): self.tests[-1].yaml_buffer = [line.strip()] in_yaml = True continue # this is "beginning" of the parsing, skip all lines until # version is found if seek_version: if RE_VERSION.match(line): seek_version = False seek_plan = True seek_test = True else: continue if seek_plan: m = RE_PLAN.match(line) if m: d = m.groupdict() self.tests_planned = int(d.get('end', 0)) seek_plan = False # Stop processing if tests were found before the plan # if plan is at the end, it must be the last line -> stop processing if self.__tests_counter > 0: break if seek_test: m = RE_TEST_LINE.match(line) if m: self.__tests_counter += 1 t_attrs = m.groupdict() if t_attrs['id'] is None: t_attrs['id'] = self.__tests_counter t_attrs['id'] = int(t_attrs['id']) if t_attrs['id'] < self.__tests_counter: raise ValueError("Descending test id on line: %r" % line) # according to TAP13 specs, missing tests must be handled as 'not ok' # here we add the missing tests in sequence while t_attrs['id'] > self.__tests_counter: self.tests.append(Test('not ok', self.__tests_counter, comment = 'DIAG: Test %s not present' % self.__tests_counter)) self.__tests_counter += 1 t = Test(**t_attrs) self.tests.append(t) in_test = True continue if self.tests_planned is None: # TODO: raise better error than ValueError raise ValueError("Missing plan in the TAP source") if len(self.tests) != self.tests_planned: for i in range(len(self.tests), self.tests_planned): self.tests.append(Test('not ok', i+1, comment = 'DIAG: Test %s not present'))
print("WARNING: {0}".format(msg), file=sys.stderr) def error(msg): global has_failures print("ERROR: {0}".format(msg), file=sys.stderr) has_failures = True # # MAIN # # Open up the test specification. This contains the commands we should run. with open(TEST_SPEC, 'r') as spec_file: spec = yamlish.load(spec_file) print("TAP version 13") parser = tap.parser.Parser() test_number = 0 for cmd in spec['commands']: # Run each command in the shell and capture the output. Standard error is # piped directly to this script's stderr descriptor. p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None) p.stdin.close()