2121import pytest
2222import inspect
2323import pathlib
24+ import shutil
25+ import subprocess
2426
2527from execution_process_metrics_collector .collector import execution_metrics_collector
28+ from execution_process_metrics_collector .tdp_finder import tdp_finder
2629
2730from typing import (
2831 TYPE_CHECKING ,
3336 Optional ,
3437 Sequence ,
3538 )
39+ from typing_extensions import (
40+ Final ,
41+ )
3642
3743
3844COLLECTOR_TESTBED = pytest .mark .parametrize (
4349)
4450
4551
52+ @pytest .mark .filterwarnings ("ignore:.*:pytest.PytestReturnNotNoneWarning" )
4653@COLLECTOR_TESTBED
4754def test_collector (
4855 tmpdir : "str" ,
4956 command_line : "Sequence[str]" ,
5057 should_fail : "Optional[Sequence[str]]" ,
51- ) -> "None " :
58+ ) -> "pathlib.Path " :
5259 try :
53- execution_metrics_collector (
60+ metrics_path = execution_metrics_collector (
5461 command_line ,
5562 pathlib .Path (tmpdir ),
5663 match_docker = True ,
@@ -73,3 +80,52 @@ def test_collector(
7380 raise AssertionError (
7481 f"Method { current_frame .f_code .co_name } should have failed with command line { command_line } "
7582 ) # type: ignore[union-attr]
83+
84+ return metrics_path
85+
86+
87+ CPU_SPEC_DATASET_REPO : "Final[str]" = "https://github.com/JosuaCarl/cpu-spec-dataset"
88+
89+
90+ @COLLECTOR_TESTBED
91+ def test_tdp_finder (
92+ tmpdir : "str" ,
93+ command_line : "Sequence[str]" ,
94+ should_fail : "Optional[Sequence[str]]" ,
95+ ) -> "None" :
96+ metrics_path = test_collector (tmpdir , command_line , should_fail )
97+
98+ spec_path = pathlib .Path (tmpdir ) / "cpu_spec_dataset"
99+ if not spec_path .exists ():
100+ git_path = shutil .which ("git" )
101+ assert git_path is not None , "git not found"
102+ subprocess .run (
103+ [git_path , "clone" , CPU_SPEC_DATASET_REPO , spec_path .as_posix ()], check = True
104+ )
105+
106+ assert spec_path .is_dir ()
107+
108+ processors_file = spec_path / "dataset" / "intel-cpus.csv"
109+
110+ assert processors_file .exists ()
111+
112+ try :
113+ tdp_finder (metrics_path , processors_file )
114+ except BaseException :
115+ current_frame = inspect .currentframe ()
116+ if (
117+ should_fail is None
118+ or current_frame is None
119+ or current_frame .f_code .co_name not in should_fail
120+ ): # type: ignore[union-attr]
121+ raise
122+ else :
123+ current_frame = inspect .currentframe ()
124+ if (
125+ should_fail is not None
126+ and current_frame is not None
127+ and current_frame .f_code .co_name in should_fail
128+ ): # type: ignore[union-attr]
129+ raise AssertionError (
130+ f"Method { current_frame .f_code .co_name } should have failed with command line { command_line } "
131+ ) # type: ignore[union-attr]
0 commit comments