def test_validate_conf_section_exist(self, tmpdir): with cd(tmpdir): self.runner.invoke(cli, ['init']) self.runner.invoke(cli, ['add', 'blah']) with pytest.raises(LogmeError): validate_conf('blah', Path(tmpdir / 'logme.ini'))
def test_remove_raise(self, tmpdir): with cd(tmpdir): self.runner.invoke(cli, ['init']) with pytest.raises(LogmeError): result = self.runner.invoke(cli, ['remove', 'logme']) raise result.exception
def test_cd(self, tmpdir): original_cwd = Path.cwd() with cd(tmpdir): assert Path.cwd() == tmpdir assert Path.cwd() != original_cwd assert original_cwd == Path.cwd()
def test_init_raise(self, tmpdir): with pytest.raises(NotADirectoryError) as e_info: with cd(tmpdir): result = self.runner.invoke(cli, ['init', '-p', 'blah']) raise result.exception assert e_info.value.args[0] == f"{tmpdir.join('blah')} does not exist. If you'd " \ f"like to make the directory, please use '-mk' flag."
def test_init_absolute_root_path(self, tmpdir): root_path = Path(tmpdir.join('dir_abs')) with cd(tmpdir): result = self.runner.invoke( cli, ['init', '-p', str(root_path), '-mk']) assert result.exit_code == 0 assert (root_path / 'logme.ini').is_file()
def test_init(self, tmpdir, file_path, cmd_args): expected_file = Path(tmpdir.join(file_path)) with cd(tmpdir): result = self.runner.invoke(cli, cmd_args) assert result.exit_code == 0 assert expected_file.is_file() conf = ConfigParser() conf.read(expected_file) assert conf.sections() == ['logme']
def test_add_command(self, tmpdir): with cd(tmpdir): self.runner.invoke(cli, ['init']) result = self.runner.invoke(cli, ['add', 'blah']) config_path = tmpdir.join('logme.ini') config = read_config(config_path) assert result.exit_code == 0 assert Path(config_path).is_file() assert set(config.sections()) == {'logme', 'blah'}
def test_remove_command(self, tmpdir): with cd(tmpdir): self.runner.invoke(cli, ['init']) self.runner.invoke(cli, ['add', 'test']) config_path = tmpdir.join('logme.ini') config_before = read_config(config_path) assert set(config_before.sections()) == {'logme', 'test'} result = self.runner.invoke(cli, ['remove', 'test']) config_after = read_config(config_path) assert result.exit_code == 0 assert config_after.sections() == ['logme']
def test_add_command_no_file(self, tmpdir): with cd(tmpdir): with pytest.raises(FileNotFoundError): result = self.runner.invoke(cli, ['add', 'blah']) raise result.exception