Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions autotest/t501_test.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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