Ejemplo n.º 1
0
def test_frozenlist():
    l = frozenlist([1, 2, 3])
    assert l[0] == 1
    assert l[:2] == [1, 2]
    assert l.index(2) == 1
    py.test.raises(TypeError, "l[0] = 1")
    py.test.raises(TypeError, "del l[0]")
    py.test.raises(TypeError, "l[:] = []")
    py.test.raises(TypeError, "del l[:]")
    py.test.raises(TypeError, "l += []")
    py.test.raises(TypeError, "l *= 2")
    py.test.raises(TypeError, "l.append(1)")
    py.test.raises(TypeError, "l.insert(0, 0)")
    py.test.raises(TypeError, "l.pop()")
    py.test.raises(TypeError, "l.remove(1)")
    py.test.raises(TypeError, "l.reverse()")
    py.test.raises(TypeError, "l.sort()")
    py.test.raises(TypeError, "l.extend([])")
Ejemplo n.º 2
0
def test_frozenlist():
    l = frozenlist([1, 2, 3])
    assert l[0] == 1
    assert l[:2] == [1, 2]
    assert l.index(2) == 1
    py.test.raises(TypeError, "l[0] = 1")
    py.test.raises(TypeError, "del l[0]")
    py.test.raises(TypeError, "l[:] = []")
    py.test.raises(TypeError, "del l[:]")
    py.test.raises(TypeError, "l += []")
    py.test.raises(TypeError, "l *= 2")
    py.test.raises(TypeError, "l.append(1)")
    py.test.raises(TypeError, "l.insert(0, 0)")
    py.test.raises(TypeError, "l.pop()")
    py.test.raises(TypeError, "l.remove(1)")
    py.test.raises(TypeError, "l.reverse()")
    py.test.raises(TypeError, "l.sort()")
    py.test.raises(TypeError, "l.extend([])")
Ejemplo n.º 3
0
def get_deep_immutable_oplist(operations):
    """
    When not we_are_translated(), turns ``operations`` into a frozenlist and
    monkey-patch its items to make sure they are not mutated.

    When we_are_translated(), do nothing and just return the old list.
    """
    from rpython.tool.frozenlist import frozenlist
    if we_are_translated():
        return operations
    #
    def setarg(*args):
        assert False, "operations cannot change at this point"
    def setdescr(*args):
        assert False, "operations cannot change at this point"
    newops = frozenlist(operations)
    for op in newops:
        op.setarg = setarg
        op.setdescr = setdescr
    return newops
Ejemplo n.º 4
0
def get_deep_immutable_oplist(operations):
    """
    When not we_are_translated(), turns ``operations`` into a frozenlist and
    monkey-patch its items to make sure they are not mutated.

    When we_are_translated(), do nothing and just return the old list.
    """
    from rpython.tool.frozenlist import frozenlist
    if we_are_translated():
        return operations
    #
    def setarg(*args):
        assert False, "operations cannot change at this point"

    def setdescr(*args):
        assert False, "operations cannot change at this point"

    newops = frozenlist(operations)
    for op in newops:
        op.setarg = setarg
        op.setdescr = setdescr
    return newops