Skip to content

Commit e0722d0

Browse files
committed
fix repl test
1 parent d087713 commit e0722d0

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tests/repl/repl_test.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,53 @@
2121
foo = 1234
2222
"""
2323

24+
IS_WINDOWS = os.name == "nt"
2425

2526
class ReplTest(unittest.TestCase):
2627
def setUp(self):
27-
self.repl = rfiles.Rlocation("rules_python/python/bin/repl")
28+
rpath = "rules_python/python/bin/repl"
29+
if IS_WINDOWS:
30+
rpath += ".exe"
31+
self.repl = rfiles.Rlocation(rpath)
2832
assert self.repl
33+
if IS_WINDOWS:
34+
self.repl = os.path.normpath(self.repl)
2935

3036
def run_code_in_repl(self, lines: Iterable[str], *, env=None) -> str:
3137
"""Runs the lines of code in the REPL and returns the text output."""
38+
input="\n".join(lines)
3239
try:
3340
return subprocess.check_output(
3441
[self.repl],
3542
text=True,
3643
stderr=subprocess.STDOUT,
37-
input="\n".join(lines),
44+
input=input,
3845
env=env,
3946
).strip()
4047
except subprocess.CalledProcessError as error:
4148
raise RuntimeError(f"Failed to run the REPL:\n{error.stdout}") from error
49+
except Exception as exc:
50+
if env:
51+
env_str = "\n".join(f"{key}={value!r}" for key, value in sorted(env.items()))
52+
else:
53+
env_str = "<inherited env>"
54+
if isinstance(exc, subprocess.CalledProcessError):
55+
stdout = exc.stdout
56+
else:
57+
stdout = "<unknown>"
58+
exc.add_note(f"""
59+
===== env start =====
60+
{env_str}
61+
===== env end =====
62+
===== input start =====
63+
{input}
64+
===== input end =====
65+
commmand: {self.repl}
66+
===== stdout start =====
67+
{stdout}
68+
===== stdout end =====
69+
""")
70+
raise
4271

4372
def test_repl_version(self):
4473
"""Validates that we can successfully execute arbitrary code on the REPL."""

0 commit comments

Comments
 (0)