##// END OF EJS Templates
tests: more completely restore the environment in syshgenv...
Adam Simpkins -
r33121:98e2c78e default
parent child Browse files
Show More
@@ -18,10 +18,7 b' syshg () {'
18 # Revert the environment so that running "hg" runs the system hg
18 # Revert the environment so that running "hg" runs the system hg
19 # rather than the test hg installation.
19 # rather than the test hg installation.
20 syshgenv () {
20 syshgenv () {
21 PATH="$ORIG_PATH"
21 . "$HGTEST_RESTOREENV"
22 PYTHONPATH="$ORIG_PYTHONPATH"
23 JYTHONPATH="$ORIG_JYTHONPATH"
24 unset HGRCPATH
25 HGPLAIN=1
22 HGPLAIN=1
26 export HGPLAIN
23 export HGPLAIN
27 }
24 }
@@ -70,6 +70,13 b' try:'
70 except ImportError:
70 except ImportError:
71 import queue
71 import queue
72
72
73 try:
74 import shlex
75 shellquote = shlex.quote
76 except (ImportError, AttributeError):
77 import pipes
78 shellquote = pipes.quote
79
73 if os.environ.get('RTUNICODEPEDANTRY', False):
80 if os.environ.get('RTUNICODEPEDANTRY', False):
74 try:
81 try:
75 reload(sys)
82 reload(sys)
@@ -752,6 +759,7 b' class Test(unittest.TestCase):'
752 This will return a tuple describing the result of the test.
759 This will return a tuple describing the result of the test.
753 """
760 """
754 env = self._getenv()
761 env = self._getenv()
762 self._genrestoreenv(env)
755 self._daemonpids.append(env['DAEMON_PIDS'])
763 self._daemonpids.append(env['DAEMON_PIDS'])
756 self._createhgrc(env['HGRCPATH'])
764 self._createhgrc(env['HGRCPATH'])
757
765
@@ -888,6 +896,30 b' class Test(unittest.TestCase):'
888 else:
896 else:
889 return b'127.0.0.1'
897 return b'127.0.0.1'
890
898
899 def _genrestoreenv(self, testenv):
900 """Generate a script that can be used by tests to restore the original
901 environment."""
902 # Put the restoreenv script inside self._threadtmp
903 scriptpath = os.path.join(self._threadtmp, b'restoreenv.sh')
904 testenv['HGTEST_RESTOREENV'] = scriptpath
905
906 # Only restore environment variable names that the shell allows
907 # us to export.
908 name_regex = re.compile('[a-zA-Z][a-zA-Z0-9_]*')
909
910 with open(scriptpath, 'w') as envf:
911 for name, value in os.environ.items():
912 if not name_regex.match(name):
913 # Skip environment variables with unusual names not
914 # allowed by most shells.
915 continue
916 envf.write('%s=%s\n' % (name, shellquote(value)))
917
918 for name in testenv:
919 if name in os.environ:
920 continue
921 envf.write('unset %s\n' % (name,))
922
891 def _getenv(self):
923 def _getenv(self):
892 """Obtain environment variables to use during test execution."""
924 """Obtain environment variables to use during test execution."""
893 def defineport(i):
925 def defineport(i):
@@ -2274,9 +2306,6 b' class TestRunner(object):'
2274 sepb = _bytespath(os.pathsep)
2306 sepb = _bytespath(os.pathsep)
2275 else:
2307 else:
2276 sepb = os.pathsep
2308 sepb = os.pathsep
2277 # save the original path, for tests that need to invoke the
2278 # system python
2279 osenvironb[b"ORIG_PATH"] = osenvironb[b"PATH"]
2280 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb)
2309 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb)
2281 if os.path.islink(__file__):
2310 if os.path.islink(__file__):
2282 # test helper will likely be at the end of the symlink
2311 # test helper will likely be at the end of the symlink
@@ -2302,7 +2331,6 b' class TestRunner(object):'
2302 # are in /opt/subversion.)
2331 # are in /opt/subversion.)
2303 oldpypath = osenvironb.get(IMPL_PATH)
2332 oldpypath = osenvironb.get(IMPL_PATH)
2304 if oldpypath:
2333 if oldpypath:
2305 osenvironb['ORIG_' + IMPL_PATH] = oldpypath
2306 pypath.append(oldpypath)
2334 pypath.append(oldpypath)
2307 osenvironb[IMPL_PATH] = sepb.join(pypath)
2335 osenvironb[IMPL_PATH] = sepb.join(pypath)
2308
2336
General Comments 0
You need to be logged in to leave comments. Login now