MCPcopy
hub / github.com/ManimCommunity/manim / decorator_maker

Function decorator_maker

manim/utils/testing/frames_comparison.py:66–162  ·  view source on GitHub ↗
(tested_scene_construct: Callable)

Source from the content-addressed store, hash-verified

64 """
65
66 def decorator_maker(tested_scene_construct: Callable) -> Callable:
67 if (
68 SCENE_PARAMETER_NAME
69 not in inspect.getfullargspec(tested_scene_construct).args
70 ):
71 raise Exception(
72 f"Invalid graphical test function test function : must have '{SCENE_PARAMETER_NAME}'as one of the parameters.",
73 )
74
75 # Exclude "scene" from the argument list of the signature.
76 old_sig = inspect.signature(
77 functools.partial(tested_scene_construct, scene=None),
78 )
79
80 if "__module_test__" not in tested_scene_construct.__globals__:
81 raise Exception(
82 "There is no module test name indicated for the graphical unit test. You have to declare __module_test__ in the test file.",
83 )
84 module_name = tested_scene_construct.__globals__.get("__module_test__")
85 assert isinstance(module_name, str)
86 test_name = tested_scene_construct.__name__[len("test_") :]
87
88 @functools.wraps(tested_scene_construct)
89 # The "request" parameter is meant to be used as a fixture by pytest. See below.
90 def wrapper(
91 *args: Any, request: FixtureRequest, tmp_path: StrPath, **kwargs: Any
92 ) -> None:
93 # check for cairo version
94 if (
95 renderer_class is CairoRenderer
96 and cairo.cairo_version() < MIN_CAIRO_VERSION
97 ):
98 pytest.skip("Cairo version is too old. Skipping cairo graphical tests.")
99 # Wraps the test_function to a construct method, to "freeze" the eventual additional arguments (parametrizations fixtures).
100 construct = functools.partial(tested_scene_construct, *args, **kwargs)
101
102 # Kwargs contains the eventual parametrization arguments.
103 # This modifies the test_name so that it is defined by the parametrization
104 # arguments too.
105 # Example: if "length" is parametrized from 0 to 20, the kwargs
106 # will be once with {"length" : 1}, etc.
107 test_name_with_param = test_name + "_".join(
108 f"_{str(tup[0])}[{str(tup[1])}]" for tup in kwargs.items()
109 )
110
111 config_tests = _config_test(last_frame)
112
113 config_tests["text_dir"] = tmp_path
114 config_tests["tex_dir"] = tmp_path
115
116 if last_frame:
117 config_tests["frame_rate"] = 1
118 config_tests["dry_run"] = True
119
120 setting_test = request.config.getoption("--set_test")
121 try:
122 test_file_path = tested_scene_construct.__globals__["__file__"]
123 except Exception:

Callers 1

frames_comparisonFunction · 0.85

Calls 3

valuesMethod · 0.80
getMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected