| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7cd3aa9 commit cf2576e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + # This module is part of GitPython and is released under the | ||
| 2 | + # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ | ||
| 3 | + | ||
| 4 | + """Support library for deprecation tests.""" | ||
| 5 | + | ||
| 6 | + __all__ = ["assert_no_deprecation_warning", "suppress_deprecation_warning"] | ||
| 7 | + | ||
| 8 | + import contextlib | ||
| 9 | + import warnings | ||
| 10 | + | ||
| 11 | + from typing import Generator | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + @contextlib.contextmanager | ||
| 15 | + def assert_no_deprecation_warning() -> Generator[None, None, None]: | ||
| 16 | + """Context manager to assert that code does not issue any deprecation warnings.""" | ||
| 17 | + with warnings.catch_warnings(): | ||
| 18 | + warnings.simplefilter("error", DeprecationWarning) | ||
| 19 | + warnings.simplefilter("error", PendingDeprecationWarning) | ||
| 20 | + yield | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + @contextlib.contextmanager | ||
| 24 | + def suppress_deprecation_warning() -> Generator[None, None, None]: | ||
| 25 | + with warnings.catch_warnings(): | ||
| 26 | + warnings.simplefilter("ignore", DeprecationWarning) | ||
| 27 | + yield | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,16 +15,15 @@ | |||
| 15 | 15 | It is inapplicable to the deprecations whose warnings are tested in this module. | |
| 16 | 16 | """ | |
| 17 | 17 | ||
| 18 | - import contextlib | ||
| 19 | - import warnings | ||
| 20 | - | ||
| 21 | 18 | import pytest | |
| 22 | 19 | ||
| 23 | 20 | from git.diff import NULL_TREE | |
| 24 | 21 | from git.objects.util import Traversable | |
| 25 | 22 | from git.repo import Repo | |
| 26 | 23 | from git.util import Iterable as _Iterable, IterableObj | |
| 27 | 24 | ||
| 25 | + from .lib import assert_no_deprecation_warning | ||
| 26 | + | ||
| 28 | 27 | # typing ----------------------------------------------------------------- | |
| 29 | 28 | ||
| 30 | 29 | from typing import Generator, TYPE_CHECKING | |
@@ -38,15 +37,6 @@ | |||
| 38 | 37 | # ------------------------------------------------------------------------ | |
| 39 | 38 | ||
| 40 | 39 | ||
| 41 | - @contextlib.contextmanager | ||
| 42 | - def _assert_no_deprecation_warning() -> Generator[None, None, None]: | ||
| 43 | - """Context manager to assert that code does not issue any deprecation warnings.""" | ||
| 44 | - with warnings.catch_warnings(): | ||
| 45 | - # FIXME: Refine this to filter for deprecation warnings from GitPython. | ||
| 46 | - warnings.simplefilter("error", DeprecationWarning) | ||
| 47 | - yield | ||
| 48 | - | ||
| 49 | - | ||
| 50 | 40 | @pytest.fixture | |
| 51 | 41 | def commit(tmp_path: "Path") -> Generator["Commit", None, None]: | |
| 52 | 42 | """Fixture to supply a one-commit repo's commit, enough for deprecation tests.""" | |
@@ -72,7 +62,7 @@ def test_diff_renamed_warns(diff: "Diff") -> None: | |||
| 72 | 62 | ||
| 73 | 63 | def test_diff_renamed_file_does_not_warn(diff: "Diff") -> None: | |
| 74 | 64 | """The preferred Diff.renamed_file property issues no deprecation warning.""" | |
| 75 | - with _assert_no_deprecation_warning(): | ||
| 65 | + with assert_no_deprecation_warning(): | ||
| 76 | 66 | diff.renamed_file | |
| 77 | 67 | ||
| 78 | 68 | ||
@@ -84,13 +74,13 @@ def test_commit_trailers_warns(commit: "Commit") -> None: | |||
| 84 | 74 | ||
| 85 | 75 | def test_commit_trailers_list_does_not_warn(commit: "Commit") -> None: | |
| 86 | 76 | """The nondeprecated Commit.trailers_list property issues no deprecation warning.""" | |
| 87 | - with _assert_no_deprecation_warning(): | ||
| 77 | + with assert_no_deprecation_warning(): | ||
| 88 | 78 | commit.trailers_list | |
| 89 | 79 | ||
| 90 | 80 | ||
| 91 | 81 | def test_commit_trailers_dict_does_not_warn(commit: "Commit") -> None: | |
| 92 | 82 | """The nondeprecated Commit.trailers_dict property issues no deprecation warning.""" | |
| 93 | - with _assert_no_deprecation_warning(): | ||
| 83 | + with assert_no_deprecation_warning(): | ||
| 94 | 84 | commit.trailers_dict | |
| 95 | 85 | ||
| 96 | 86 | ||
@@ -102,7 +92,7 @@ def test_traverse_list_traverse_in_base_class_warns(commit: "Commit") -> None: | |||
| 102 | 92 | ||
| 103 | 93 | def test_traversable_list_traverse_override_does_not_warn(commit: "Commit") -> None: | |
| 104 | 94 | """Calling list_traverse on concrete subclasses is not deprecated, does not warn.""" | |
| 105 | - with _assert_no_deprecation_warning(): | ||
| 95 | + with assert_no_deprecation_warning(): | ||
| 106 | 96 | commit.list_traverse() | |
| 107 | 97 | ||
| 108 | 98 | ||
@@ -114,7 +104,7 @@ def test_traverse_traverse_in_base_class_warns(commit: "Commit") -> None: | |||
| 114 | 104 | ||
| 115 | 105 | def test_traverse_traverse_override_does_not_warn(commit: "Commit") -> None: | |
| 116 | 106 | """Calling traverse on concrete subclasses is not deprecated, does not warn.""" | |
| 117 | - with _assert_no_deprecation_warning(): | ||
| 107 | + with assert_no_deprecation_warning(): | ||
| 118 | 108 | commit.traverse() | |
| 119 | 109 | ||
| 120 | 110 | ||
@@ -128,7 +118,7 @@ class Derived(_Iterable): | |||
| 128 | 118 | ||
| 129 | 119 | def test_iterable_obj_inheriting_does_not_warn() -> None: | |
| 130 | 120 | """Subclassing git.util.IterableObj is not deprecated, does not warn.""" | |
| 131 | - with _assert_no_deprecation_warning(): | ||
| 121 | + with assert_no_deprecation_warning(): | ||
| 132 | 122 | ||
| 133 | 123 | class Derived(IterableObj): | |
| 134 | 124 | pass | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,12 +56,10 @@ | |||
| 56 | 56 | metaclass marginal enough, to justify introducing a metaclass to issue the warnings. | |
| 57 | 57 | """ | |
| 58 | 58 | ||
| 59 | - import contextlib | ||
| 60 | 59 | import logging | |
| 61 | 60 | import sys | |
| 62 | 61 | from typing import Generator | |
| 63 | 62 | import unittest.mock | |
| 64 | - import warnings | ||
| 65 | 63 | ||
| 66 | 64 | if sys.version_info >= (3, 11): | |
| 67 | 65 | from typing import assert_type | |
@@ -73,6 +71,8 @@ | |||
| 73 | 71 | ||
| 74 | 72 | from git.cmd import Git | |
| 75 | 73 | ||
| 74 | + from .lib import assert_no_deprecation_warning, suppress_deprecation_warning | ||
| 75 | + | ||
| 76 | 76 | _USE_SHELL_DEPRECATED_FRAGMENT = "Git.USE_SHELL is deprecated" | |
| 77 | 77 | """Text contained in all USE_SHELL deprecation warnings, and starting most of them.""" | |
| 78 | 78 | ||
@@ -82,13 +82,6 @@ | |||
| 82 | 82 | _logger = logging.getLogger(__name__) | |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | - @contextlib.contextmanager | ||
| 86 | - def _suppress_deprecation_warning() -> Generator[None, None, None]: | ||
| 87 | - with warnings.catch_warnings(): | ||
| 88 | - warnings.simplefilter("ignore", DeprecationWarning) | ||
| 89 | - yield | ||
| 90 | - | ||
| 91 | - | ||
| 92 | 85 | @pytest.fixture | |
| 93 | 86 | def restore_use_shell_state() -> Generator[None, None, None]: | |
| 94 | 87 | """Fixture to attempt to restore state associated with the USE_SHELL attribute. | |
@@ -129,15 +122,15 @@ def restore_use_shell_state() -> Generator[None, None, None]: | |||
| 129 | 122 | # Try to save the original public value. Rather than attempt to restore a state | |
| 130 | 123 | # where the attribute is not set, if we cannot do this we allow AttributeError | |
| 131 | 124 | # to propagate out of the fixture, erroring the test case before its code runs. | |
| 132 | - with _suppress_deprecation_warning(): | ||
| 125 | + with suppress_deprecation_warning(): | ||
| 133 | 126 | old_public_value = Git.USE_SHELL | |
| 134 | 127 | ||
| 135 | 128 | # This doesn't have its own try-finally because pytest catches exceptions raised | |
| 136 | 129 | # during the yield. (The outer try-finally catches exceptions in this fixture.) | |
| 137 | 130 | yield | |
| 138 | 131 | ||
| 139 | 132 | # Try to restore the original public value. | |
| 140 | - with _suppress_deprecation_warning(): | ||
| 133 | + with suppress_deprecation_warning(): | ||
| 141 | 134 | Git.USE_SHELL = old_public_value | |
| 142 | 135 | finally: | |
| 143 | 136 | # Try to restore the original private state. | |
@@ -323,14 +316,7 @@ def test_execute_without_shell_arg_does_not_warn() -> None: | |||
| 323 | 316 | USE_SHELL is to be used, the way Git.execute itself accesses USE_SHELL does not | |
| 324 | 317 | issue a deprecation warning. | |
| 325 | 318 | """ | |
| 326 | - with warnings.catch_warnings(): | ||
| 327 | - for category in DeprecationWarning, PendingDeprecationWarning: | ||
| 328 | - warnings.filterwarnings( | ||
| 329 | - action="error", | ||
| 330 | - category=category, | ||
| 331 | - module=r"git(?:\.|$)", | ||
| 332 | - ) | ||
| 333 | - | ||
| 319 | + with assert_no_deprecation_warning(): | ||
| 334 | 320 | Git().version() | |
| 335 | 321 | ||
| 336 | 322 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments