def should_not_be_same(self, expected, msg=None): """Fail if the two objects are different as determined by the 'is' operator. """ from re import search global ignore_stack ignore_stack = True source = compat_ironpython.get_source_code() if source is None: match1 = None match2 = None else: m = search(r"About\((.*?)\).should_not_be_same\((.*?)\)", source) match1 = m.group(1) match2 = m.group(2) if expected is self.actual: try: msg = "%s should not be same %s, but equal." % \ (self._source(match1, self.actual), \ self._source(match2, expected)) except: msg = "%s should not be same %s, but equal." % \ (self.actual, expected) ignore_stack = False raise AssertionError(msg) try: msg = "%s(id=%d) should not be same %s(id=%d)." % \ (self._source(match1, self.actual), id(self.actual), \ self._source(match2, expected), id(expected)) except: msg = "%s(id=%d) should not be same %s(id=%d)." % \ (self.actual, id(self.actual), expected, id(expected)) self._write((source, msg)) ignore_stack = False
def should_include(self, expected, msg=None): from re import search global ignore_stack ignore_stack = True source = compat_ironpython.get_source_code() if source is None: match1 = None match2 = None else: m = search(r"About\((.*?)\).should_include\((.*?)\)", source) match1 = m.group(1) match2 = m.group(2) if (not hasattr(self.actual, "__contains__") and not hasattr(self.actual, "__iter__")): msg = "%s should have __contains__ or __iter__ method." % \ self._value_with_source(match1, self.actual) ignore_stack = False raise TypeError(msg) elif not expected in self.actual: msg = "%s should include %s, but didn't." % \ (self._value_with_source(match1, self.actual), \ self._value_with_source(match2, expected)) ignore_stack = False raise AssertionError(msg) msg = "%s should include %s." % \ (self._value_with_source(match1, self.actual), \ self._value_with_source(match2, expected)) self._write((source, msg)) ignore_stack = False
def _get_target(): import re source = compat_ironpython.get_source_code(3) if source is None: return None match = re.search(r"About\((.*?)\).should", source) if match: return match.group(1) return None