/compute_genes_psi_id/pymodules/python2.7/lib/python/sqlalchemy/testing/warnings.py

https://gitlab.com/pooja043/Globus_Docker_2 · Python · 58 lines · 34 code · 15 blank · 9 comment · 4 complexity · c57e2bbfdbc66f025fe20e040fb8212d MD5 · raw file

  1. # testing/warnings.py
  2. # Copyright (C) 2005-2014 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  7. from __future__ import absolute_import
  8. import warnings
  9. from .. import exc as sa_exc
  10. from .. import util
  11. import re
  12. def testing_warn(msg, stacklevel=3):
  13. """Replaces sqlalchemy.util.warn during tests."""
  14. filename = "sqlalchemy.testing.warnings"
  15. lineno = 1
  16. if isinstance(msg, util.string_types):
  17. warnings.warn_explicit(msg, sa_exc.SAWarning, filename, lineno)
  18. else:
  19. warnings.warn_explicit(msg, filename, lineno)
  20. def resetwarnings():
  21. """Reset warning behavior to testing defaults."""
  22. util.warn = util.langhelpers.warn = testing_warn
  23. warnings.filterwarnings('ignore',
  24. category=sa_exc.SAPendingDeprecationWarning)
  25. warnings.filterwarnings('error', category=sa_exc.SADeprecationWarning)
  26. warnings.filterwarnings('error', category=sa_exc.SAWarning)
  27. def assert_warnings(fn, warnings, regex=False):
  28. """Assert that each of the given warnings are emitted by fn."""
  29. from .assertions import eq_, emits_warning
  30. canary = []
  31. orig_warn = util.warn
  32. def capture_warnings(*args, **kw):
  33. orig_warn(*args, **kw)
  34. popwarn = warnings.pop(0)
  35. canary.append(popwarn)
  36. if regex:
  37. assert re.match(popwarn, args[0])
  38. else:
  39. eq_(args[0], popwarn)
  40. util.warn = util.langhelpers.warn = capture_warnings
  41. result = emits_warning()(fn)()
  42. assert canary, "No warning was emitted"
  43. return result