Ejemplo n.º 1
0
 def test_simple(self):
     x = (1, )
     assert not is_deeply_readonly(x)
     r = ensure_deeply_readonly(x)
     assert is_deeply_readonly(r)
     assert r
     assert len(r) == 1
     assert r[0] == 1
     c = get_mutable_deepcopy(r)
     assert c == x
Ejemplo n.º 2
0
 def test_simple(self):
     x = set()
     assert not is_deeply_readonly(x)
     r = ensure_deeply_readonly(x)
     assert is_deeply_readonly(r)
     assert not r
     assert "x" not in r
     with pytest.raises(AttributeError):
         r.add(2)
     assert len(r) == 0
Ejemplo n.º 3
0
 def test_simple(self):
     x = [1]
     assert not is_deeply_readonly(x)
     r = ensure_deeply_readonly(x)
     assert r
     assert is_deeply_readonly(r)
     assert len(r) == 1
     with pytest.raises(AttributeError):
         r.append(2)
     c = get_mutable_deepcopy(r)
     assert c == x
     c.append(1)
     assert c != x
Ejemplo n.º 4
0
    def test_write_then_readonly(self, keyfs):
        key1 = keyfs.add_key("NAME", "some1", dict)
        keyfs.restart_as_write_transaction()
        with key1.update() as d:
            d[1] = [1,2,3]

        # if we get it new, we still get a readonly view
        assert is_deeply_readonly(key1.get())

        # if we get it new in write mode, we get a new copy
        d2 = key1.get(readonly=False)
        assert d2 == d
        d2[3] = 4
        assert d2 != d