summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2015-09-07 05:27:42 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2015-09-07 05:27:42 (GMT)
commitf35bd306ffa2c05a1297435bb15cd3b4d47b3977 (patch)
tree8a909b9eb6a5325a5ebbcbdc5858dd798d78db0d /Lib/test
parentda19767b86dcee5810ad8c77a05811be041d7c89 (diff)
parentc1635e497d060bae076127152801af2b2ec552ff (diff)
downloadcpython-f35bd306ffa2c05a1297435bb15cd3b4d47b3977.zip
cpython-f35bd306ffa2c05a1297435bb15cd3b4d47b3977.tar.gz
cpython-f35bd306ffa2c05a1297435bb15cd3b4d47b3977.tar.bz2
Merge from 3.5.0 branch.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/imp_dummy.py3
-rw-r--r--Lib/test/test_imp.py24
-rw-r--r--Lib/test/test_time.py13
-rw-r--r--Lib/test/test_warnings/__init__.py (renamed from Lib/test/test_warnings.py)37
-rw-r--r--Lib/test/test_warnings/__main__.py3
-rw-r--r--Lib/test/test_warnings/data/import_warning.py3
-rw-r--r--Lib/test/test_warnings/data/stacklevel.py (renamed from Lib/test/warning_tests.py)0
7 files changed, 67 insertions, 16 deletions
diff --git a/Lib/test/imp_dummy.py b/Lib/test/imp_dummy.py
new file mode 100644
index 0000000..2a4deb4
--- /dev/null
+++ b/Lib/test/imp_dummy.py
@@ -0,0 +1,3 @@
+# Fodder for test of issue24748 in test_imp
+
+dummy_name = True
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 47bf1de..ee9ee1a 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -3,6 +3,7 @@ try:
except ImportError:
_thread = None
import importlib
+import importlib.util
import os
import os.path
import shutil
@@ -275,6 +276,29 @@ class ImportTests(unittest.TestCase):
self.skipTest("found module doesn't appear to be a C extension")
imp.load_module(name, None, *found[1:])
+ @requires_load_dynamic
+ def test_issue24748_load_module_skips_sys_modules_check(self):
+ name = 'test.imp_dummy'
+ try:
+ del sys.modules[name]
+ except KeyError:
+ pass
+ try:
+ module = importlib.import_module(name)
+ spec = importlib.util.find_spec('_testmultiphase')
+ module = imp.load_dynamic(name, spec.origin)
+ self.assertEqual(module.__name__, name)
+ self.assertEqual(module.__spec__.name, name)
+ self.assertEqual(module.__spec__.origin, spec.origin)
+ self.assertRaises(AttributeError, getattr, module, 'dummy_name')
+ self.assertEqual(module.int_const, 1969)
+ self.assertIs(sys.modules[name], module)
+ finally:
+ try:
+ del sys.modules[name]
+ except KeyError:
+ pass
+
@unittest.skipIf(sys.dont_write_bytecode,
"test meaningful only when writing bytecode")
def test_bug7732(self):
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 6334e02..6bcd212 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -174,6 +174,19 @@ class TimeTestCase(unittest.TestCase):
def test_strftime_bounding_check(self):
self._bounds_checking(lambda tup: time.strftime('', tup))
+ def test_strftime_format_check(self):
+ # Test that strftime does not crash on invalid format strings
+ # that may trigger a buffer overread. When not triggered,
+ # strftime may succeed or raise ValueError depending on
+ # the platform.
+ for x in [ '', 'A', '%A', '%AA' ]:
+ for y in range(0x0, 0x10):
+ for z in [ '%', 'A%', 'AA%', '%A%', 'A%A%', '%#' ]:
+ try:
+ time.strftime(x * y + z)
+ except ValueError:
+ pass
+
def test_default_values_for_zero(self):
# Make sure that using all zeros uses the proper default
# values. No test for daylight savings since strftime() does
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings/__init__.py
index 03d9958..991a249 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -7,7 +7,7 @@ import unittest
from test import support
from test.support.script_helper import assert_python_ok, assert_python_failure
-from test import warning_tests
+from test.test_warnings.data import stacklevel as warning_tests
import warnings as original_warnings
@@ -44,7 +44,6 @@ class BaseTest:
"""Basic bookkeeping required for testing."""
def setUp(self):
- self.old_unittest_module = unittest.case.warnings
# The __warningregistry__ needs to be in a pristine state for tests
# to work properly.
if '__warningregistry__' in globals():
@@ -56,15 +55,10 @@ class BaseTest:
# The 'warnings' module must be explicitly set so that the proper
# interaction between _warnings and 'warnings' can be controlled.
sys.modules['warnings'] = self.module
- # Ensure that unittest.TestCase.assertWarns() uses the same warnings
- # module than warnings.catch_warnings(). Otherwise,
- # warnings.catch_warnings() will be unable to remove the added filter.
- unittest.case.warnings = self.module
super(BaseTest, self).setUp()
def tearDown(self):
sys.modules['warnings'] = original_warnings
- unittest.case.warnings = self.old_unittest_module
super(BaseTest, self).tearDown()
class PublicAPITests(BaseTest):
@@ -194,11 +188,11 @@ class FilterTests(BaseTest):
self.module.resetwarnings()
self.module.filterwarnings("once", category=UserWarning)
message = UserWarning("FilterTests.test_once")
- self.module.warn_explicit(message, UserWarning, "test_warnings.py",
+ self.module.warn_explicit(message, UserWarning, "__init__.py",
42)
self.assertEqual(w[-1].message, message)
del w[:]
- self.module.warn_explicit(message, UserWarning, "test_warnings.py",
+ self.module.warn_explicit(message, UserWarning, "__init__.py",
13)
self.assertEqual(len(w), 0)
self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
@@ -304,10 +298,10 @@ class WarnTests(BaseTest):
module=self.module) as w:
warning_tests.inner("spam1")
self.assertEqual(os.path.basename(w[-1].filename),
- "warning_tests.py")
+ "stacklevel.py")
warning_tests.outer("spam2")
self.assertEqual(os.path.basename(w[-1].filename),
- "warning_tests.py")
+ "stacklevel.py")
def test_stacklevel(self):
# Test stacklevel argument
@@ -317,25 +311,36 @@ class WarnTests(BaseTest):
module=self.module) as w:
warning_tests.inner("spam3", stacklevel=1)
self.assertEqual(os.path.basename(w[-1].filename),
- "warning_tests.py")
+ "stacklevel.py")
warning_tests.outer("spam4", stacklevel=1)
self.assertEqual(os.path.basename(w[-1].filename),
- "warning_tests.py")
+ "stacklevel.py")
warning_tests.inner("spam5", stacklevel=2)
self.assertEqual(os.path.basename(w[-1].filename),
- "test_warnings.py")
+ "__init__.py")
warning_tests.outer("spam6", stacklevel=2)
self.assertEqual(os.path.basename(w[-1].filename),
- "warning_tests.py")
+ "stacklevel.py")
warning_tests.outer("spam6.5", stacklevel=3)
self.assertEqual(os.path.basename(w[-1].filename),
- "test_warnings.py")
+ "__init__.py")
warning_tests.inner("spam7", stacklevel=9999)
self.assertEqual(os.path.basename(w[-1].filename),
"sys")
+ def test_stacklevel_import(self):
+ # Issue #24305: With stacklevel=2, module-level warnings should work.
+ support.unload('test.test_warnings.data.import_warning')
+ with warnings_state(self.module):
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.simplefilter('always')
+ import test.test_warnings.data.import_warning
+ self.assertEqual(len(w), 1)
+ self.assertEqual(w[0].filename, __file__)
+
def test_missing_filename_not_main(self):
# If __file__ is not specified and __main__ is not the module name,
# then __file__ should be set to the module name.
diff --git a/Lib/test/test_warnings/__main__.py b/Lib/test/test_warnings/__main__.py
new file mode 100644
index 0000000..44e52ec
--- /dev/null
+++ b/Lib/test/test_warnings/__main__.py
@@ -0,0 +1,3 @@
+import unittest
+
+unittest.main('test.test_warnings')
diff --git a/Lib/test/test_warnings/data/import_warning.py b/Lib/test/test_warnings/data/import_warning.py
new file mode 100644
index 0000000..d6ea2ce
--- /dev/null
+++ b/Lib/test/test_warnings/data/import_warning.py
@@ -0,0 +1,3 @@
+import warnings
+
+warnings.warn('module-level warning', DeprecationWarning, stacklevel=2) \ No newline at end of file
diff --git a/Lib/test/warning_tests.py b/Lib/test/test_warnings/data/stacklevel.py
index d0519ef..d0519ef 100644
--- a/Lib/test/warning_tests.py
+++ b/Lib/test/test_warnings/data/stacklevel.py