Coverage for tests/import_test/two/three/success.py: 100%
15 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 03:35 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 03:35 -0700
1# A module that always works
4def okay() -> bool:
5 """Return `True`."""
6 return True
9class Container:
10 """Class for testing stacklevel."""
12 def inside() -> str:
13 """Return 1."""
14 return "1"
16 @classmethod
17 def level(cls, allow_methods=frozenset(), allow_modules=frozenset()) -> int:
18 """Return the stacklevel of the caller relative to this method.
20 Parameters
21 ----------
22 allow_methods : `frozenset`
23 Allowed methods.
24 allow_modules : `frozenset`
25 Allowed modules.
27 Returns
28 -------
29 `int`
30 The stack level relative to this method.
31 """
32 import warnings
34 from lsst.utils.introspection import find_outside_stacklevel
36 stacklevel = find_outside_stacklevel(
37 "import_test", allow_methods=allow_methods, allow_modules=allow_modules
38 )
39 warnings.warn(
40 f"Using stacklevel={stacklevel} in Container class", category=FutureWarning, stacklevel=stacklevel
41 )
42 return stacklevel
44 @classmethod
45 def indirect_level(cls, allow_methods=frozenset(), allow_modules=frozenset()):
46 """Return the stacklevel of the caller relative to this method.
48 Deliberately includes an additional level.
50 Parameters
51 ----------
52 allow_methods : `frozenset`
53 Allowed methods.
54 allow_modules : `frozenset`
55 Allowed modules.
57 Returns
58 -------
59 `int`
60 The stack level relative to this method.
61 """
62 return cls.level(allow_methods=allow_methods, allow_modules=allow_modules)