File: lib.py

package info (click to toggle)
python-git 3.1.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,772 kB
  • sloc: python: 18,642; sh: 186; makefile: 78
file content (27 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

"""Support library for deprecation tests."""

__all__ = ["assert_no_deprecation_warning", "suppress_deprecation_warning"]

import contextlib
import warnings

from typing import Generator


@contextlib.contextmanager
def assert_no_deprecation_warning() -> Generator[None, None, None]:
    """Context manager to assert that code does not issue any deprecation warnings."""
    with warnings.catch_warnings():
        warnings.simplefilter("error", DeprecationWarning)
        warnings.simplefilter("error", PendingDeprecationWarning)
        yield


@contextlib.contextmanager
def suppress_deprecation_warning() -> Generator[None, None, None]:
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", DeprecationWarning)
        yield