本文整理汇总了Python中sure.old.AssertionHelper类的典型用法代码示例。如果您正苦于以下问题:Python AssertionHelper类的具体用法?Python AssertionHelper怎么用?Python AssertionHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AssertionHelper类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: within
def within(self, first, *rest):
if isinstance(first, Iterable):
collection_should = AssertionHelper(first)
else:
args = [first] + list(rest)
collection_should = AssertionHelper(range(*args))
if self.negative:
return collection_should.does_not_contain(self.obj)
else:
return collection_should.contains(self.obj)
开发者ID:spulec,项目名称:sure,代码行数:11,代码来源:__init__.py
示例2: throw
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)
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:15,代码来源:__init__.py
示例3: __init__
def __init__(self, name=None, negative=False, obj=None):
self._name = name
self.negative = negative
self.obj = obj
self._callable_args = []
self._callable_kw = {}
self._that = AssertionHelper(self.obj)
开发者ID:grigi,项目名称:sure,代码行数:7,代码来源:__init__.py
示例4: __call__
def __call__(self, obj):
self.obj = obj
if isinstance(obj, self.__class__):
self.obj = obj.obj
self._that = AssertionHelper(self.obj)
return self
开发者ID:spulec,项目名称:sure,代码行数:8,代码来源:__init__.py
示例5: cool
def cool(self):
_that = AssertionHelper(self.obj,
with_args=self._callable_args,
and_kwargs=self._callable_kw)
if self.negative:
try:
return _that.raises(Exception)
except AssertionError:
raise AssertionError('The callable `{0}` was supposed to not be cool and throw an exception, but it is too cool for that'.format(self.obj.__name__))
try:
self.obj(*self._callable_args, **self._callable_kw)
except Exception as e:
raise AssertionError('The callable `{2}` should be cool but threw {0}: {1}'.format(
e.__class__.__name__,
str(e),
self.obj.__name__
))
return True
开发者ID:GbalsaC,项目名称:bitnamiP,代码行数:20,代码来源:__init__.py
示例6: within
def within(self, first, *rest):
if isinstance(first, Iterable):
collection_should = AssertionHelper(first)
if self.negative:
return collection_should.does_not_contain(self.obj)
else:
return collection_should.contains(self.obj)
elif len(rest) == 1:
return self.within_range(first, rest[0])
else:
if self.negative:
ppath = '{0}.should_not.be.within'.format(self.obj)
else:
ppath = '{0}.should.be.within'.format(self.obj)
raise AssertionError((
'{0}({1}, {2}) must be called with either a iterable:\n'
'{0}([1, 2, 3, 4])\n'
'or with a range of numbers:'
'{0}(1, 3000)'
).format(ppath, first, ", ".join([repr(x) for x in rest])))
开发者ID:adamchainz,项目名称:sure,代码行数:22,代码来源:__init__.py
示例7: AssertionBuilder
class AssertionBuilder(object):
def __init__(self, name=None, negative=False):
self._name = name
self.negative = negative
self._callable_args = []
self._callable_kw = {}
def __call__(self, obj):
self.obj = obj
if isinstance(obj, self.__class__):
self.obj = obj.obj
self._that = AssertionHelper(self.obj)
return self
def __getattr__(self, attr):
special_case = False
special_case = attr in (POSITIVES + NEGATIVES)
self.negative = attr in NEGATIVES
if attr in POSITIVES:
self.negative = False
special_case = True
if attr in NEGATIVES:
self.negative = True
special_case = True
if special_case:
return self
return super(AssertionBuilder, self).__getattribute__(attr)
@assertionproperty
def callable(self):
if self.negative:
assert not callable(self.obj), (
'expected `{0}` to not be callable but it is'.format(safe_repr(self.obj)))
else:
assert callable(self.obj), (
'expected {0} to be callable'.format(safe_repr(self.obj)))
return True
@assertionproperty
def be(self):
return self
@assertionproperty
def being(self):
return self
@assertionproperty
def not_being(self):
return self.should_not
@assertionproperty
def not_be(self):
return self.obj.should_not
@assertionproperty
def not_have(self):
return self.obj.should_not
@assertionproperty
def to_not(self):
return self.obj.should_not
@assertionproperty
def to(self):
return self
@assertionproperty
def when(self):
return self
@assertionproperty
def have(self):
return self
@assertionproperty
def with_value(self):
return self
def property(self, name):
has_it = hasattr(self.obj, name)
if self.negative:
assert not has_it, (
'%r should not have the property `%s`, '
'but it is %r' % (self.obj, name, getattr(self.obj, name)))
return True
assert has_it, (
"%r should have the property `%s` but doesn't" % (
self.obj, name))
return expect(getattr(self.obj, name))
def key(self, name):
#.........这里部分代码省略.........
开发者ID:spulec,项目名称:sure,代码行数:101,代码来源:__init__.py
示例8: AssertionBuilder
class AssertionBuilder(object):
def __init__(self, name=None, negative=False, obj=None, callable_args=None, callable_kw=None):
self._name = name
self.negative = negative
self.obj = obj
self._callable_args = callable_args or []
self._callable_kw = callable_kw or {}
self._that = AssertionHelper(self.obj)
def __call__(self, obj):
self.obj = obj
if isinstance(obj, self.__class__):
self.obj = obj.obj
self._callable_args = obj._callable_args
self._callable_kw = obj._callable_kw
self._that = AssertionHelper(self.obj)
return self
def __getattr__(self, attr):
special_case = False
special_case = attr in (POSITIVES + NEGATIVES)
negative = attr in NEGATIVES
if special_case:
return AssertionBuilder(attr, negative=negative, obj=self.obj,
callable_args=self._callable_args, callable_kw=self._callable_kw)
return super(AssertionBuilder, self).__getattribute__(attr)
@assertionproperty
def callable(self):
if self.negative:
assert not callable(self.obj), (
'expected `{0}` to not be callable but it is'.format(safe_repr(self.obj)))
else:
assert callable(self.obj), (
'expected {0} to be callable'.format(safe_repr(self.obj)))
return True
@assertionproperty
def be(self):
return IdentityAssertion(self)
being = be
@assertionproperty
def not_be(self):
return IdentityAssertion(self.should_not)
not_being = not_be
@assertionproperty
def not_have(self):
return self.should_not
@assertionproperty
def to_not(self):
return self.should_not
@assertionproperty
def to(self):
return self
which = to
@assertionproperty
def when(self):
return self
@assertionproperty
def have(self):
return self
@assertionproperty
def with_value(self):
return self
def property(self, name):
has_it = hasattr(self.obj, name)
if self.negative:
assert not has_it, (
'%r should not have the property `%s`, '
'but it is %r' % (self.obj, name, getattr(self.obj, name)))
return True
assert has_it, (
"%r should have the property `%s` but does not" % (
self.obj, name))
return expect(getattr(self.obj, name))
def key(self, name):
has_it = name in self.obj
if self.negative:
assert not has_it, (
#.........这里部分代码省略.........
开发者ID:adamchainz,项目名称:sure,代码行数:101,代码来源:__init__.py
示例9: AssertionBuilder
class AssertionBuilder(object):
def __init__(self, name=None, negative=False, obj=None):
self._name = name
self.negative = negative
self.obj = obj
self._callable_args = []
self._callable_kw = {}
self._that = AssertionHelper(self.obj)
def __call__(self, obj):
self.obj = obj
if isinstance(obj, self.__class__):
self.obj = obj.obj
self._that = AssertionHelper(self.obj)
return self
def __getattr__(self, attr):
special_case = False
special_case = attr in (POSITIVES + NEGATIVES)
negative = attr in NEGATIVES
if special_case:
return AssertionBuilder(attr, negative=negative, obj=self.obj)
return super(AssertionBuilder, self).__getattribute__(attr)
@assertionproperty
def callable(self):
if self.negative:
assert not callable(self.obj), "expected `{0}` to not be callable but it is".format(safe_repr(self.obj))
else:
assert callable(self.obj), "expected {0} to be callable".format(safe_repr(self.obj))
return True
@assertionproperty
def be(self):
import os
if os.getenv("DEBUG"):
import ipdb
ipdb.set_trace()
return IdentityAssertion(self)
being = be
@assertionproperty
def not_be(self):
return IdentityAssertion(self.should_not)
not_being = not_be
@assertionproperty
def not_have(self):
return self.should_not
@assertionproperty
def to_not(self):
return self.should_not
@assertionproperty
def to(self):
return self
@assertionproperty
def when(self):
return self
@assertionproperty
def have(self):
return self
@assertionproperty
def with_value(self):
return self
def property(self, name):
has_it = hasattr(self.obj, name)
if self.negative:
assert not has_it, "%r should not have the property `%s`, " "but it is %r" % (
self.obj,
name,
getattr(self.obj, name),
)
return True
assert has_it, "%r should have the property `%s` but does not" % (self.obj, name)
return expect(getattr(self.obj, name))
def key(self, name):
has_it = name in self.obj
if self.negative:
assert not has_it, "%r should not have the key `%s`, " "but it is %r" % (self.obj, name, self.obj[name])
return True
#.........这里部分代码省略.........
开发者ID:CyrilRoelandteNovance,项目名称:sure,代码行数:101,代码来源:__init__.py
注:本文中的sure.old.AssertionHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论