Gitlab Community Edition Instance

Commit f273ee9a authored by xrotwang's avatar xrotwang Committed by Marcel Hellkamp
Browse files

Added tests for some cli functionality

parent eac72783
......@@ -36,7 +36,7 @@ class CliContext:
cfile = os.path.join(path, name)
if os.path.exists(cfile):
printer.vv("Found config file: {}", cfile)
self._config = Config(cfile)
self.load_config(cfile)
return
def _find_root(self):
......@@ -104,7 +104,7 @@ class ArchiveDir:
def __init__(self, path):
if not os.path.isdir(path):
raise IOError("Not a directory: " + path)
if not os.path.exists(os.path.join(path, METADIR_NAME)):
if os.path.exists(os.path.join(path, METADIR_NAME)):
raise IOError("Already initialized: " + path)
self.root = path
self.metadir = os.path.join(path, METADIR_NAME)
......
import pathlib
import pytest
from pycdstar3.cli.context import CliContext, ArchiveDir, Config, CliError
@pytest.fixture
def cfgfile(tmpdir):
cfg = pathlib.Path(str(tmpdir)) / 'cdstar.conf'
cfg.write_text(
'[DEFAULT]\nopt = value\nserver = http://example.org/v3/\nvault = demo', encoding='utf8')
return str(cfg)
@pytest.fixture
def context(tmpdir):
workdir = pathlib.Path(str(tmpdir)) / 'work'
workdir.mkdir()
return CliContext(workdir=str(workdir))
def test_CliContext_config(context, cfgfile, capsys):
assert context.config
def test_CliContext_no_config(context, capsys):
with pytest.raises(CliError):
_ = context.config
def test_CliContext_resolve_error(context):
with pytest.raises(ValueError):
context.resolve('http://example.org')
@pytest.mark.parametrize(
'ref,vault,archive,file',
[
('http://usr:pwd@example.org/v3/', 'demo', '', ''),
('/x/y/z', 'x', 'y', '/z'),
('y/z', 'demo', 'y', '/z'),
]
)
def test_CliContext_resolve(cfgfile, context, ref, vault, archive, file):
assert context.resolve(ref)[1:] == (vault, archive, file)
def test_ArchiveDir(tmpdir):
with pytest.raises(IOError):
_ = ArchiveDir(str(tmpdir.join('fname')))
ad = ArchiveDir(str(tmpdir))
pathlib.Path(ad.metadir).mkdir()
with pytest.raises(IOError):
_ = ArchiveDir(str(tmpdir))
def test_Config(cfgfile):
cfg = Config(cfgfile)
assert 'opt' in cfg
assert list(cfg)
assert cfg['opt'] == 'value'
with pytest.raises(KeyError):
_ = cfg['abc']
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment