def assert_regex_contains(self, pattern, string, flags=None): flags = flags or 0 pattern = to_unicode(pattern) string = to_unicode(string) diagnostic = u'"%s" not found in "%s"' % (pattern, string) self.assertTrue( re.search(pattern, string, flags) is not None, diagnostic)
def _step_visit(self, node): if self._scenario_exception: return self._suite.step = node self._steps_num += 1 reconstruction = node.get_real_reconstruction() start_time = time.time() status = 'pass' try: self.run_step(node) except (MissingStepError, AssertionError) as exc: status = 'fail' etype, evalue, etraceback = sys.exc_info() tb = traceback.extract_tb(etraceback)[:-2] fix_exception_encoding(evalue) self._scenario_exception = ( node.parent.get_real_reconstruction() + reconstruction, ''.join(to_unicode(line) for line in traceback.format_list(tb)), ''.join(to_unicode(line) for line in traceback.format_exception_only(etype, evalue)) ) except (SystemExit, Exception) as exc: status = 'error' self._format_exception(node, exc) raise finally: end_time = time.time() duration = end_time - start_time self._formatter.output(node, reconstruction, status, duration)
def format_fault(self, diagnostic): parent_reconstruction = '' if self.parent: parent_reconstruction = self.parent.reconstruction().strip('\n') reconstruction = self.reconstruction() args = (self.get_filename(), self.line_number, parent_reconstruction, reconstruction, diagnostic) args = tuple([to_unicode(i) for i in args]) return u'\n File "%s", line %s, in %s\n %s\n%s' % args
def slugify(self, predicate): predicate = to_unicode(predicate) result = [] for part in re.split('[^\w]+', predicate): part = unicodedata.normalize('NFD', part).encode( 'ascii', 'replace').decode('utf-8') part = part.replace(u'??', u'_').replace(u'?', u'') try: float(part) except ValueError: pass else: part = 'number' result.append(part) return '_'.join(result).strip('_')
def parse_feature(self, lines): lines = to_unicode(lines) self._line_producer = LineSource(lines) self._docstring_parser = DocStringParser(self._line_producer) self._language_parser = LanguageParser(default_language=self._language) self._labels_parser = LabelParser() try: while True: line = self._line_producer.get_line() if line: self._parse_line(line) except StopIteration: pass return self.steps
def match(self, predicate, augmented_predicate, step_methods): """See :py:meth:`IStepMatcher.match`.""" for method_name in step_methods: method = self._suite.__getattribute__(method_name) doc = method.__doc__ if not doc: continue doc = to_unicode(doc) doc = re.compile('^' + doc + '$') m = doc.match(augmented_predicate) if m: kwargs = m.groupdict() if not kwargs: args = m.groups() else: args = () return method, args, kwargs return None, (), {}
def assert_regex_contains(self, pattern, string, flags=None): flags = flags or 0 pattern = to_unicode(pattern) string = to_unicode(string) diagnostic = u'"%s" not found in "%s"' % (pattern, string) self.assertTrue(re.search(pattern, string, flags) is not None, diagnostic)
def slugify(self, predicate): predicate = to_unicode(predicate) predicate = unicodedata.normalize('NFD', predicate).encode( 'ascii', 'replace').decode('utf-8') predicate = predicate.replace(u'??', u'_').replace(u'?', u'') return re.sub(u'[^\w]+', u'_', predicate, re.U).strip('_')
def get_real_reconstruction(self): predicate = to_unicode(self._augment_predicate()) recon = u' %s %s' % (self.keyword, predicate) recon += '\n' if recon[-1] != '\n' else '' return recon
def reconstruction(self): predicate = to_unicode(self.predicate) predicate = predicate.replace('\n', '\n ') recon = u'%s%s: %s' % (self.prefix(), self.keyword, predicate) recon += '\n' if recon[-1] != '\n' else '' return recon