1616
1717import asyncio
1818import logging
19- import os
2019import signal
2120import sys
2221from abc import ABC , abstractmethod
2322from asyncio import Task
2423from datetime import datetime
24+ from pathlib import Path
2525from types import FrameType
2626from typing import Dict , List , Optional
2727
@@ -44,7 +44,7 @@ class BaseRunner(ABC):
4444 mode (str): The operation mode ('dry-run', 'run').
4545 system (System): The system schema object.
4646 test_scenario (TestScenario): The test scenario to run.
47- output_path (str ): Path to the output directory.
47+ output_path (Path ): Path to the output directory.
4848 monitor_interval (int): Interval in seconds for monitoring jobs.
4949 jobs (List[BaseJob]): List to track jobs created by the runner.
5050 test_to_job_map (Dict[Test, BaseJob]): Mapping from tests to their jobs.
@@ -78,21 +78,21 @@ def __init__(
7878 self .shutting_down = False
7979 self .register_signal_handlers ()
8080
81- def setup_output_directory (self , base_output_path : str ) -> str :
81+ def setup_output_directory (self , base_output_path : Path ) -> Path :
8282 """
8383 Set up and return the output directory path for the runner instance.
8484
8585 Args:
86- base_output_path (str ): The base output directory.
86+ base_output_path (Path ): The base output directory.
8787
8888 Returns:
89- str : The path to the output directory.
89+ Path : The path to the output directory.
9090 """
91- if not os . path . exists (base_output_path ):
92- os . makedirs ( base_output_path )
91+ if not base_output_path . exists ():
92+ base_output_path . mkdir ( )
9393 current_time = datetime .now ().strftime ("%Y-%m-%d_%H-%M-%S" )
94- output_subpath = os . path . join ( base_output_path , f"{ self .test_scenario .name } _{ current_time } " )
95- os . makedirs ( output_subpath )
94+ output_subpath = base_output_path / f"{ self .test_scenario .name } _{ current_time } "
95+ output_subpath . mkdir ( )
9696 return output_subpath
9797
9898 def register_signal_handlers (self ):
@@ -242,9 +242,9 @@ def find_dependency_free_tests(self) -> List[Test]:
242242
243243 return dependency_free_tests
244244
245- def get_job_output_path (self , test : Test ) -> str :
245+ def get_job_output_path (self , test : Test ) -> Path :
246246 """
247- Generate and ensures the existence of the output directory for a given test.
247+ Generate and ensure the existence of the output directory for a given test.
248248
249249 It constructs the path based on the test's section name and current iteration, creating the directories if they
250250 do not exist.
@@ -253,23 +253,24 @@ def get_job_output_path(self, test: Test) -> str:
253253 test (Test): The test instance for which to generate the output directory path.
254254
255255 Returns:
256- str : The path to the job's output directory.
256+ Path : The path to the job's output directory.
257257
258258 Raises:
259259 ValueError: If the test's section name is None.
260260 FileNotFoundError: If the base output directory does not exist.
261261 PermissionError: If there is a permission issue creating the directories.
262262 """
263- job_output_path = ""
263+ if not self .output_path .exists ():
264+ raise FileNotFoundError (f"Output directory { self .output_path } does not exist" )
265+
266+ job_output_path = Path () # avoid reportPossiblyUnboundVariable from pyright
264267
265- if not os .path .exists (self .output_path ):
266- raise FileNotFoundError (f"Output directory { self .output_path } " f"does not exist" )
267268 try :
268269 assert test .section_name is not None , "test.section_name must not be None"
269- test_output_path = os . path . join ( self .output_path , test .section_name )
270- os . makedirs ( test_output_path , exist_ok = True )
271- job_output_path = os . path . join ( test_output_path , str (test .current_iteration ) )
272- os . makedirs ( job_output_path , exist_ok = True )
270+ test_output_path = self .output_path / test .section_name
271+ test_output_path . mkdir ( )
272+ job_output_path = test_output_path / str (test .current_iteration )
273+ job_output_path . mkdir ( )
273274 except PermissionError as e :
274275 raise PermissionError (f"Cannot create directory { job_output_path } : { e } " ) from e
275276
0 commit comments