Repository: ManimCommunity/manim
File: tests/test_graphical_units/testing/frames_comparison.py (Python)

Code before:
import functools
import inspect
import itertools
from pathlib import Path
from typing import Any, Callable, Type

from _pytest.config import ConftestImportFailure
from _pytest.fixtures import FixtureRequest
from _pytest.mark.structures import Mark

from manim import Scene, config
from manim._config import tempconfig
from manim._config.utils import ManimConfig
from manim.renderer.cairo_renderer import CairoRenderer

from ._frames_testers import _ControlDataWriter, _FramesTester
from ._test_class_makers import (
    DummySceneFileWriter,
    _make_scene_file_writer_class,
    _make_test_renderer_class,
    _make_test_scene_class,
)

SCENE_PARAMETER_NAME = "scene"
PATH_CONTROl_DATA = Path("tests", "control_data", "graphical_units_data").absolute()


def frames_comparison(
    test_name: str,
    module_name: str,
    last_frame: bool = True,
    renderer_class=CairoRenderer,
    base_scene=Scene,
    **custom_config,
):
    """Compares the frames generated by the test with control frames
    specified with the ``test_name`` and ``module_name``.

    If there is no control frames for this test, the test will fail. To generate
    control frames for a given test, pass ``--set_test`` flag to pytest
    while running the test.

    Parameters
    ----------
    test_name
        The name of the test.
    module_name
        The module which the test belongs to.
    last_frame
        whether the test should test the last frame, by default True.

Review comment (suggestion):
Ah, this absolute path here probably causes the path issue, right? Do you want to fix this still in the scope of this PR?

There also is a typo in the variable name. :-)

```suggestion
PATH_CONTROL_DATA = Path("tests", "control_data", "graphical_units_data").absolute()
```

Code after:
import functools
import inspect
import itertools
from pathlib import Path
from typing import Any, Callable, Type

from _pytest.fixtures import FixtureRequest
from _pytest.mark.structures import Mark

from manim import Scene, config
from manim._config import tempconfig
from manim._config.utils import ManimConfig
from manim.renderer.cairo_renderer import CairoRenderer

from ._frames_testers import _ControlDataWriter, _FramesTester
from ._test_class_makers import (
    DummySceneFileWriter,
    _make_scene_file_writer_class,
    _make_test_renderer_class,
    _make_test_scene_class,
)

SCENE_PARAMETER_NAME = "scene"
_tests_root_dir_path = Path(__file__).absolute().parents[2]
PATH_CONTROL_DATA = _tests_root_dir_path / Path("control_data", "graphical_units_data")


def frames_comparison(
    test_name: str,
    module_name: str,
    last_frame: bool = True,
    renderer_class=CairoRenderer,
    base_scene=Scene,
    **custom_config,
):
    """Compares the frames generated by the test with control frames
    specified with the ``test_name`` and ``module_name``.

    If there is no control frames for this test, the test will fail. To generate
    control frames for a given test, pass ``--set_test`` flag to pytest
    while running the test.

    Parameters
    ----------
    test_name
        The name of the test.
    module_name
        The module which the test belongs to.
    last_frame
        whether the test should test the last frame, by default True.