Skip to content

Commit

Permalink
#350 Simplify tests with better default env var: APPDATA
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs authored and soxofaan committed Dec 15, 2022
1 parent e6879a2 commit b85b2e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# Make tests more predictable and avoid loading real configs in tests.
os.environ["XDG_CONFIG_HOME"] = str(Path(__file__).parent / "data/user_dirs/config")
os.environ["XDG_DATA_HOME"] = str(Path(__file__).parent / "data/user_dirs/data")
# Windows does not use the *nix environment variables XDG_CONFIG_HOME and XDG_DATA_HOME
# It has only one corresponding folder for both config and data: APPDATA
os.environ["APPDATA"] = str(Path(__file__).parent / "data/user_dirs/AppData/Roaming")


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
20 changes: 8 additions & 12 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@


def test_get_user_config_dir():
# For Linux/Mac we configure the config and data directories in conftest.py
# via the environment variables XDG_CONFIG_HOME and XDG_DATA_HOME.
# But on Windows we need to set APPDATA instead, and we don't have separate
# variables for config and data.
if platform.system() == "Windows":
os.environ["APPDATA"] = str(Path(__file__).parent / "data/user_dirs/config")
assert get_user_config_dir() == Path(__file__).parent / "data/user_dirs/config/openeo-python-client"
expected = Path(__file__).parent / "data/user_dirs/AppData/Roaming/openeo-python-client"
else:
expected = Path(__file__).parent / "data/user_dirs/config/openeo-python-client"
assert get_user_config_dir() == expected


def test_get_user_data_dir():
# For Linux/Mac we configure the config and data directories in conftest.py
# via the environment variables XDG_CONFIG_HOME and XDG_DATA_HOME.
# But on Windows we need to set APPDATA instead, and we don't have separate
# variables for config and data.
if platform.system() == "Windows":
os.environ["APPDATA"] = str(Path(__file__).parent / "data/user_dirs/data")
assert get_user_data_dir() == Path(__file__).parent / "data/user_dirs/data/openeo-python-client"
expected = Path(__file__).parent / "data/user_dirs/AppData/Roaming/openeo-python-client"
else:
expected = Path(__file__).parent / "data/user_dirs/data/openeo-python-client"
assert get_user_data_dir() == expected


class TestClientConfig:
Expand Down

0 comments on commit b85b2e4

Please sign in to comment.