toga/testbed/tests/test_paths.py
2023-06-07 07:39:12 +08:00

29 lines
850 B
Python

import os
import shutil
import pytest
@pytest.mark.parametrize("attr", ["config", "data", "cache", "logs"])
async def test_app_paths(app, app_probe, attr):
"""Platform paths are as expected."""
path = getattr(app.paths, attr)
assert path == getattr(app_probe, f"{attr}_path")
try:
# We can create a folder in the app path
tempdir = path / f"testbed-{os.getpid()}"
tempdir.mkdir(parents=True)
# We can create a file in the app path
tempfile = tempdir / f"{attr}.txt"
with tempfile.open("w", encoding="utf-8") as f:
f.write(f"Hello {attr}\n")
# We can create a file in the app path
with tempfile.open("r", encoding="utf-8") as f:
assert f.read() == f"Hello {attr}\n"
finally:
if path.exists():
shutil.rmtree(tempdir)