コード例 #1
0
def test_seq_of_checkonly():
    almost_ints = list(range(1000)) + ["ha!"] + list(range(1001,2001))
    non_gotchas = (tc.seq_of(int, checkonly=9)(almost_ints) +
                   tc.seq_of(int, checkonly=10)(almost_ints) +
                   tc.seq_of(int, checkonly=11)(almost_ints))
    assert non_gotchas >= 2  # should fail about once every 40000 runs
    almost_ints = list(range(1000)) + 10*["ha!"] + list(range(1010,2001))
    non_gotchas = (tc.seq_of(str, checkonly=8)(almost_ints) +
                   tc.seq_of(str, checkonly=9)(almost_ints) +
                   tc.seq_of(str, checkonly=10)(almost_ints))
    assert non_gotchas <= 1  # should fail almost never
コード例 #2
0
def test_seq_of_checkonly():
    almost_ints = list(range(1000)) + ["ha!"] + list(range(1001, 2001))
    non_gotchas = (tc.seq_of(int, checkonly=9)(almost_ints) +
                   tc.seq_of(int, checkonly=10)(almost_ints) +
                   tc.seq_of(int, checkonly=11)(almost_ints))
    assert non_gotchas >= 2  # should fail about once every 40000 runs
    almost_ints = list(range(1000)) + 10 * ["ha!"] + list(range(1010, 2001))
    non_gotchas = (tc.seq_of(str, checkonly=8)(almost_ints) +
                   tc.seq_of(str, checkonly=9)(almost_ints) +
                   tc.seq_of(str, checkonly=10)(almost_ints))
    assert non_gotchas <= 1  # should fail almost never
コード例 #3
0
def test_seq_of_str_with_simple_str():
    assert not tc.seq_of(str)("A sequence of strings, but not a seq_of(str)")
コード例 #4
0
def test_seq_of_UserList():
    assert tc.seq_of(int)([4, 5])
    assert tc.seq_of(int)(collections.UserList([4, 5]))
コード例 #5
0
def test_seq_of_with_optional():
    assert tc.seq_of(tc.optional(tc.re("^foo$")))(["foo", None, "foo"]) and \
           tc.seq_of(tc.optional(tc.re("^foo$"))).check(["foo", None, "foo"])
    assert not tc.seq_of(tc.optional(tc.re("^foo$")))(["123", None, "foo"]) and \
           not tc.seq_of(tc.optional(tc.re("^foo$"))).check(["foo", None, "1234"])
コード例 #6
0
 def foo(x: tc.seq_of((tc.re("^[01]+$"), int))) -> bool:
     return functools.reduce(lambda r, e: r and int(e[0], 2) == e[1],
                             x, True)
コード例 #7
0
 def foo_s(x: tc.seq_of(int)) -> tc.seq_of(float):
     return list(map(float, x))
コード例 #8
0
def test_seq_of_str_with_simple_str():
    assert not tc.seq_of(str)("A sequence of strings, but not a seq_of(str)",
                              None)
コード例 #9
0
def test_seq_of_UserList():
    namespace = None
    assert tc.seq_of(int)([4, 5], namespace)
    assert tc.seq_of(int)(collections.UserList([4, 5]), namespace)
コード例 #10
0
def test_seq_of_with_optional():
    namespace = None
    assert tc.seq_of(tc.optional(tc.re("^foo$")))(["foo", None, "foo"], namespace) and \
           tc.seq_of(tc.optional(tc.re("^foo$"))).check(["foo", None, "foo"], namespace)
    assert not tc.seq_of(tc.optional(tc.re("^foo$")))(["123", None, "foo"], namespace) and \
           not tc.seq_of(tc.optional(tc.re("^foo$"))).check(["foo", None, "1234"], namespace)
コード例 #11
0
 def foo(x: tc.seq_of((tc.re("^[01]+$"), int))) -> bool:
     return functools.reduce(lambda r, e: r and int(e[0], 2) == e[1], x,
                             True)
コード例 #12
0
 def foo_s(x: tc.seq_of(int)) -> tc.seq_of(float):
     return list(map(float, x))
コード例 #13
0
def test_seq_of_UserList():
    namespace = None
    assert tc.seq_of(int)([4, 5], namespace)
    assert tc.seq_of(int)(collections.UserList([4, 5]), namespace)
コード例 #14
0
def test_seq_of_UserList():
    assert tc.seq_of(int)([4, 5])
    assert tc.seq_of(int)(collections.UserList([4, 5]))