aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_ops.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests/test_ops.py')
-rw-r--r--packages/meshbay-node/tests/test_ops.py46
1 files changed, 40 insertions, 6 deletions
diff --git a/packages/meshbay-node/tests/test_ops.py b/packages/meshbay-node/tests/test_ops.py
index b3f0378..c118b5a 100644
--- a/packages/meshbay-node/tests/test_ops.py
+++ b/packages/meshbay-node/tests/test_ops.py
@@ -11,7 +11,7 @@ call them.
import asyncio
import inspect
-from pathlib import Path
+from pathlib import Path, PureWindowsPath
from types import SimpleNamespace
import pytest
@@ -359,13 +359,47 @@ def test_update_node_toml_forces_lf_and_keeps_standalone_comments(tmp_path):
def test_a_backslash_path_written_into_node_toml_stays_parseable():
- # attach_group / add_root / init embed a directory into a TOML basic string.
- # A raw Windows path there (drive + backslash + "Users" + ...) is a parse
- # error since backslash sequences are escapes; the code writes as_posix().
+ """
+ attach_group and add_root embed a directory into a TOML basic string. A raw
+ Windows path there is a parse error, because backslash sequences are escapes
+ (`\\U`, `\\a`, ...); the code writes `as_posix()` and pathlib reads `/` back
+ on Windows.
+
+ `PureWindowsPath`, not `Path`: on this suite's usual machine `Path` is a
+ `PosixPath`, where a backslash is an ordinary filename character and
+ `as_posix()` converts nothing — so the test modelled the wrong platform and
+ failed everywhere except the one it was written for. Naming the flavour
+ explicitly is what makes it the same assertion on all three.
+ """
import tomllib
bs = chr(92)
win_dir = f"C:{bs}Users{bs}alice{bs}Media"
- assert tomllib.loads(f'path = "{Path(win_dir).as_posix()}"\n')["path"] == \
- "C:/Users/alice/Media"
+
+ assert tomllib.loads(
+ f'path = "{PureWindowsPath(win_dir).as_posix()}"\n'
+ )["path"] == "C:/Users/alice/Media"
+
with pytest.raises(tomllib.TOMLDecodeError):
tomllib.loads(f'path = "{win_dir}"\n') # the bug this guards against
+
+
+def test_every_path_written_into_node_toml_goes_through_as_posix():
+ """
+ The half the round trip above cannot see.
+
+ Proving `as_posix()` produces a parseable string says nothing about whether
+ the code calls it, and this is a defect no Linux machine can reproduce: the
+ config is written, parsed and served correctly here, and fails on the
+ operator's Windows box. So the source is read for the shape instead —
+ weak evidence, and the only kind available for a platform the suite does
+ not run on.
+ """
+ import re
+ source = inspect.getsource(ops)
+ # Every f-string interpolation that lands on the right of a TOML `path =`.
+ writes = re.findall(r'path\s*=\s*\\?"\{([^}]+)\}', source)
+ assert writes, "no TOML path writer found — did the config writer move?"
+ for expr in writes:
+ assert "as_posix()" in expr, (
+ f'node.toml path written as `{expr}` — a Windows path needs '
+ f'as_posix(), or the file it lands in will not parse')