Commit ad6139ac authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 79936 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79936 | philip.jenvey | 2010-04-10 15:27:15 -0500 (Sat, 10 Apr 2010) | 3 lines

  fix PYTHONWARNINGS handling to not modify the original env value and improve
  its tests
........
parent 75825a7a
...@@ -694,7 +694,8 @@ class EnvironmentVariableTests(BaseTest): ...@@ -694,7 +694,8 @@ class EnvironmentVariableTests(BaseTest):
p = subprocess.Popen([sys.executable, p = subprocess.Popen([sys.executable,
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
stdout=subprocess.PIPE, env=newenv) stdout=subprocess.PIPE, env=newenv)
self.assertEqual(p.stdout.read(), b"['ignore::DeprecationWarning']") self.assertEqual(p.communicate()[0], b"['ignore::DeprecationWarning']")
self.assertEqual(p.wait(), 0)
def test_comma_separated_warnings(self): def test_comma_separated_warnings(self):
newenv = os.environ.copy() newenv = os.environ.copy()
...@@ -703,8 +704,9 @@ class EnvironmentVariableTests(BaseTest): ...@@ -703,8 +704,9 @@ class EnvironmentVariableTests(BaseTest):
p = subprocess.Popen([sys.executable, p = subprocess.Popen([sys.executable,
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
stdout=subprocess.PIPE, env=newenv) stdout=subprocess.PIPE, env=newenv)
self.assertEqual(p.stdout.read(), self.assertEqual(p.communicate()[0],
b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']") b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']")
self.assertEqual(p.wait(), 0)
def test_envvar_and_command_line(self): def test_envvar_and_command_line(self):
newenv = os.environ.copy() newenv = os.environ.copy()
...@@ -712,8 +714,9 @@ class EnvironmentVariableTests(BaseTest): ...@@ -712,8 +714,9 @@ class EnvironmentVariableTests(BaseTest):
p = subprocess.Popen([sys.executable, "-W" "ignore::UnicodeWarning", p = subprocess.Popen([sys.executable, "-W" "ignore::UnicodeWarning",
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
stdout=subprocess.PIPE, env=newenv) stdout=subprocess.PIPE, env=newenv)
self.assertEqual(p.stdout.read(), self.assertEqual(p.communicate()[0],
b"['ignore::UnicodeWarning', 'ignore::DeprecationWarning']") b"['ignore::UnicodeWarning', 'ignore::DeprecationWarning']")
self.assertEqual(p.wait(), 0)
class CEnvironmentVariableTests(EnvironmentVariableTests): class CEnvironmentVariableTests(EnvironmentVariableTests):
module = c_warnings module = c_warnings
......
...@@ -403,22 +403,27 @@ Py_Main(int argc, wchar_t **argv) ...@@ -403,22 +403,27 @@ Py_Main(int argc, wchar_t **argv)
Py_NoUserSiteDirectory = 1; Py_NoUserSiteDirectory = 1;
if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') { if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
char *buf; char *buf, *warning;
wchar_t *warning;
size_t len; buf = (char *)malloc(strlen(p) + 1);
if (buf == NULL)
for (buf = strtok(p, ","); Py_FatalError(
buf != NULL; "not enough memory to copy PYTHONWARNINGS");
buf = strtok(NULL, ",")) { strcpy(buf, p);
len = strlen(buf); for (warning = strtok(buf, ",");
warning = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); warning != NULL;
if (warning == NULL) warning = strtok(NULL, ",")) {
wchar_t *wide_warning;
size_t len = strlen(buf);
wide_warning = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
if (wide_warning == NULL)
Py_FatalError( Py_FatalError(
"not enough memory to copy PYTHONWARNINGS"); "not enough memory to copy PYTHONWARNINGS");
mbstowcs(warning, buf, len); mbstowcs(wide_warning, warning, len);
PySys_AddWarnOption(warning); PySys_AddWarnOption(wide_warning);
free(warning); free(wide_warning);
} }
free(buf);
} }
if (command == NULL && module == NULL && _PyOS_optind < argc && if (command == NULL && module == NULL && _PyOS_optind < argc &&
......
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