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

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

12 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 

11"""Run all functions registered for the "hypothesis" entry point. 

12 

13This can be used with `st.register_type_strategy` to register strategies for your 

14custom types, running the relevant code when *hypothesis* is imported instead of 

15your package. 

16""" 

17 

18import importlib.metadata 

19import os 

20from collections.abc import Generator, Sequence 

21from importlib.metadata import EntryPoint 

22 

23 

24def get_entry_points() -> Generator[EntryPoint, None, None]: 

25 try: 

26 eps: Sequence[EntryPoint] = importlib.metadata.entry_points(group="hypothesis") 

27 except TypeError: # pragma: no cover 

28 # Load-time selection requires Python >= 3.10. See also 

29 # https://importlib-metadata.readthedocs.io/en/latest/using.html 

30 eps = importlib.metadata.entry_points().get("hypothesis", []) 

31 yield from eps 

32 

33 

34def run() -> None: 

35 if not os.environ.get("HYPOTHESIS_NO_PLUGINS"): 

36 for entry in get_entry_points(): # pragma: no cover 

37 hook = entry.load() 

38 if callable(hook): 

39 hook()