From 9a9c266b76e33b06e3d4ca3b5cae1da2e40eda3e Mon Sep 17 00:00:00 2001 From: Jesper Sandvig Mariegaard <34088801+jsmariegaard@users.noreply.github.com> Date: Sat, 19 Nov 2022 18:22:49 +0100 Subject: [PATCH 1/4] failing test --- tests/test_pfs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_pfs.py b/tests/test_pfs.py index 96d5141d3..d7b596eae 100644 --- a/tests/test_pfs.py +++ b/tests/test_pfs.py @@ -605,6 +605,7 @@ def test_difficult_chars_in_str(tmpdir): C = |sd's\d.dfs0| D = |str'd.dfs0| E = |str,s'+-s_d.dfs0| + F = |DT,M.dfs2| EndSect // ENGINE """ with pytest.warns(match="contains a single quote character"): From 056d3e07edbd15bd77ae5ad35fc1da0e8b607960 Mon Sep 17 00:00:00 2001 From: Jesper Sandvig Mariegaard <34088801+jsmariegaard@users.noreply.github.com> Date: Sat, 19 Nov 2022 18:27:30 +0100 Subject: [PATCH 2/4] more failing --- tests/test_pfs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_pfs.py b/tests/test_pfs.py index d7b596eae..67d1e36cb 100644 --- a/tests/test_pfs.py +++ b/tests/test_pfs.py @@ -614,9 +614,8 @@ def test_difficult_chars_in_str(tmpdir): assert isinstance(pfs.ENGINE.A, str) assert pfs.ENGINE.A == "str,s/d\sd.dfs0" - # NOTE: B will appear wrong as a list with one item - assert isinstance(pfs.ENGINE.B[0], str) - assert pfs.ENGINE.B[0] == "str,sd'sd.dfs0" + assert isinstance(pfs.ENGINE.B, str) + assert pfs.ENGINE.B == "str,sd'sd.dfs0" assert isinstance(pfs.ENGINE.C, str) assert pfs.ENGINE.C == "|sd\U0001F600s\d.dfs0|" assert isinstance(pfs.ENGINE.D, str) From 8aeaa9097b028255a56549424d9d20d4a488ff18 Mon Sep 17 00:00:00 2001 From: Jesper Sandvig Mariegaard <34088801+jsmariegaard@users.noreply.github.com> Date: Sat, 19 Nov 2022 18:30:55 +0100 Subject: [PATCH 3/4] use shlex instead of re for splitting --- mikeio/pfs.py | 17 +++++++++-------- tests/test_pfs.py | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mikeio/pfs.py b/mikeio/pfs.py index b0a3a7e7b..b9a7c6df2 100644 --- a/mikeio/pfs.py +++ b/mikeio/pfs.py @@ -578,16 +578,17 @@ def _parse_param(self, value: str) -> str: value = self._parse_token(value) return value - _COMMA_MATCHER = re.compile(r",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)") + # _COMMA_MATCHER = re.compile(r",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)") def _split_line_by_comma(self, s: str): - return self._COMMA_MATCHER.split(s) - # import shlex - # lexer = shlex.shlex(s) - # lexer.whitespace += "," - # lexer.quotes += "|" - # lexer.wordchars += ".-" - # return list(lexer) + # return self._COMMA_MATCHER.split(s) + import shlex + + lexer = shlex.shlex(s) + lexer.whitespace += "," + lexer.quotes += "|" + lexer.wordchars += ",.-" + return list(lexer) def _parse_token(self, token: str) -> str: s = token.strip() diff --git a/tests/test_pfs.py b/tests/test_pfs.py index 67d1e36cb..9deaaf123 100644 --- a/tests/test_pfs.py +++ b/tests/test_pfs.py @@ -709,6 +709,7 @@ def test_read_write_list_list(tmpdir): assert n_rgb_out == 2 +@pytest.mark.skip(reason="temporary") def test_double_single_quotes_in_string(tmpdir): text = """ [DERIVED_VARIABLE_106] From 480fe95874038bcfb58fa12a63e22c15b7dbb8ea Mon Sep 17 00:00:00 2001 From: Jesper Sandvig Mariegaard <34088801+jsmariegaard@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:27:20 +0100 Subject: [PATCH 4/4] don't skip anymore --- tests/test_pfs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_pfs.py b/tests/test_pfs.py index 9deaaf123..67d1e36cb 100644 --- a/tests/test_pfs.py +++ b/tests/test_pfs.py @@ -709,7 +709,6 @@ def test_read_write_list_list(tmpdir): assert n_rgb_out == 2 -@pytest.mark.skip(reason="temporary") def test_double_single_quotes_in_string(tmpdir): text = """ [DERIVED_VARIABLE_106]