diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_plistlib.py | 26 | ||||
| -rw-r--r-- | Lib/test/test_subprocess.py | 26 | ||||
| -rw-r--r-- | Lib/test/test_threading.py | 32 |
3 files changed, 75 insertions, 9 deletions
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py index dfa4725..5f980d0 100644 --- a/Lib/test/test_plistlib.py +++ b/Lib/test/test_plistlib.py @@ -175,6 +175,32 @@ class TestPlistlib(unittest.TestCase): self.assertEqual(test1, result1) self.assertEqual(test2, result2) + def test_invalidarray(self): + for i in ["<key>key inside an array</key>", + "<key>key inside an array2</key><real>3</real>", + "<true/><key>key inside an array3</key>"]: + self.assertRaises(ValueError, plistlib.readPlistFromBytes, + ("<plist><array>%s</array></plist>"%i).encode()) + + def test_invaliddict(self): + for i in ["<key><true/>k</key><string>compound key</string>", + "<key>single key</key>", + "<string>missing key</string>", + "<key>k1</key><string>v1</string><real>5.3</real>" + "<key>k1</key><key>k2</key><string>double key</string>"]: + self.assertRaises(ValueError, plistlib.readPlistFromBytes, + ("<plist><dict>%s</dict></plist>"%i).encode()) + self.assertRaises(ValueError, plistlib.readPlistFromBytes, + ("<plist><array><dict>%s</dict></array></plist>"%i).encode()) + + def test_invalidinteger(self): + self.assertRaises(ValueError, plistlib.readPlistFromBytes, + b"<plist><integer>not integer</integer></plist>") + + def test_invalidreal(self): + self.assertRaises(ValueError, plistlib.readPlistFromBytes, + b"<plist><integer>not real</integer></plist>") + def test_main(): support.run_unittest(TestPlistlib) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 176ff10..ad89864 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1399,15 +1399,23 @@ class ProcessTestCaseNoPoll(ProcessTestCase): @unittest.skipUnless(getattr(subprocess, '_posixsubprocess', False), "_posixsubprocess extension module not found.") class ProcessTestCasePOSIXPurePython(ProcessTestCase, POSIXProcessTestCase): - def setUp(self): - subprocess._posixsubprocess = None - ProcessTestCase.setUp(self) - POSIXProcessTestCase.setUp(self) - - def tearDown(self): - subprocess._posixsubprocess = sys.modules['_posixsubprocess'] - POSIXProcessTestCase.tearDown(self) - ProcessTestCase.tearDown(self) + @classmethod + def setUpClass(cls): + global subprocess + assert subprocess._posixsubprocess + # Reimport subprocess while forcing _posixsubprocess to not exist. + with support.check_warnings(('.*_posixsubprocess .* not being used.*', + RuntimeWarning)): + subprocess = support.import_fresh_module( + 'subprocess', blocked=['_posixsubprocess']) + assert not subprocess._posixsubprocess + + @classmethod + def tearDownClass(cls): + global subprocess + # Reimport subprocess as it should be, restoring order to the universe. + subprocess = support.import_fresh_module('subprocess') + assert subprocess._posixsubprocess class HelperFunctionTests(unittest.TestCase): diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 04c3598..416d95f 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -12,6 +12,7 @@ import unittest import weakref import os from test.script_helper import assert_python_ok, assert_python_failure +import subprocess from test import lock_tests @@ -691,6 +692,37 @@ class ThreadingExceptionTests(BaseTestCase): thread.start() self.assertRaises(RuntimeError, setattr, thread, "daemon", True) + @unittest.skipUnless(sys.platform == 'darwin', 'test macosx problem') + def test_recursion_limit(self): + # Issue 9670 + # test that excessive recursion within a non-main thread causes + # an exception rather than crashing the interpreter on platforms + # like Mac OS X or FreeBSD which have small default stack sizes + # for threads + script = """if True: + import threading + + def recurse(): + return recurse() + + def outer(): + try: + recurse() + except RuntimeError: + pass + + w = threading.Thread(target=outer) + w.start() + w.join() + print('end of main thread') + """ + expected_output = "end of main thread\n" + p = subprocess.Popen([sys.executable, "-c", script], + stdout=subprocess.PIPE) + stdout, stderr = p.communicate() + data = stdout.decode().replace('\r', '') + self.assertEqual(p.returncode, 0, "Unexpected error") + self.assertEqual(data, expected_output) class LockTests(lock_tests.LockTests): locktype = staticmethod(threading.Lock) |
