Comments
Patch
@@ -879,17 +879,33 @@ class PythonTest(Test):
"""A Python-based test."""
@property
def refpath(self):
return os.path.join(self._testdir, b'%s.out' % self.bname)
def _run(self, env):
py3kswitch = self._py3kwarnings and b' -3' or b''
- cmd = b'%s%s "%s"' % (PYTHON, py3kswitch, self.path)
+
+ # We don't write the test path directly to the file in order to
+ # avoid quoting concerns.
+ testlines = [
+ b'import sys',
+ b'from hghave import require',
+ b'with open(sys.argv[1], "rb") as fh:',
+ b' code = compile(fh.read(), sys.argv[1], "exec")',
+ b'exec(code)',
+ ]
+
+ testpath = os.path.join(self._testtmp, b'test.py')
+ with open(testpath, 'wb') as fh:
+ fh.write(b'\n'.join(testlines))
+
+ cmd = b'%s%s "%s" "%s"' % (PYTHON, py3kswitch, testpath, self.path)
+
vlog("# Running", cmd)
normalizenewlines = os.name == 'nt'
result = self._runcommand(cmd, env,
normalizenewlines=normalizenewlines)
if self._aborted:
raise KeyboardInterrupt()
return result