]> granicus.if.org Git - python/commitdiff
fix PYTHONWARNINGS handling to not modify the original env value and improve
authorPhilip Jenvey <pjenvey@underboss.org>
Sat, 10 Apr 2010 20:27:15 +0000 (20:27 +0000)
committerPhilip Jenvey <pjenvey@underboss.org>
Sat, 10 Apr 2010 20:27:15 +0000 (20:27 +0000)
its tests

Lib/test/test_warnings.py
Modules/main.c

index e8df3684dcbf2f4fb404ae8f720207e193a80e2f..4e0afcc659a6dd6282a627dd7b5fa0e63ee78054 100644 (file)
@@ -683,7 +683,8 @@ class EnvironmentVariableTests(BaseTest):
         p = subprocess.Popen([sys.executable,
                 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
                 stdout=subprocess.PIPE, env=newenv)
-        self.assertEqual(p.stdout.read(), "['ignore::DeprecationWarning']")
+        self.assertEqual(p.communicate()[0], "['ignore::DeprecationWarning']")
+        self.assertEqual(p.wait(), 0)
 
     def test_comma_separated_warnings(self):
         newenv = os.environ.copy()
@@ -692,8 +693,9 @@ class EnvironmentVariableTests(BaseTest):
         p = subprocess.Popen([sys.executable,
                 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
                 stdout=subprocess.PIPE, env=newenv)
-        self.assertEqual(p.stdout.read(),
+        self.assertEqual(p.communicate()[0],
                 "['ignore::DeprecationWarning', 'ignore::UnicodeWarning']")
+        self.assertEqual(p.wait(), 0)
 
     def test_envvar_and_command_line(self):
         newenv = os.environ.copy()
@@ -701,8 +703,9 @@ class EnvironmentVariableTests(BaseTest):
         p = subprocess.Popen([sys.executable, "-W" "ignore::UnicodeWarning",
                 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
                 stdout=subprocess.PIPE, env=newenv)
-        self.assertEqual(p.stdout.read(),
+        self.assertEqual(p.communicate()[0],
                 "['ignore::UnicodeWarning', 'ignore::DeprecationWarning']")
+        self.assertEqual(p.wait(), 0)
 
 class CEnvironmentVariableTests(EnvironmentVariableTests):
     module = c_warnings
index 0ba01f79dbbfb4a21a10ba8021c8782b58cd7f78..11ac97e6938d0152d37cb83c8654872af7c918ec 100644 (file)
@@ -421,14 +421,19 @@ Py_Main(int argc, char **argv)
            (p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')
                Py_NoUserSiteDirectory = 1;
 
-       if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0')
-       {
-               char* warning = strtok(p, ",");
-               while (warning != NULL)
-               {
+       if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
+               char *buf, *warning;
+
+               buf = (char *)malloc(strlen(p) + 1);
+               if (buf == NULL)
+                       Py_FatalError(
+                          "not enough memory to copy PYTHONWARNINGS");
+               strcpy(buf, p);
+               for (warning = strtok(buf, ",");
+                    warning != NULL;
+                    warning = strtok(NULL, ","))
                        PySys_AddWarnOption(warning);
-                       warning = strtok(NULL, ",");
-               }
+               free(buf);
        }
 
        if (command == NULL && module == NULL && _PyOS_optind < argc &&