summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_marshal.py8
-rw-r--r--Lib/test/test_support.py33
-rw-r--r--Lib/test/test_textwrap.py8
3 files changed, 49 insertions, 0 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 66545e0..838207a 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -199,6 +199,14 @@ class BugsTestCase(unittest.TestCase):
subtyp = type('subtyp', (typ,), {})
self.assertRaises(ValueError, marshal.dumps, subtyp())
+ # Issue #1792 introduced a change in how marshal increases the size of its
+ # internal buffer; this test ensures that the new code is exercised.
+ def test_large_marshal(self):
+ size = int(1e6)
+ testString = 'abc' * size
+ marshal.dumps(testString)
+
+
def test_main():
test_support.run_unittest(IntTestCase,
FloatTestCase,
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 27a01ea..c4084bb 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -409,6 +409,39 @@ def catch_warning(module=warnings, record=True):
module.showwarning = original_showwarning
module.filters = original_filters
+
+class CleanImport(object):
+ """Context manager to force import to return a new module reference.
+
+ This is useful for testing module-level behaviours, such as
+ the emission of a DepreciationWarning on import.
+
+ Use like this:
+
+ with CleanImport("foo"):
+ __import__("foo") # new reference
+ """
+
+ def __init__(self, *module_names):
+ self.original_modules = sys.modules.copy()
+ for module_name in module_names:
+ if module_name in sys.modules:
+ module = sys.modules[module_name]
+ # It is possible that module_name is just an alias for
+ # another module (e.g. stub for modules renamed in 3.x).
+ # In that case, we also need delete the real module to clear
+ # the import cache.
+ if module.__name__ != module_name:
+ del sys.modules[module.__name__]
+ del sys.modules[module_name]
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *ignore_exc):
+ sys.modules.update(self.original_modules)
+
+
class EnvironmentVarGuard(object):
"""Class to help protect the environment variable properly. Can be used as
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index dc97d40..1a9761a 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -351,6 +351,14 @@ What a mess!
["Hello", " ", "there", " ", "--", " ", "you", " ", "goof-",
"ball,", " ", "use", " ", "the", " ", "-b", " ", "option!"])
+ def test_break_on_hyphens(self):
+ # Ensure that the break_on_hyphens attributes work
+ text = "yaba daba-doo"
+ self.check_wrap(text, 10, ["yaba daba-", "doo"],
+ break_on_hyphens=True)
+ self.check_wrap(text, 10, ["yaba", "daba-doo"],
+ break_on_hyphens=False)
+
def test_bad_width(self):
# Ensure that width <= 0 is caught.
text = "Whatever, it doesn't matter."