Skip to content

Commit b4cbb02

Browse files
committed
temp
1 parent f6c2ea5 commit b4cbb02

File tree

7 files changed

+74
-8
lines changed

7 files changed

+74
-8
lines changed

android/tests_backend/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def paths(self):
3131
"logs": Path(self.get_app_context().getFilesDir().getPath()) / "log",
3232
}
3333

34+
def apply_path_customization(self):
35+
pytest.xfail("This backend doesn't implement app path customization.")
36+
37+
def remove_path_customization(self):
38+
pytest.xfail("This backend doesn't implement app path customization.")
39+
3440
def assert_app_icon(self, icon):
3541
pytest.xfail("Android apps don't have app icons at runtime")
3642

cocoa/tests_backend/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22

33
import PIL.Image
4+
import pytest
45
from rubicon.objc import SEL, NSPoint, ObjCClass, objc_id, send_message
56

67
import toga
@@ -42,6 +43,12 @@ def paths(self):
4243
"logs": Path.home() / "Library/Logs/org.beeware.toga.testbed",
4344
}
4445

46+
def apply_path_customization(self):
47+
pytest.xfail("This backend doesn't implement app path customization.")
48+
49+
def remove_path_customization(self):
50+
pytest.xfail("This backend doesn't implement app path customization.")
51+
4552
@property
4653
def is_cursor_visible(self):
4754
# There's no API level mechanism to detect cursor visibility;

gtk/src/toga_gtk/paths.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23

34
from toga import App
@@ -7,14 +8,22 @@ class Paths:
78
def __init__(self, interface):
89
self.interface = interface
910

11+
def _get_root(self, envvar, default):
12+
custom_root = os.getenv(envvar)
13+
return Path(custom_root) if custom_root else Path.home() / default
14+
1015
def get_config_path(self):
11-
return Path.home() / ".config" / App.app.app_name
16+
root = self._get_root("XDG_CONFIG_HOME", ".config")
17+
return root / App.app.app_name
1218

1319
def get_data_path(self):
14-
return Path.home() / ".local/share" / App.app.app_name
20+
root = self._get_root("XDG_DATA_HOME", ".local/share")
21+
return root / App.app.app_name
1522

1623
def get_cache_path(self):
17-
return Path.home() / ".cache" / App.app.app_name
24+
root = self._get_root("XDG_CACHE_HOME", ".cache")
25+
return root / App.app.app_name
1826

1927
def get_logs_path(self):
20-
return Path.home() / ".local/state" / App.app.app_name / "log"
28+
root = self._get_root("XDG_STATE_HOME", ".local/state")
29+
return root / App.app.app_name / "log"

gtk/tests_backend/app.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ def __init__(self, app):
2424
assert isinstance(self.app._impl.native, Gtk.Application)
2525
assert IS_WAYLAND is (os.environ.get("WAYLAND_DISPLAY", "") != "")
2626

27-
def paths(self):
27+
@property
28+
def _custom_path_root(self):
29+
return Path.home() / ".cache/testbed/custom_app_paths"
30+
31+
def paths(self, *, custom):
32+
if custom:
33+
return {
34+
"config": self._custom_path_root / "config/testbed",
35+
"data": self._custom_path_root / "data/testbed",
36+
"cache": self._custom_path_root / "cache/testbed",
37+
"logs": self._custom_path_root / "state/testbed/log",
38+
}
39+
2840
return {
2941
"config": Path.home() / ".config/testbed",
3042
"data": Path.home() / ".local/share/testbed",
@@ -36,6 +48,19 @@ def paths(self):
3648
def is_cursor_visible(self):
3749
pytest.skip("Cursor visibility not implemented on GTK")
3850

51+
def apply_path_customization(self):
52+
root = Path.home() / ".cache/testbed/custom_app_paths"
53+
os.environ["XDG_CONFIG_HOME"] = str(root / "config")
54+
os.environ["XDG_DATA_HOME"] = str(root / "data")
55+
os.environ["XDG_CACHE_HOME"] = str(root / "cache")
56+
os.environ["XDG_STATE_HOME"] = str(root / "state")
57+
58+
def remove_path_customization(self):
59+
del os.environ["XDG_CONFIG_HOME"]
60+
del os.environ["XDG_DATA_HOME"]
61+
del os.environ["XDG_CACHE_HOME"]
62+
del os.environ["XDG_STATE_HOME"]
63+
3964
def unhide(self):
4065
pytest.xfail("This platform doesn't have an app level unhide.")
4166

iOS/tests_backend/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def paths(self):
3838
"logs": self.get_path(NSSearchPathDirectory.ApplicationSupport) / "Logs",
3939
}
4040

41+
def apply_path_customization(self):
42+
pytest.xfail("This backend doesn't implement app path customization.")
43+
44+
def remove_path_customization(self):
45+
pytest.xfail("This backend doesn't implement app path customization.")
46+
4147
def assert_app_icon(self, icon):
4248
pytest.xfail("iOS apps don't have app icons at runtime")
4349

testbed/tests/test_paths.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66

77
@pytest.mark.parametrize("attr", ["config", "data", "cache", "logs"])
8-
async def test_app_paths(app, app_probe, attr):
8+
@pytest.mark.parametrize("custom", [False, True])
9+
async def test_app_paths(app, app_probe, attr, custom):
10+
if custom:
11+
app_probe.apply_path_customization()
12+
913
"""Platform paths are as expected."""
1014
path = getattr(app.paths, attr)
11-
expected_paths = app_probe.paths()
15+
expected_paths = app_probe.paths(custom=custom)
1216
assert path == expected_paths[attr]
1317

1418
try:
@@ -21,10 +25,13 @@ async def test_app_paths(app, app_probe, attr):
2125
with tempfile.open("w", encoding="utf-8") as f:
2226
f.write(f"Hello {attr}\n")
2327

24-
# We can create a file in the app path
28+
# We can read a file in the app path
2529
with tempfile.open("r", encoding="utf-8") as f:
2630
assert f.read() == f"Hello {attr}\n"
2731

2832
finally:
2933
if path.exists():
3034
shutil.rmtree(tempdir)
35+
36+
if custom:
37+
app_probe.remove_path_customization()

winforms/tests_backend/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def paths(self):
4949
"logs": Path.home() / "AppData/Local/Tiberius Yak/Toga Testbed/Logs",
5050
}
5151

52+
def apply_path_customization(self):
53+
pytest.xfail("This backend doesn't implement app path customization.")
54+
55+
def remove_path_customization(self):
56+
pytest.xfail("This backend doesn't implement app path customization.")
57+
5258
@property
5359
def is_cursor_visible(self):
5460
# Despite what the documentation says, Cursor.Current never returns null in

0 commit comments

Comments
 (0)