Exemplo n.º 1
0
 def test_wrong_permissions(self, tmp_path):
     private = PrivateJsonFile(tmp_path)
     with private.path.open("w") as f:
         json.dump({"foo": "bar"}, f)
     assert private.path.stat().st_mode & 0o077 > 0
     with pytest.raises(PermissionError,
                        match="readable by others.*expected: 600"):
         private.get("foo")
     with pytest.raises(PermissionError,
                        match="readable by others.*expected: 600"):
         private.set("foo", value="lol")
Exemplo n.º 2
0
 def test_set_get(self, tmp_path):
     private = PrivateJsonFile(tmp_path)
     private.set("foo", "bar", value=42)
     assert private.get("foo", "bar") == 42
     with private.path.open("r") as f:
         data = json.load(f)
     assert data == {"foo": {"bar": 42}}
Exemplo n.º 3
0
 def test_empty(self, tmp_path):
     private = PrivateJsonFile(tmp_path)
     assert private.get("foo") is None
     assert not private.path.exists()