From 7d1ebffa447d0a5e291ac96682c4a544ff05bffe Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Wed, 23 Apr 2025 11:25:10 +0800 Subject: [PATCH] speccpu/x264: doctest for `speccpu.x264.MCBuilder.get_src` --- src/speccpu/x264.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/speccpu/x264.py b/src/speccpu/x264.py index 847f755..19a25a5 100644 --- a/src/speccpu/x264.py +++ b/src/speccpu/x264.py @@ -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()