示例#1
0
def test_repr():
    rs = ResultSet(resource_cls=ReprResource)
    rs._results = range(20)
    assert repr(rs) == '<ResultSet: 0, 1, 2, 3, 4, ...>', repr(rs)

    rs._results = range(3)
    assert repr(rs) == '<ResultSet: 0, 1, 2>', repr(rs)
示例#2
0
def test_repr():
    rs = ResultSet(resource_cls=ReprResource)
    rs._results = range(20)
    assert repr(rs) == '<ResultSet: 0, 1, 2, 3, 4, ...>', repr(rs)

    rs._results = range(3)
    assert repr(rs) == '<ResultSet: 0, 1, 2>', repr(rs)
示例#3
0
def test_slicing():
    rs = ResultSet(resource_cls='foo')
    rs._results = fibs_to(13)
    assert rs[0] == 0
    assert rs[1] == 1
    assert rs[2] == 1
    assert rs[3] == 2
    assert rs[4] == 3
    assert rs[5] == 5
    assert rs[6] == 8
    assert rs[7] == 13

    assert rs[0:13] == [0, 1, 1, 2, 3, 5, 8, 13]
    assert rs[0:1000] == [0, 1, 1, 2, 3, 5, 8, 13]  # per convention
    assert rs[1:] == [1, 1, 2, 3, 5, 8, 13]
    assert rs[:1] == [0]

    # no negative indexing
    with assert_raises(IndexError):
        rs[0:-1]
    with assert_raises(IndexError):
        rs[-3:-1]
    with assert_raises(IndexError):
        rs[-1]

    # out of range
    with assert_raises(IndexError):
        rs[100]
示例#4
0
def test_slicing():
    rs = ResultSet(resource_cls='foo')
    rs._results = fibs_to(13)
    assert rs[0] == 0
    assert rs[1] == 1
    assert rs[2] == 1
    assert rs[3] == 2
    assert rs[4] == 3
    assert rs[5] == 5
    assert rs[6] == 8
    assert rs[7] == 13

    assert rs[0:13] == [0, 1, 1, 2, 3, 5, 8, 13]
    assert rs[0:1000] == [0, 1, 1, 2, 3, 5, 8, 13]  # per convention
    assert rs[1:] == [1, 1, 2, 3, 5, 8, 13]
    assert rs[:1] == [0]

    # no negative indexing
    with assert_raises(IndexError):
        rs[0:-1]
    with assert_raises(IndexError):
        rs[-3:-1]
    with assert_raises(IndexError):
        rs[-1]

    # out of range
    with assert_raises(IndexError):
        rs[100]