def _init_outdir(self): """Initialize the output directory for writing or appending test results.""" if self.dirpath.exists(): # Only accept empty output directory. paths = (self.dp_path, self.info_path, self.logs_path, self.stats_path, self.descr_path) for path in paths: if path.exists(): raise ErrorExists( f"cannot use path '{self.dirpath}' as the output directory, " f"it already contains '{path.name}'") self._created_paths = paths else: try: self.dirpath.mkdir(parents=True, exist_ok=True) self._created_paths.append(self.dirpath) FSHelpers.set_default_perm(self.dirpath) except OSError as err: raise Error( f"failed to create directory '{self.dirpath}':\n{err}" ) from None self.csv = _CSV.WritableCSV(self.dp_path) if self.info_path.exists(): if not self.info_path.is_file(): raise Error( f"path '{self.info_path}' exists, but it is not a regular file" ) # Verify that we are going to be able writing to the info file. if not os.access(self.info_path, os.W_OK): raise Error(f"cannot access '{self.info_path}' for writing") else: # Create an empty info file in advance. try: self.info_path.open("tw+", encoding="utf-8").close() except OSError as err: raise Error(f"failed to create file '{self.info_path}':\n{err}" ) from None
def _copy_raw_data(self): """Copy raw test results to the output directory.""" # Paths to the stats directory. stats_paths = {} # Paths to the logs directory. logs_paths = {} # Paths to test reports' description files. descr_paths = {} for res in self.rsts: resdir = res.dirpath if self.relocatable: dstpath = self.outdir / f"raw-{res.reportid}" try: FSHelpers.copy_dir(resdir, dstpath, exist_ok=True, ignore=["html-report"]) FSHelpers.set_default_perm(dstpath) except Error as err: raise Error(f"failed to copy raw data to report directory: {err}") from None # Use the path of the copied raw results rather than the original. resdir = dstpath if res.stats_path.is_dir(): stats_paths[res.reportid] = resdir / res.stats_path.name else: stats_paths[res.reportid] = None if res.logs_path.is_dir(): logs_paths[res.reportid] = resdir / res.logs_path.name else: logs_paths[res.reportid] = None if res.descr_path.is_file(): descr_paths[res.reportid] = resdir / res.descr_path.name return stats_paths, logs_paths, descr_paths