本文整理汇总了Python中sure.deprecated.that函数的典型用法代码示例。如果您正苦于以下问题:Python that函数的具体用法?Python that怎么用?Python that使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了that函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_that_checking_each_matches
def test_that_checking_each_matches():
"that(iterable).in_each('').equals('value')"
class animal(object):
def __init__(self, kind):
self.attributes = {"class": "mammal", "kind": kind}
animals = [animal("dog"), animal("cat"), animal("cow"), animal("cow"), animal("cow")]
assert animals[0].attributes["kind"] != "cow"
assert animals[1].attributes["kind"] != "cow"
assert animals[2].attributes["kind"] == "cow"
assert animals[3].attributes["kind"] == "cow"
assert animals[4].attributes["kind"] == "cow"
assert animals[0].attributes["class"] == "mammal"
assert animals[1].attributes["class"] == "mammal"
assert animals[2].attributes["class"] == "mammal"
assert animals[3].attributes["class"] == "mammal"
assert animals[4].attributes["class"] == "mammal"
assert that(animals).in_each("attributes['class']").matches("mammal")
assert that(animals).in_each("attributes['class']").matches(["mammal", "mammal", "mammal", "mammal", "mammal"])
assert that(animals).in_each("attributes['kind']").matches(["dog", "cat", "cow", "cow", "cow"])
try:
assert that(animals).in_each("attributes['kind']").matches(["dog"])
assert False, "should not reach here"
except AssertionError as e:
assert that(text_type(e)).equals(
"%r has 5 items, but the matching list has 1: %r" % (["dog", "cat", "cow", "cow", "cow"], ["dog"])
)
示例2: test_that_something_iterable_matches_another
def test_that_something_iterable_matches_another():
"that(something_iterable).matches(another_iterable)"
KlassOne = type('KlassOne', (object,), {})
KlassTwo = type('KlassTwo', (object,), {})
one = [
("/1", KlassOne),
("/2", KlassTwo),
]
two = [
("/1", KlassOne),
("/2", KlassTwo),
]
assert that(one).matches(two)
assert that(one).equals(two)
def fail_1():
assert that(range(1)).matches(xrange(2))
class Fail2(object):
def __init__(self):
assert that(xrange(1)).matches(range(2))
class Fail3(object):
def __call__(self):
assert that(xrange(1)).matches(range(2))
assert that(fail_1).raises('X is a list and Y is a xrange instead')
assert that(Fail2).raises('X is a xrange and Y is a list instead')
assert that(Fail3()).raises('X is a xrange and Y is a list instead')
示例3: test_that_something_iterable_matches_another
def test_that_something_iterable_matches_another():
"that(something_iterable).matches(another_iterable)"
# types must be unicode in py3, bute bytestrings in py2
KlassOne = type("KlassOne" if PY3 else b"KlassOne", (object,), {})
KlassTwo = type("KlassTwo" if PY3 else b"KlassTwo", (object,), {})
one = [("/1", KlassOne), ("/2", KlassTwo)]
two = [("/1", KlassOne), ("/2", KlassTwo)]
assert that(one).matches(two)
assert that(one).equals(two)
def fail_1():
assert that([1]).matches(xrange(2))
class Fail2(object):
def __init__(self):
assert that(xrange(1)).matches([2])
class Fail3(object):
def __call__(self):
assert that(xrange(1)).matches([2])
xrange_name = xrange.__name__
assert that(fail_1).raises("X is a list and Y is a {0} instead".format(xrange_name))
assert that(Fail2).raises("X is a {0} and Y is a list instead".format(xrange_name))
assert that(Fail3()).raises("X is a {0} and Y is a list instead".format(xrange_name))
示例4: test_that_len_greater_than_should_raise_assertion_error
def test_that_len_greater_than_should_raise_assertion_error():
"that() len_greater_than(number) raise AssertionError"
lst = list(range(1000))
try:
that(lst).len_greater_than(1000)
except AssertionError as e:
assert_equals(str(e), "the length of the list should be greater then %d, but is %d" % (1000, 1000))
示例5: test_that_len_lower_than_or_equals_should_raise_assertion_error
def test_that_len_lower_than_or_equals_should_raise_assertion_error():
"that() len_lower_than_or_equals(number) raise AssertionError"
lst = list(range(1000))
try:
that(lst).len_lower_than_or_equals(100)
except AssertionError as e:
assert_equals(str(e), "the length of %r should be lower then or equals %d, but is %d" % (lst, 100, 1000))
示例6: test_that_len_is
def test_that_len_is():
"that() len_is(number)"
lst = range(1000)
assert that(lst).len_is(1000)
assert len(lst) == 1000
assert that(lst).len_is(lst)
示例7: test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher
def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher():
u"that.is_a_matcher should absorb callables to be used as matcher"
@that.is_a_matcher
def is_truthful(what):
assert bool(what), '%s is so untrue' % (what)
return 'foobar'
assert that('friend').is_truthful()
assert_equals(that('friend').is_truthful(), 'foobar')
示例8: test_that_len_greater_than
def test_that_len_greater_than():
"that() len_greater_than(number)"
lst = range(1000)
lst2 = range(100)
assert that(lst).len_greater_than(100)
assert len(lst) == 1000
assert that(lst).len_greater_than(lst2)
示例9: test_that_len_lower_than
def test_that_len_lower_than():
"that() len_lower_than(number)"
lst = list(range(100))
lst2 = list(range(1000))
assert that(lst).len_lower_than(101)
assert len(lst) == 100
assert that(lst).len_lower_than(lst2)
示例10: test_get_argv_options_integration
def test_get_argv_options_integration(context):
u"Nose should parse sys.argv and figure out whether to run as integration"
sys.argv = ['./manage.py', 'test', '--integration']
runner = Nose()
opts = runner.get_argv_options()
assert that(opts['is_unit']).equals(False)
assert that(opts['is_functional']).equals(False)
assert that(opts['is_integration']).equals(True)
示例11: test_get_argv_options_simple
def test_get_argv_options_simple(context):
u"Nose should parse sys.argv"
sys.argv = ['./manage.py', 'test']
runner = Nose()
opts = runner.get_argv_options()
assert that(opts['is_unit']).equals(False)
assert that(opts['is_functional']).equals(False)
assert that(opts['is_integration']).equals(False)
示例12: mock_get_paths_for
def mock_get_paths_for(names, appending):
k = expected_kinds.pop(0)
assert that(names).is_a(list)
assert that(appending).is_a(list)
assert that(names).equals(['john', 'doe'])
assert that(appending).equals(['tests', k])
return [
'/apps/john/tests/%s' % k,
'/apps/doe/tests/%s' % k,
]
示例13: test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher
def test_that_is_a_matcher_should_absorb_callables_to_be_used_as_matcher():
"that.is_a_matcher should absorb callables to be used as matcher"
@that.is_a_matcher
def is_truthful(what):
assert bool(what), "%s is so untrue" % (what)
return "foobar"
assert that("friend").is_truthful()
assert_equals(that("friend").is_truthful(), "foobar")
示例14: test_that_len_greater_than_or_equals_should_raise_assertion_error
def test_that_len_greater_than_or_equals_should_raise_assertion_error():
"that() len_greater_than_or_equals(number) raise AssertionError"
lst = range(1000)
try:
that(lst).len_greater_than_or_equals(1001)
except AssertionError, e:
assert_equals(
str(e),
'the length of %r should be greater then or equals %d, but is %d' \
% (lst, 1001, 1000))
示例15: test_that_len_lower_than_or_equals
def test_that_len_lower_than_or_equals():
"that() len_lower_than_or_equals(number)"
lst = list(range(1000))
lst2 = list(range(1001))
assert that(lst).len_lower_than_or_equals(1001)
assert that(lst).len_lower_than_or_equals(1000)
assert len(lst) == 1000
assert that(lst).len_lower_than_or_equals(lst2)
assert that(lst).len_lower_than_or_equals(lst)