Skip to content

Commit

Permalink
grass.jupyter: Fix session tests on Windows
Browse files Browse the repository at this point in the history
The interpolated path strings aren't escaped when evaluated, so using a
raw string allows C:\Users to not have an invalid \U escape sequence.
  • Loading branch information
echoix committed Sep 23, 2024
1 parent 25afbfb commit 5b46b84
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions python/grass/jupyter/tests/grass_jupyter_session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import sys

import pytest


# All init tests change the global environment, but we use a separate process
# only when it is necessary.
Expand All @@ -22,19 +20,15 @@ def run_in_subprocess(file):
return process.stdout


@pytest.mark.xfail(
sys.platform == "win32",
reason="tmp_path string in interpolated code should be escaped or use raw strings",
)
def test_init_finish(tmp_path):
"""Check that init function works with an explicit session finish"""
location = "test"
script = f"""
import os
import grass.script as gs
import grass.jupyter as gj
gs.core._create_location_xy("{tmp_path}", "{location}")
session = gj.init("{tmp_path / location}")
gs.core._create_location_xy(r"{tmp_path}", r"{location}")
session = gj.init(r"{tmp_path / location}")
gs.read_command("g.region", flags="p")
print(os.environ["GISRC"])
session.finish()
Expand All @@ -48,19 +42,15 @@ def test_init_finish(tmp_path):
assert not os.path.exists(session_file), f"Session file {session_file} not deleted"


@pytest.mark.xfail(
sys.platform == "win32",
reason="tmp_path string in interpolated code should be escaped or use raw strings",
)
def test_init_with_auto_finish(tmp_path):
"""Check that init function works with an implicit session finish"""
location = "test"
script = f"""
import os
import grass.script as gs
import grass.jupyter as gj
gs.core._create_location_xy("{tmp_path}", "{location}")
session = gj.init("{tmp_path / location}")
gs.core._create_location_xy(r"{tmp_path}", r"{location}")
session = gj.init(r"{tmp_path / location}")
print(os.environ["GISRC"])
"""

Expand Down

0 comments on commit 5b46b84

Please sign in to comment.