コード例 #1
0
ファイル: test_readonly.py プロジェクト: yunstanford/devpi
 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
コード例 #2
0
ファイル: test_readonly.py プロジェクト: yunstanford/devpi
 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
コード例 #3
0
ファイル: test_readonly.py プロジェクト: yunstanford/devpi
 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
コード例 #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