speccpu/x264: doctest for speccpu.x264.MCBuilder.get_src

This commit is contained in:
2025-04-23 11:25:10 +08:00
parent 498667ba5f
commit 7d1ebffa44

View File

@@ -12,6 +12,28 @@ def get_mc_path(build):
class MCBuilder:
@staticmethod
def get_src():
"""
Get the source code of the motion compensation (mc.c) file.
This static method reads and returns the content of the mc.c file,
which is part of the x264 benchmark package. The file is accessed
using importlib.resources to ensure proper resource handling.
Returns:
str: The complete source code of the mc.c file as a string.
Raises:
AssertionError: If the function is called from a module that is not part of a package.
Example:
>>> src = MCBuilder.get_src()
>>> isinstance(src, str)
True
>>> "mc_weight" in src
True
>>> len(src) > 0
True
"""
assert __package__ is not None
with (importlib.resources.files(__package__) / "mc.c").open("r") as f:
mc_src = f.read()