def test_with_invalid_defaults_key_raises(self, empty_config_mock): empty_config_mock.write( os.linesep.join([ f"[{_repobee.constants.CORE_SECTION_HDR}]", "user = someone", "option = value", ])) with pytest.raises(exception.FileError) as exc_info: config.check_config_integrity(str(empty_config_mock)) assert ( f"config file at {empty_config_mock} contains invalid default keys" ) in str(exc_info.value) assert "option" in str(exc_info.value) assert "user" not in str(exc_info.value)
def test_with_valid_but_malformed_default_args_raises( self, empty_config_mock): empty_config_mock.write( os.linesep.join([ f"[{_repobee.constants.CORE_SECTION_HDR}]", "user = someone", "base_url", "org_name = cool", "plugins ", ])) with pytest.raises(exception.FileError) as exc_info: config.check_config_integrity(str(empty_config_mock)) assert "user" not in str(exc_info.value) assert "org_name" not in str(exc_info.value) assert "base_url" in str(exc_info.value) assert "plugins" in str(exc_info.value)
def show_config(config_file: pathlib.Path, show_secrets: bool) -> None: """Echo the config file. Args: config_file: The config file to echo. show_secrets: Whether or not to show configured secrets. """ config.check_config_integrity(config_file) plug.echo(f"Found valid config file at {config_file}") with config_file.open(encoding=sys.getdefaultencoding()) as f: config_contents = "".join(f.readlines()) output = (os.linesep + "BEGIN CONFIG FILE".center(50, "-") + os.linesep + config_contents + "END CONFIG FILE".center(50, "-")) sanitized_output = re.sub(r"token\s*=\s*.*", "token = xxxxxxxxxx", output) plug.echo(output if show_secrets else sanitized_output)
def test_with_no_config_file_raises(self, unused_path): with pytest.raises(exception.FileError) as exc_info: config.check_config_integrity(config_file=unused_path) assert str(unused_path) in str(exc_info.value)
def test_with_well_formed_config(self, config_mock): """This should just not raise.""" config.check_config_integrity(str(config_mock))