-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass through
resolve_path
when the path is not accessible (#783)
* Resolve path only if accessible, otherwise return unchanged Fixes #771
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Do not try to resolve file paths if they are not accessible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
import glob | ||
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 by ensuring its glob is truthy | ||
monkeypatch.setattr(glob, "glob", 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)) |