Commit 23f41a3e authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Change the way how locales are overridden:

- Set only LC_ALL, it overrides any other variable
- Restore environment after unittest

Reviewed-by: iustinp
parent 3312b702
......@@ -209,13 +209,13 @@ def RunCmd(cmd):
strcmd = cmd
shell = True
new_env = dict([(key, val) for (key, val) in os.environ.items()
if not (key == "LANG" or key.startswith("LC_"))])
env = os.environ.copy()
env["LC_ALL"] = "C"
child = subprocess.Popen(cmd, shell=shell,
close_fds=True, env=new_env)
close_fds=True, env=env)
out =
......@@ -151,13 +151,20 @@ class TestRunCmd(unittest.TestCase):
def testLang(self):
"""Test locale environment"""
os.environ["LANG"] = "en_US.UTF-8"
os.environ["LC_ALL"] = "en_US.UTF-8"
result = RunCmd(["env"])
for line in result.output.splitlines():
key, val = line.split("=", 1)
if key.startswith("LC_") or key == "LANG":"Unexpected language variable '%s' = '%s'" % (key, val))
old_env = os.environ.copy()
os.environ["LANG"] = "en_US.UTF-8"
os.environ["LC_ALL"] = "en_US.UTF-8"
result = RunCmd(["locale"])
for line in result.output.splitlines():
key, value = line.split("=", 1)
# Ignore these variables, they're overridden by LC_ALL
if key == "LANG" or key == "LANGUAGE":
self.failIf(value and value != "C" and value != '"C"',
"Variable %s is set to the invalid value '%s'" % (key, value))
os.environ = old_env
class TestRemoveFile(unittest.TestCase):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment