Python test.test_support.check_warnings() Examples
The following are 30
code examples of test.test_support.check_warnings().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
test.test_support
, or try the search function
.
Example #1
Source File: test_doctest.py From BinderFilter with MIT License | 6 votes |
def test_main(): # Check the doctest cases in doctest itself: test_support.run_doctest(doctest, verbosity=True) from test import test_doctest # Ignore all warnings about the use of class Tester in this module. deprecations = [] if __debug__: deprecations.append(("class Tester is deprecated", DeprecationWarning)) if sys.py3kwarning: deprecations += [("backquote not supported", SyntaxWarning), ("execfile.. not supported", DeprecationWarning)] with test_support.check_warnings(*deprecations): # Check the doctest cases defined here: test_support.run_doctest(test_doctest, verbosity=True)
Example #2
Source File: test_doctest.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_main(): # Check the doctest cases in doctest itself: test_support.run_doctest(doctest, verbosity=True) from test import test_doctest # Ignore all warnings about the use of class Tester in this module. deprecations = [] if __debug__: deprecations.append(("class Tester is deprecated", DeprecationWarning)) if sys.py3kwarning: deprecations += [("backquote not supported", SyntaxWarning), ("execfile.. not supported", DeprecationWarning)] with test_support.check_warnings(*deprecations): # Check the doctest cases defined here: test_support.run_doctest(test_doctest, verbosity=True)
Example #3
Source File: test_xml_etree.py From BinderFilter with MIT License | 6 votes |
def __init__(self, quiet=False): if sys.flags.optimize >= 2: # under -OO, doctests cannot be run and therefore not all warnings # will be emitted quiet = True deprecations = ( # Search behaviour is broken if search path starts with "/". ("This search is broken in 1.3 and earlier, and will be fixed " "in a future version. If you rely on the current behaviour, " "change it to '.+'", FutureWarning), # Element.getchildren() and Element.getiterator() are deprecated. ("This method will be removed in future versions. " "Use .+ instead.", DeprecationWarning), ("This method will be removed in future versions. " "Use .+ instead.", PendingDeprecationWarning), # XMLParser.doctype() is deprecated. ("This method of XMLParser is deprecated. Define doctype.. " "method on the TreeBuilder target.", DeprecationWarning)) self.checkwarnings = test_support.check_warnings(*deprecations, quiet=quiet)
Example #4
Source File: test_urllib2.py From BinderFilter with MIT License | 6 votes |
def test_basic_auth_with_unquoted_realm(self): opener = OpenerDirector() password_manager = MockPasswordManager() auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) realm = "ACME Widget Store" http_handler = MockHTTPHandler( 401, 'WWW-Authenticate: Basic realm=%s\r\n\r\n' % realm) opener.add_handler(auth_handler) opener.add_handler(http_handler) msg = "Basic Auth Realm was unquoted" with test_support.check_warnings((msg, UserWarning)): self._test_basic_auth(opener, auth_handler, "Authorization", realm, http_handler, password_manager, "http://acme.example.com/protected", "http://acme.example.com/protected" )
Example #5
Source File: test_ascii_formatd.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_format(self): buf = create_string_buffer(' ' * 100) tests = [ ('%f', 100.0), ('%g', 100.0), ('%#g', 100.0), ('%#.2g', 100.0), ('%#.2g', 123.4567), ('%#.2g', 1.234567e200), ('%e', 1.234567e200), ('%e', 1.234), ('%+e', 1.234), ('%-e', 1.234), ] with check_warnings(('PyOS_ascii_formatd is deprecated', DeprecationWarning)): for format, val in tests: PyOS_ascii_formatd(byref(buf), sizeof(buf), format, c_double(val)) self.assertEqual(buf.value, format % val)
Example #6
Source File: test___all__.py From BinderFilter with MIT License | 6 votes |
def check_all(self, modname): names = {} with support.check_warnings((".* (module|package)", DeprecationWarning), quiet=True): try: exec "import %s" % modname in names except: # Silent fail here seems the best route since some modules # may not be available or not initialize properly in all # environments. raise FailedImport(modname) if not hasattr(sys.modules[modname], "__all__"): raise NoAll(modname) names = {} try: exec "from %s import *" % modname in names except Exception as e: # Include the module name in the exception string self.fail("__all__ failure in {}: {}: {}".format( modname, e.__class__.__name__, e)) if "__builtins__" in names: del names["__builtins__"] keys = set(names) all = set(sys.modules[modname].__all__) self.assertEqual(keys, all)
Example #7
Source File: test_ascii_formatd.py From BinderFilter with MIT License | 6 votes |
def test_format(self): buf = create_string_buffer(' ' * 100) tests = [ ('%f', 100.0), ('%g', 100.0), ('%#g', 100.0), ('%#.2g', 100.0), ('%#.2g', 123.4567), ('%#.2g', 1.234567e200), ('%e', 1.234567e200), ('%e', 1.234), ('%+e', 1.234), ('%-e', 1.234), ] with check_warnings(('PyOS_ascii_formatd is deprecated', DeprecationWarning)): for format, val in tests: PyOS_ascii_formatd(byref(buf), sizeof(buf), format, c_double(val)) self.assertEqual(buf.value, format % val)
Example #8
Source File: test_tarfile.py From BinderFilter with MIT License | 6 votes |
def test_exclude(self): tempdir = os.path.join(TEMPDIR, "exclude") os.mkdir(tempdir) try: for name in ("foo", "bar", "baz"): name = os.path.join(tempdir, name) open(name, "wb").close() exclude = os.path.isfile tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") with test_support.check_warnings(("use the filter argument", DeprecationWarning)): tar.add(tempdir, arcname="empty_dir", exclude=exclude) tar.close() tar = tarfile.open(tmpname, "r") self.assertEqual(len(tar.getmembers()), 1) self.assertEqual(tar.getnames()[0], "empty_dir") finally: shutil.rmtree(tempdir)
Example #9
Source File: test_urllib2.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_basic_auth_with_unquoted_realm(self): opener = OpenerDirector() password_manager = MockPasswordManager() auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) realm = "ACME Widget Store" http_handler = MockHTTPHandler( 401, 'WWW-Authenticate: Basic realm=%s\r\n\r\n' % realm) opener.add_handler(auth_handler) opener.add_handler(http_handler) msg = "Basic Auth Realm was unquoted" with test_support.check_warnings((msg, UserWarning)): self._test_basic_auth(opener, auth_handler, "Authorization", realm, http_handler, password_manager, "http://acme.example.com/protected", "http://acme.example.com/protected" )
Example #10
Source File: test___all__.py From ironpython2 with Apache License 2.0 | 6 votes |
def check_all(self, modname): names = {} with support.check_warnings((".* (module|package)", DeprecationWarning), quiet=True): try: exec "import %s" % modname in names except: # Silent fail here seems the best route since some modules # may not be available or not initialize properly in all # environments. raise FailedImport(modname) if not hasattr(sys.modules[modname], "__all__"): raise NoAll(modname) names = {} try: exec "from %s import *" % modname in names except Exception as e: # Include the module name in the exception string self.fail("__all__ failure in {}: {}: {}".format( modname, e.__class__.__name__, e)) if "__builtins__" in names: del names["__builtins__"] keys = set(names) all = set(sys.modules[modname].__all__) self.assertEqual(keys, all)
Example #11
Source File: test_io.py From oss-ftp with MIT License | 5 votes |
def test_constructor_max_buffer_size_deprecation(self): with support.check_warnings(("max_buffer_size is deprecated", DeprecationWarning)): self.tp(self.MockRawIO(), self.MockRawIO(), 8, 12)
Example #12
Source File: test_importhooks.py From oss-ftp with MIT License | 5 votes |
def testImpWrapper(self): i = ImpWrapper() sys.meta_path.append(i) sys.path_hooks.append(ImpWrapper) mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc") for mname in mnames: parent = mname.split(".")[0] for n in sys.modules.keys(): if n.startswith(parent): del sys.modules[n] with test_support.check_warnings(("The compiler package is deprecated " "and removed", DeprecationWarning)): for mname in mnames: m = __import__(mname, globals(), locals(), ["__dummy__"]) m.__loader__ # to make sure we actually handled the import
Example #13
Source File: test_cookie.py From BinderFilter with MIT License | 5 votes |
def test_main(): run_unittest(CookieTests) if Cookie.__doc__ is not None: with check_warnings(('.+Cookie class is insecure; do not use it', DeprecationWarning)): run_doctest(Cookie)
Example #14
Source File: test_result.py From oss-ftp with MIT License | 5 votes |
def assertOldResultWarning(self, test, failures): with test_support.check_warnings(("TestResult has no add.+ method,", RuntimeWarning)): result = OldResult() test.run(result) self.assertEqual(len(result.failures), failures)
Example #15
Source File: test_structmembers.py From BinderFilter with MIT License | 5 votes |
def test_ushort_max(self): with test_support.check_warnings(('', RuntimeWarning)): ts.T_USHORT = USHRT_MAX+1
Example #16
Source File: test_sdist.py From oss-ftp with MIT License | 5 votes |
def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated dist, cmd = self.get_cmd() with check_warnings() as w: warnings.simplefilter("always") cmd.check_metadata() self.assertEqual(len(w.warnings), 1)
Example #17
Source File: test_archive_util.py From oss-ftp with MIT License | 5 votes |
def test_compress_deprecated(self): tmpdir, tmpdir2, base_name = self._create_files() # using compress and testing the PendingDeprecationWarning old_dir = os.getcwd() os.chdir(tmpdir) try: with check_warnings() as w: warnings.simplefilter("always") make_tarball(base_name, 'dist', compress='compress') finally: os.chdir(old_dir) tarball = base_name + '.tar.Z' self.assertTrue(os.path.exists(tarball)) self.assertEqual(len(w.warnings), 1) # same test with dry_run os.remove(tarball) old_dir = os.getcwd() os.chdir(tmpdir) try: with check_warnings() as w: warnings.simplefilter("always") make_tarball(base_name, 'dist', compress='compress', dry_run=True) finally: os.chdir(old_dir) self.assertFalse(os.path.exists(tarball)) self.assertEqual(len(w.warnings), 1)
Example #18
Source File: test_io.py From oss-ftp with MIT License | 5 votes |
def test_max_buffer_size_deprecation(self): with support.check_warnings(("max_buffer_size is deprecated", DeprecationWarning)): self.tp(self.MockRawIO(), 8, 12)
Example #19
Source File: test_fileio.py From BinderFilter with MIT License | 5 votes |
def testWarnings(self): with check_warnings(quiet=True) as w: self.assertEqual(w.warnings, []) self.assertRaises(TypeError, _FileIO, []) self.assertEqual(w.warnings, []) self.assertRaises(ValueError, _FileIO, "/some/invalid/name", "rt") self.assertEqual(w.warnings, [])
Example #20
Source File: test_structmembers.py From BinderFilter with MIT License | 5 votes |
def test_short_min(self): with test_support.check_warnings(('', RuntimeWarning)): ts.T_SHORT = SHRT_MIN-1
Example #21
Source File: test_structmembers.py From BinderFilter with MIT License | 5 votes |
def test_short_max(self): with test_support.check_warnings(('', RuntimeWarning)): ts.T_SHORT = SHRT_MAX+1
Example #22
Source File: test_structmembers.py From BinderFilter with MIT License | 5 votes |
def test_byte_min(self): with test_support.check_warnings(('', RuntimeWarning)): ts.T_BYTE = CHAR_MIN-1
Example #23
Source File: test_structmembers.py From BinderFilter with MIT License | 5 votes |
def test_byte_max(self): with test_support.check_warnings(('', RuntimeWarning)): ts.T_BYTE = CHAR_MAX+1
Example #24
Source File: test_descr.py From BinderFilter with MIT License | 5 votes |
def test_main(): deprecations = [(r'complex divmod\(\), // and % are deprecated$', DeprecationWarning)] if sys.py3kwarning: deprecations += [ ("classic (int|long) division", DeprecationWarning), ("coerce.. not supported", DeprecationWarning), (".+__(get|set|del)slice__ has been removed", DeprecationWarning)] with test_support.check_warnings(*deprecations): # Run all local test cases, with PTypesLongInitTest first. test_support.run_unittest(PTypesLongInitTest, OperatorsTest, ClassPropertiesAndMethods, DictProxyTests)
Example #25
Source File: test_pep352.py From BinderFilter with MIT License | 5 votes |
def test_message_deprecation(self): # As of Python 2.6, BaseException.message is deprecated. with check_warnings(("", DeprecationWarning)): BaseException().message
Example #26
Source File: test_pep352.py From BinderFilter with MIT License | 5 votes |
def ignore_deprecation_warnings(func): """Ignore the known DeprecationWarnings.""" def wrapper(*args, **kw): with check_warnings(*_deprecations, quiet=True): return func(*args, **kw) return wrapper
Example #27
Source File: test_contextlib.py From BinderFilter with MIT License | 5 votes |
def test_main(): with test_support.check_warnings(("With-statements now directly support " "multiple context managers", DeprecationWarning)): test_support.run_unittest(__name__)
Example #28
Source File: test_coercion.py From BinderFilter with MIT License | 5 votes |
def test_main(): with check_warnings(("complex divmod.., // and % are deprecated", DeprecationWarning), ("classic (int|long) division", DeprecationWarning), quiet=True): run_unittest(CoercionTest)
Example #29
Source File: test_importhooks.py From BinderFilter with MIT License | 5 votes |
def testImpWrapper(self): i = ImpWrapper() sys.meta_path.append(i) sys.path_hooks.append(ImpWrapper) mnames = ("colorsys", "urlparse", "distutils.core", "compiler.misc") for mname in mnames: parent = mname.split(".")[0] for n in sys.modules.keys(): if n.startswith(parent): del sys.modules[n] with test_support.check_warnings(("The compiler package is deprecated " "and removed", DeprecationWarning)): for mname in mnames: m = __import__(mname, globals(), locals(), ["__dummy__"]) m.__loader__ # to make sure we actually handled the import
Example #30
Source File: test_io.py From BinderFilter with MIT License | 5 votes |
def test_constructor_max_buffer_size_deprecation(self): with support.check_warnings(("max_buffer_size is deprecated", DeprecationWarning)): self.tp(self.MockRawIO(), self.MockRawIO(), 8, 12)