summaryrefslogtreecommitdiff
path: root/Lib/test/test_warnings.py
diff options
context:
space:
mode:
authorPhilip Jenvey <pjenvey@underboss.org>2010-04-07 04:04:10 +0000
committerPhilip Jenvey <pjenvey@underboss.org>2010-04-07 04:04:10 +0000
commit0805ca3f931ccd4735dcaa231752371deadf5ccf (patch)
tree39545abe56278b67c831df94acca0b897c61691f /Lib/test/test_warnings.py
parent42dfeec893fb924cb8dda2a0bddf3fd54ab3c9e3 (diff)
downloadcpython-git-0805ca3f931ccd4735dcaa231752371deadf5ccf.tar.gz
Merged revisions 79878-79880 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79878 | philip.jenvey | 2010-04-06 16:24:45 -0700 (Tue, 06 Apr 2010) | 4 lines #7301: add the environment variable $PYTHONWARNINGS to supplement the -W command line option patch from Brian Curtin ........ r79879 | benjamin.peterson | 2010-04-06 16:32:27 -0700 (Tue, 06 Apr 2010) | 1 line tell people to update python.man, too ........ r79880 | philip.jenvey | 2010-04-06 16:38:57 -0700 (Tue, 06 Apr 2010) | 1 line document new PYTHONWARNINGS env var ........
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r--Lib/test/test_warnings.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 7bd71914b4..fa83fca42a 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -4,6 +4,7 @@ import os
from io import StringIO
import sys
import unittest
+import subprocess
from test import support
from test import warning_tests
@@ -685,6 +686,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(), b"['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(),
+ b"['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(),
+ b"['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()
@@ -696,6 +733,8 @@ def test_main():
_WarningsTests,
CWarningsDisplayTests, PyWarningsDisplayTests,
CCatchWarningTests, PyCatchWarningTests,
+ CEnvironmentVariableTests,
+ PyEnvironmentVariableTests
)