From 533e5c493cbd23b386c69d90e9c42b6c2aa47141 Mon Sep 17 00:00:00 2001 From: David Waterman Date: Fri, 22 Nov 2024 16:29:37 +0000 Subject: [PATCH] Given that we're already monkeypatching here, use this to also fake out os.path.exists to get the old behaviour for the test. Add a new assert to test the new behaviour first. --- tests/serialize/test_filename.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/serialize/test_filename.py b/tests/serialize/test_filename.py index 65393fac7..e492d4faf 100644 --- a/tests/serialize/test_filename.py +++ b/tests/serialize/test_filename.py @@ -1,15 +1,30 @@ from __future__ import annotations import os +import uuid from dxtbx.serialize.filename import resolve_path def test_resolve_path(monkeypatch): + # Resolve path + def alwaystrue(path): + return True + + # Set an environment variable monkeypatch.setenv("HELLO_WORLD", "EXPANDED") - new_path = os.path.join("~", "$HELLO_WORLD", "path") + + # First try a path that does not exist + filename = str(uuid.uuid4()) + new_path = os.path.join("~", "$HELLO_WORLD", filename) path = resolve_path(new_path) - assert path == os.path.join(os.path.expanduser("~"), "EXPANDED", "path") - new_path = os.path.join("$HELLO_WORLD", "path") + assert path == new_path + + # Now pretend the path exists + monkeypatch.setattr(os.path, "exists", alwaystrue) + path = resolve_path(new_path) + assert path == os.path.join(os.path.expanduser("~"), "EXPANDED", filename) + + new_path = os.path.join("$HELLO_WORLD", filename) path = resolve_path(new_path) - assert path == os.path.abspath(os.path.join("EXPANDED", "path")) + assert path == os.path.abspath(os.path.join("EXPANDED", filename))