mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 23:20:29 -05:00
#13435 Improve string list parsing for backslashes and quotes
Enhanced parsing in PdmFieldScriptingCapabilityIOHandler to correctly handle backslashes and escape sequences in both quoted and unquoted strings. Unquoted Windows paths now preserve backslashes, while quoted strings process escape sequences as expected. Added unit tests to verify correct handling of both cases. Add tests for Windows-style path handling in rips API Introduce test_windows_paths.py with two pytest tests to verify correct handling of Windows-style file paths (backslashes) in the rips Python API.
This commit is contained in:
1 parent
d47de408aa
commit
5356f078a5
3 files changed
+116
-7
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import sys
|
||||
import os
|
||||
import platform
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
platform.system() != "Windows", reason="Windows-specific path test"
|
||||
)
|
||||
|
||||
|
||||
def test_import_well_paths_with_backslashes(rips_instance, initialize_test):
|
||||
"""Test that Windows-style paths with backslashes are correctly handled.
|
||||
|
||||
This test verifies the fix for issue #13435 where backslashes in Windows paths
|
||||
were incorrectly interpreted as escape characters when passed from Python to
|
||||
ResInsight via gRPC.
|
||||
"""
|
||||
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
|
||||
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
assert len(case.grids()) == 2
|
||||
|
||||
# Build paths using forward slashes first, then convert to Windows-style backslashes
|
||||
well_path_a = os.path.abspath(
|
||||
os.path.join(case_root_path, "wellpath_a.dev")
|
||||
).replace("/", "\\")
|
||||
well_path_b = os.path.abspath(
|
||||
os.path.join(case_root_path, "wellpath_b.dev")
|
||||
).replace("/", "\\")
|
||||
|
||||
# The paths now contain backslashes (e.g., "C:\path\to\wellpath_a.dev")
|
||||
# This tests the fix for issue #13435 where backslashes were incorrectly
|
||||
# interpreted as escape characters
|
||||
well_path_files = [well_path_a, well_path_b]
|
||||
|
||||
well_path_names = rips_instance.project.import_well_paths(well_path_files)
|
||||
assert len(well_path_names) == 2
|
||||
wells = rips_instance.project.well_paths()
|
||||
assert len(wells) == 2
|
||||
assert wells[0].name == "Well Path A"
|
||||
assert wells[1].name == "Well Path B"
|
||||
Reference in new issue
Block a user