Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/hypothesis/reporting.py: 55%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

33 statements  

1# This file is part of Hypothesis, which may be found at 

2# https://github.com/HypothesisWorks/hypothesis/ 

3# 

4# Copyright the Hypothesis Authors. 

5# Individual contributors are listed in AUTHORS.rst and the git log. 

6# 

7# This Source Code Form is subject to the terms of the Mozilla Public License, 

8# v. 2.0. If a copy of the MPL was not distributed with this file, You can 

9# obtain one at https://mozilla.org/MPL/2.0/. 

10 

11from collections.abc import Callable 

12from contextlib import AbstractContextManager 

13from typing import TypeAlias 

14 

15from hypothesis._settings import Verbosity, settings 

16from hypothesis.internal.compat import escape_unicode_characters 

17from hypothesis.utils.dynamicvariables import DynamicVariable 

18 

19 

20def default(value: object) -> None: 

21 try: 

22 print(value) 

23 except UnicodeEncodeError: 

24 print(escape_unicode_characters(str(value))) 

25 

26 

27ReporterT: TypeAlias = Callable[[object], None] 

28reporter = DynamicVariable[ReporterT](default) 

29 

30 

31def current_reporter() -> ReporterT: 

32 return reporter.value 

33 

34 

35def with_reporter(new_reporter: ReporterT) -> AbstractContextManager[None]: 

36 return reporter.with_value(new_reporter) 

37 

38 

39def current_verbosity() -> Verbosity: 

40 assert settings.default is not None 

41 return settings.default.verbosity 

42 

43 

44def verbose_report(text: str) -> None: 

45 if current_verbosity() >= Verbosity.verbose: 

46 base_report(text) 

47 

48 

49def debug_report(text: str) -> None: 

50 if current_verbosity() >= Verbosity.debug: 

51 base_report(text) 

52 

53 

54def report(text: str) -> None: 

55 if current_verbosity() >= Verbosity.normal: 

56 base_report(text) 

57 

58 

59def base_report(text: str) -> None: 

60 assert isinstance(text, str), f"unexpected non-str {text=}" 

61 current_reporter()(text)