summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_logging.py31
-rw-r--r--Lib/test/test_subprocess.py34
2 files changed, 63 insertions, 2 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index c99a650ca8..c179d1457f 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -18,7 +18,7 @@
"""Test harness for the logging module. Run all tests.
-Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
"""
import logging
@@ -44,6 +44,7 @@ import threading
import time
import types
import unittest
+import warnings
import weakref
@@ -885,6 +886,32 @@ class EncodingTest(BaseTest):
if os.path.isfile(fn):
os.remove(fn)
+class WarningsTest(BaseTest):
+ def test_warnings(self):
+ logging.captureWarnings(True)
+ warnings.filterwarnings("always", category=UserWarning)
+ try:
+ file = io.StringIO()
+ h = logging.StreamHandler(file)
+ logger = logging.getLogger("py.warnings")
+ logger.addHandler(h)
+ warnings.warn("I'm warning you...")
+ logger.removeHandler(h)
+ s = file.getvalue()
+ h.close()
+ self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
+
+ #See if an explicit file uses the original implementation
+ file = io.StringIO()
+ warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, file,
+ "Dummy line")
+ s = file.getvalue()
+ file.close()
+ self.assertEqual(s, "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
+ finally:
+ warnings.resetwarnings()
+ logging.captureWarnings(False)
+
# Set the locale to the platform-dependent default. I have no idea
# why the test does this, but in any case we save the current locale
# first and restore it at the end.
@@ -893,7 +920,7 @@ def test_main():
run_unittest(BuiltinLevelsTest, BasicFilterTest,
CustomLevelsAndFiltersTest, MemoryHandlerTest,
ConfigFileTest, SocketHandlerTest, MemoryTest,
- EncodingTest)
+ EncodingTest, WarningsTest)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index f4f1cd5a86..eb4e759336 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -73,6 +73,40 @@ class ProcessTestCase(unittest.TestCase):
else:
self.fail("Expected CalledProcessError")
+ def test_check_output(self):
+ # check_output() function with zero return code
+ output = subprocess.check_output(
+ [sys.executable, "-c", "print('BDFL')"])
+ self.assertTrue(b'BDFL' in output)
+
+ def test_check_output_nonzero(self):
+ # check_call() function with non-zero return code
+ try:
+ subprocess.check_output(
+ [sys.executable, "-c", "import sys; sys.exit(5)"])
+ except subprocess.CalledProcessError as e:
+ self.assertEqual(e.returncode, 5)
+ else:
+ self.fail("Expected CalledProcessError")
+
+ def test_check_output_stderr(self):
+ # check_output() function stderr redirected to stdout
+ output = subprocess.check_output(
+ [sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
+ stderr=subprocess.STDOUT)
+ self.assertTrue(b'BDFL' in output)
+
+ def test_check_output_stdout_arg(self):
+ # check_output() function stderr redirected to stdout
+ try:
+ output = subprocess.check_output(
+ [sys.executable, "-c", "print('will not be run')"],
+ stdout=sys.stdout)
+ except ValueError as e:
+ self.assertTrue('stdout' in e.args[0])
+ else:
+ self.fail("Expected ValueError when stdout arg supplied.")
+
def test_call_kwargs(self):
# call() function with keyword args
newenv = os.environ.copy()