diff -r 290d970c011d Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py Wed May 23 23:16:14 2012 +0200 +++ b/Lib/test/test_warnings.py Wed May 23 14:49:18 2012 -0700 @@ -1,4 +1,5 @@ from contextlib import contextmanager +import marshal import linecache import os import StringIO @@ -706,35 +707,42 @@ class EnvironmentVariableTests(BaseTest): + def check_child(self, env, cmdline, expected): + newenv = os.environ.copy() + newenv["PYTHONWARNINGS"] = env + + cmd = [sys.executable] + if cmdline: + cmd.extend(["-W", cmdline]) + + cmd.extend([ + "-c", + "import sys, marshal; marshal.dump(sys.warnoptions, sys.stdout)", + ]) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=newenv) + self.assertEqual(p.wait(), 0) + child_opts = marshal.load(p.stdout) + self.assertEqual(set(child_opts), set(expected)) + def test_single_warning(self): - newenv = os.environ.copy() - newenv["PYTHONWARNINGS"] = "ignore::DeprecationWarning" - p = subprocess.Popen([sys.executable, - "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], - stdout=subprocess.PIPE, env=newenv) - self.assertEqual(p.communicate()[0], "['ignore::DeprecationWarning']") - self.assertEqual(p.wait(), 0) + self.check_child( + "ignore::DeprecationWarning", + None, + ["ignore::DeprecationWarning"]) def test_comma_separated_warnings(self): - newenv = os.environ.copy() - newenv["PYTHONWARNINGS"] = ("ignore::DeprecationWarning," - "ignore::UnicodeWarning") - p = subprocess.Popen([sys.executable, - "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], - stdout=subprocess.PIPE, env=newenv) - self.assertEqual(p.communicate()[0], - "['ignore::DeprecationWarning', 'ignore::UnicodeWarning']") - self.assertEqual(p.wait(), 0) + self.check_child( + "ignore::DeprecationWarning,ignore::UnicodeWarning", + None, + ['ignore::DeprecationWarning', 'ignore::UnicodeWarning']) def test_envvar_and_command_line(self): - newenv = os.environ.copy() - newenv["PYTHONWARNINGS"] = "ignore::DeprecationWarning" - 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.communicate()[0], - "['ignore::UnicodeWarning', 'ignore::DeprecationWarning']") - self.assertEqual(p.wait(), 0) + self.check_child( + "ignore::DeprecationWarning", + "ignore::UnicodeWarning", + ['ignore::UnicodeWarning', 'ignore::DeprecationWarning']) + class CEnvironmentVariableTests(EnvironmentVariableTests): module = c_warnings @@ -746,15 +754,21 @@ def test_main(): py_warnings.onceregistry.clear() c_warnings.onceregistry.clear() - test_support.run_unittest(CFilterTests, PyFilterTests, - CWarnTests, PyWarnTests, - CWCmdLineTests, PyWCmdLineTests, - _WarningsTests, - CWarningsDisplayTests, PyWarningsDisplayTests, - CCatchWarningTests, PyCatchWarningTests, - CEnvironmentVariableTests, - PyEnvironmentVariableTests - ) + test_support.run_unittest( + CFilterTests, + PyFilterTests, + CWarnTests, + PyWarnTests, + CWCmdLineTests, + PyWCmdLineTests, + _WarningsTests, + CWarningsDisplayTests, + PyWarningsDisplayTests, + CCatchWarningTests, + PyCatchWarningTests, + CEnvironmentVariableTests, + PyEnvironmentVariableTests + ) if __name__ == "__main__":