選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

167 行
5.7KB

  1. # testing/warnings.py
  2. # Copyright (C) 2005-2021 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 assertions
  10. from .. import exc as sa_exc
  11. from ..util.langhelpers import _warnings_warn
  12. class SATestSuiteWarning(sa_exc.SAWarning):
  13. """warning for a condition detected during tests that is non-fatal"""
  14. def warn_test_suite(message):
  15. _warnings_warn(message, category=SATestSuiteWarning)
  16. def setup_filters():
  17. """Set global warning behavior for the test suite."""
  18. warnings.filterwarnings(
  19. "ignore", category=sa_exc.SAPendingDeprecationWarning
  20. )
  21. warnings.filterwarnings("error", category=sa_exc.SADeprecationWarning)
  22. warnings.filterwarnings("error", category=sa_exc.SAWarning)
  23. warnings.filterwarnings("always", category=SATestSuiteWarning)
  24. # some selected deprecations...
  25. warnings.filterwarnings("error", category=DeprecationWarning)
  26. warnings.filterwarnings(
  27. "ignore", category=DeprecationWarning, message=r".*StopIteration"
  28. )
  29. warnings.filterwarnings(
  30. "ignore",
  31. category=DeprecationWarning,
  32. message=r".*inspect.get.*argspec",
  33. )
  34. warnings.filterwarnings(
  35. "ignore",
  36. category=DeprecationWarning,
  37. message="The loop argument is deprecated",
  38. )
  39. # ignore things that are deprecated *as of* 2.0 :)
  40. warnings.filterwarnings(
  41. "ignore",
  42. category=sa_exc.SADeprecationWarning,
  43. message=r".*\(deprecated since: 2.0\)$",
  44. )
  45. warnings.filterwarnings(
  46. "ignore",
  47. category=sa_exc.SADeprecationWarning,
  48. message=r"^The (Sybase|firebird) dialect is deprecated and will be",
  49. )
  50. # 2.0 deprecation warnings, which we will want to have all of these
  51. # be "error" however for I98b8defdf7c37b818b3824d02f7668e3f5f31c94
  52. # we are moving one at a time
  53. for msg in [
  54. #
  55. # Core execution
  56. #
  57. r"The (?:Executable|Engine)\.(?:execute|scalar)\(\) method",
  58. r"The Connection.connect\(\) method is considered legacy",
  59. # r".*DefaultGenerator.execute\(\)",
  60. #
  61. #
  62. #
  63. # Core SQL constructs
  64. #
  65. r"The FromClause\.select\(\).whereclause parameter is deprecated",
  66. r"Set functions such as union\(\), union_all\(\), extract\(\),",
  67. r"The legacy calling style of select\(\) is deprecated and will be "
  68. "removed",
  69. r"The FromClause.select\(\) method will no longer accept keyword "
  70. "arguments in version 2.0",
  71. r"The Join.select\(\) method will no longer accept keyword arguments "
  72. "in version 2.0.",
  73. r"The \"whens\" argument to case\(\) is now passed",
  74. r"The Join.select\(\).whereclause parameter is deprecated",
  75. #
  76. # DML
  77. #
  78. r"The (?:update|delete).whereclause parameter will be removed in "
  79. "SQLAlchemy 2.0.",
  80. r"The (?:insert|update).values parameter will be removed in "
  81. "SQLAlchemy 2.0.",
  82. r"The update.preserve_parameter_order parameter will be removed in "
  83. "SQLAlchemy 2.0.",
  84. r"Passing dialect keyword arguments directly to the "
  85. "(?:Insert|Update|Delete) constructor",
  86. #
  87. # ORM configuration
  88. #
  89. r"Calling the mapper\(\) function directly outside of a "
  90. "declarative registry",
  91. r"The ``declarative_base\(\)`` function is now available ",
  92. r"The ``has_inherited_table\(\)`` function is now available",
  93. r"The ``bind`` argument to declarative_base is deprecated and will "
  94. "be removed in SQLAlchemy 2.0.",
  95. #
  96. # ORM Query
  97. #
  98. r"The Query\.get\(\) method",
  99. r"The Query\.from_self\(\) method",
  100. r"The Query\.with_parent\(\) method",
  101. r"The Query\.with_parent\(\) method",
  102. r"The Query\.select_entity_from\(\) method",
  103. r"The ``aliased`` and ``from_joinpoint`` keyword arguments",
  104. r"Using strings to indicate relationship names in Query.join",
  105. r"Using strings to indicate column or relationship paths in "
  106. "loader options",
  107. r"Using strings to indicate relationship names in the ORM "
  108. r"with_parent\(\)",
  109. r"The Query.with_polymorphic\(\) method is considered "
  110. "legacy as of the 1.x series",
  111. r"Passing a chain of multiple join conditions to Query.join\(\) "
  112. r"is deprecated and will be removed in SQLAlchemy 2.0.",
  113. r"Query.join\(\) will no longer accept tuples as arguments",
  114. #
  115. # ORM Session
  116. #
  117. r"This Session located a target engine via bound metadata",
  118. r"The Session.autocommit parameter is deprecated ",
  119. r".*object is being merged into a Session along the backref "
  120. "cascade path",
  121. r"Passing bind arguments to Session.execute\(\) as keyword arguments",
  122. r"The merge_result\(\) method is superseded by the "
  123. r"merge_frozen_result\(\)",
  124. r"The Session.begin.subtransactions flag is deprecated",
  125. ]:
  126. warnings.filterwarnings(
  127. "ignore",
  128. message=msg,
  129. category=sa_exc.RemovedIn20Warning,
  130. )
  131. try:
  132. import pytest
  133. except ImportError:
  134. pass
  135. else:
  136. warnings.filterwarnings(
  137. "once", category=pytest.PytestDeprecationWarning
  138. )
  139. def assert_warnings(fn, warning_msgs, regex=False):
  140. """Assert that each of the given warnings are emitted by fn.
  141. Deprecated. Please use assertions.expect_warnings().
  142. """
  143. with assertions._expect_warnings(
  144. sa_exc.SAWarning, warning_msgs, regex=regex
  145. ):
  146. return fn()