本文整理汇总了Python中sure.old.AssertionHelper.looks_like方法的典型用法代码示例。如果您正苦于以下问题:Python AssertionHelper.looks_like方法的具体用法?Python AssertionHelper.looks_like怎么用?Python AssertionHelper.looks_like使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sure.old.AssertionHelper
的用法示例。
在下文中一共展示了AssertionHelper.looks_like方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AssertionBuilder
# 需要导入模块: from sure.old import AssertionHelper [as 别名]
# 或者: from sure.old.AssertionHelper import looks_like [as 别名]
#.........这里部分代码省略.........
@assertionmethod
def length_of(self, num):
if self.negative:
return self._that.len_is_not(num)
return self._that.len_is(num)
def called_with(self, *args, **kw):
self._callable_args = args
self._callable_kw = kw
return self
called = builtins.property(called_with)
@assertionmethod
def throw(self, *args, **kw):
_that = AssertionHelper(self.obj,
with_args=self._callable_args,
and_kwargs=self._callable_kw)
if self.negative:
msg = ("{0} called with args {1} and kwargs {2} should "
"not raise {3} but raised {4}")
exc = args and args[0] or Exception
try:
self.obj(*self._callable_args, **self._callable_kw)
return True
except Exception as e:
err = msg.format(
self.obj,
self._that._callable_args,
self._that._callable_kw,
exc,
e,
)
raise AssertionError(err)
return _that.raises(*args, **kw)
thrown = throw
raised = thrown
@assertionmethod
def return_value(self, value):
return_value = self.obj(*self._callable_args, **self._callable_kw)
return this(return_value).should.equal(value)
returned_the_value = return_value
@assertionmethod
def look_like(self, value):
if self.negative:
try:
self._that.looks_like(value)
except AssertionError:
return True
else:
msg = '%r should not look like %r but does'
raise AssertionError(msg % (self.obj, value))
return self._that.looks_like(value)
@assertionmethod
def contain(self, what):
obj = self.obj
if self.negative:
return expect(what).to.not_be.within(obj)
else:
return expect(what).to.be.within(obj)
@assertionmethod
def match(self, regex, *args):
obj_repr = repr(self.obj)
assert isinstance(self.obj, basestring), (
"{0} should be a string in order to compare using .match()".format(obj_repr)
)
matched = re.search(regex, self.obj, *args)
modifiers_map = {
re.I: "i",
re.L: "l",
re.M: "m",
re.S: "s",
re.U: "u",
}
modifiers = "".join([modifiers_map.get(x, "") for x in args])
regex_representation = '/{0}/{1}'.format(regex, modifiers)
if self.negative:
assert matched is None, (
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
示例2: AssertionBuilder
# 需要导入模块: from sure.old import AssertionHelper [as 别名]
# 或者: from sure.old.AssertionHelper import looks_like [as 别名]
#.........这里部分代码省略.........
def below(self, num):
if self.negative:
msg = "{0} should not be below {1}".format(self.obj, num)
assert not self.obj < num, msg
else:
msg = "{0} should be below {1}".format(self.obj, num)
assert self.obj < num, msg
return True
@assertionmethod
def above(self, num):
if self.negative:
msg = "{0} should not be above {1}".format(self.obj, num)
assert not self.obj > num, msg
else:
msg = "{0} should be above {1}".format(self.obj, num)
assert self.obj > num, msg
return True
@assertionmethod
def length_of(self, num):
if self.negative:
return self._that.len_is_not(num)
return self._that.len_is(num)
@assertionmethod
def called_with(self, *args, **kw):
self._callable_args = args
self._callable_kw = kw
return self
called = builtins.property(called_with)
@assertionmethod
def throw(self, *args, **kw):
_that = AssertionHelper(self.obj, with_args=self._callable_args, and_kwargs=self._callable_kw)
if self.negative:
msg = "{0} called with args {1} and kwargs {2} should " "not raise {3} but raised {4}"
exc = args and args[0] or Exception
try:
self.obj(*self._callable_args, **self._callable_kw)
return True
except Exception as e:
err = msg.format(self.obj, self._that._callable_args, self._that._callable_kw, exc, e)
raise AssertionError(err)
return _that.raises(*args, **kw)
@assertionmethod
def return_value(self, value):
return_value = self.obj(*self._callable_args, **self._callable_kw)
return this(return_value).should.equal(value)
@assertionmethod
def look_like(self, value):
if self.negative:
try:
self._that.looks_like(value)
except AssertionError:
return True
else:
msg = "%r should not look like %r but does"
raise AssertionError(msg % (self.obj, value))
return self._that.looks_like(value)
@assertionmethod
def contain(self, what):
if self.negative:
return expect(what).to.not_be.within(self.obj)
else:
return expect(what).to.be.within(self.obj)
@assertionmethod
def match(self, regex, *args):
obj_repr = repr(self.obj)
assert isinstance(self.obj, basestring), "{0} should be a string in order to compare using .match()".format(
obj_repr
)
matched = re.search(regex, self.obj, *args)
modifiers_map = {re.I: "i", re.L: "l", re.M: "m", re.S: "s", re.U: "u"}
modifiers = "".join([modifiers_map.get(x, "") for x in args])
regex_representation = "/{0}/{1}".format(regex, modifiers)
if self.negative:
assert matched is None, "{0} should not match the regular expression {1}".format(
obj_repr, regex_representation
)
else:
assert matched is not None, "{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation
)
return True