Skip to content

Commit

Permalink
fix(MFFileMgmt.string_to_file_path): updated to support UNC paths (#1256
Browse files Browse the repository at this point in the history
)

* added test_mf6_string_to_file_path to t501_test.py
* Close #1237
  • Loading branch information
jlarsen-usgs committed Oct 6, 2021
1 parent fe913fe commit 459aacb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 33 additions & 0 deletions autotest/t501_test.py
Expand Up @@ -135,5 +135,38 @@ def test_mf6():
return


def test_mf6_string_to_file_path():
from flopy.mf6.mfbase import MFFileMgmt
import platform

if platform.system().lower() == "windows":
unc_path = r"\\server\path\path"
new_path = MFFileMgmt.string_to_file_path(unc_path)
if not unc_path == new_path:
raise AssertionError("UNC path error")

abs_path = r"C:\Users\some_user\path"
new_path = MFFileMgmt.string_to_file_path(abs_path)
if not abs_path == new_path:
raise AssertionError("Absolute path error")

rel_path = r"..\path\some_path"
new_path = MFFileMgmt.string_to_file_path(rel_path)
if not rel_path == new_path:
raise AssertionError("Relative path error")

else:
abs_path = "/mnt/c/some_user/path"
new_path = MFFileMgmt.string_to_file_path(abs_path)
if not abs_path == new_path:
raise AssertionError("Absolute path error")

rel_path = "../path/some_path"
new_path = MFFileMgmt.string_to_file_path(rel_path)
if not rel_path == new_path:
raise AssertionError("Relative path error")


if __name__ == "__main__":
test_mf6()
test_mf6_string_to_file_path()
7 changes: 6 additions & 1 deletion flopy/mf6/mfbase.py
Expand Up @@ -310,7 +310,12 @@ def string_to_file_path(fp_string):
arr_string = new_string.split(delimiter)
if len(arr_string) > 1:
if os.path.isabs(fp_string):
new_string = f"{arr_string[0]}{delimiter}{arr_string[1]}"
if not arr_string[0] and not arr_string[1]:
new_string = f"{delimiter}{delimiter}"
else:
new_string = (
f"{arr_string[0]}{delimiter}{arr_string[1]}"
)
else:
new_string = os.path.join(arr_string[0], arr_string[1])
if len(arr_string) > 2:
Expand Down

0 comments on commit 459aacb

Please sign in to comment.