Commit 63e5ac17 authored by juga  's avatar juga Committed by Matt Traudt
Browse files

Add unit test for init

parent 72acff55
"""Unit tests for sbws.core.init."""
import logging
import os.path
import sbws
def test_sbwshome_only_datadir(sbwshome_only_datadir, args, conf, caplog):
caplog.set_level(logging.DEBUG)
sbws.core.init.main(args, conf)
print(caplog.records[-1].getMessage())
assert "Creating {} based on example config".format(
os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
in caplog.records[-1].getMessage()
assert os.path.isdir(conf['paths']['sbws_home'])
assert os.path.isdir(conf['paths']['datadir'])
assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
'config.ini'))
def test_sbwshome_empty(args, conf, caplog):
caplog.set_level(logging.DEBUG)
sbws.core.init.main(args, conf)
assert "Creating {} based on example config".format(
os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
in caplog.records[-1].getMessage()
assert os.path.isdir(conf['paths']['sbws_home'])
assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
'config.ini'))
def test_sbwshome(sbwshome, args, conf, caplog):
caplog.set_level(logging.DEBUG)
try:
sbws.core.init.main(args, conf)
except SystemExit as e:
assert e.code == 1
else:
assert None, 'Should have failed'
assert "Directory already seems to be initted" \
in caplog.records[-1].getMessage()
assert os.path.isdir(conf['paths']['sbws_home'])
assert os.path.isdir(conf['paths']['datadir'])
assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
'config.ini'))
Markdown is supported
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