def test_check(test_path): # GIVEN a filesystem path # WHEN when checking the path result = path.check(test_path) # THEN the directories should exist assert result.exists() or result.parent.exists() assert isinstance(result, pathlib.Path)
def configure_logging(self): """Create logging handlers for any log output.""" root_logger = logging.getLogger("") root_logger.setLevel(logging.DEBUG) # Set logging to file by default. if not self.options.log_file: log_dir = path.log() log_dir = path.check(log_dir) self.options.log_file = str(pathlib.Path(log_dir) / "mariner.log") # Monkey patched to use RotatingFileHandler file_handler = logging.handlers.RotatingFileHandler( filename=self.options.log_file, maxBytes=1000000, backupCount=1) formatter = logging.Formatter(self.LOG_FILE_MESSAGE_FORMAT) file_handler.setFormatter(formatter) root_logger.addHandler(file_handler) # Always send higher-level messages to the console via stderr console = logging.StreamHandler(self.stderr) console_level = { 0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG }.get(self.options.verbose_level, logging.DEBUG) console.setLevel(console_level) formatter = logging.Formatter(self.CONSOLE_MESSAGE_FORMAT) console.setFormatter(formatter) root_logger.addHandler(console)
def test_check_str_path(test_path): # GIVEN a string representation of a filesystem path test_path = str(test_path) # WHEN when checking the path result = path.check(test_path) # THEN the directories should exist a be Path assert result.exists() or result.parent.exists() assert isinstance(result, pathlib.Path)
def configpath(self) -> pathlib.Path: """Create configuration file if necessary and return the path. Returns: Path to configuration file. """ if self._configpath: configpath = pathlib.Path(self._configpath) else: directory = path.config() directory = path.check(directory) configpath = pathlib.Path(directory, "config.yaml") self.log.debug("path=%s", path) return configpath
def __init__(self, download_path: Path = path.download(), timeout: int = 10) -> None: self.download_path = path.check(download_path) self.timeout = timeout