diff options
| author | Philip Jenvey <pjenvey@underboss.org> | 2010-04-06 23:24:45 (GMT) |
|---|---|---|
| committer | Philip Jenvey <pjenvey@underboss.org> | 2010-04-06 23:24:45 (GMT) |
| commit | aebbaeb962b306d6143f77762dd53fae176bcf0e (patch) | |
| tree | 50306f126f5f937e36252821dcfcd4398a4b3c82 /Lib/test/test_warnings.py | |
| parent | c1bf677e28a52b501ab9f93a6b78c6c0abbcc8ce (diff) | |
| download | cpython-aebbaeb962b306d6143f77762dd53fae176bcf0e.zip cpython-aebbaeb962b306d6143f77762dd53fae176bcf0e.tar.gz cpython-aebbaeb962b306d6143f77762dd53fae176bcf0e.tar.bz2 | |
#7301: add the environment variable $PYTHONWARNINGS to supplement the -W
command line option
patch from Brian Curtin
Diffstat (limited to 'Lib/test/test_warnings.py')
| -rw-r--r-- | Lib/test/test_warnings.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index a0a65b4..e8df368 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -4,6 +4,7 @@ import os import StringIO import sys import unittest +import subprocess from test import test_support import warning_tests @@ -674,6 +675,42 @@ class PyCatchWarningTests(CatchWarningTests): module = py_warnings +class EnvironmentVariableTests(BaseTest): + + 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.stdout.read(), "['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.stdout.read(), + "['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.stdout.read(), + "['ignore::UnicodeWarning', 'ignore::DeprecationWarning']") + +class CEnvironmentVariableTests(EnvironmentVariableTests): + module = c_warnings + +class PyEnvironmentVariableTests(EnvironmentVariableTests): + module = py_warnings + + def test_main(): py_warnings.onceregistry.clear() c_warnings.onceregistry.clear() @@ -683,6 +720,8 @@ def test_main(): _WarningsTests, CWarningsDisplayTests, PyWarningsDisplayTests, CCatchWarningTests, PyCatchWarningTests, + CEnvironmentVariableTests, + PyEnvironmentVariableTests ) |
