Skip to content
Snippets Groups Projects
Commit be5d940a authored by Henke's avatar Henke
Browse files

Finish implementation for #3

parent d5ae80c1
No related branches found
No related tags found
No related merge requests found
import ast
import os import os
import configparser import configparser
...@@ -26,7 +27,7 @@ def TouchStructure(): ...@@ -26,7 +27,7 @@ def TouchStructure():
} }
with open(kattcmd_file, 'w') as configfile: with open(kattcmd_file, 'w') as configfile:
configfile.write(config) config.write(configfile)
return True return True
return False return False
...@@ -42,7 +43,11 @@ def _ListExternals(): ...@@ -42,7 +43,11 @@ def _ListExternals():
config_path = os.path.expanduser('~/.kattcmd') config_path = os.path.expanduser('~/.kattcmd')
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_path) config.read(config_path)
return config['options']['plugins']
# See https://stackoverflow.com/questions/1894269/convert-string-representation-of-list-to-list-in-python
# for why we use ast.literal_eval here
L = ast.literal_eval(config['options']['plugins'])
return [x.strip() for x in L if x.strip()]
def ListPlugins(): def ListPlugins():
......
import os import os
import tempfile
import configparser
from kattcmd import core from kattcmd import core
def test_one_plus_one(): def with_custom_home(f):
assert 1 + 1 == 2 '''Descriptor for tests that should run in their own isolated environment.'''
def inner(*args, **kwargs):
with tempfile.TemporaryDirectory() as tempdirname:
os.environ['HOME'] = tempdirname
f(*args, **kwargs)
return inner
@with_custom_home
def test_creates_kattcmd_options():
assert core.TouchStructure()
kattcmd_path = os.path.expanduser('~/.kattcmd')
assert os.path.isfile(kattcmd_path)
config = configparser.ConfigParser()
config.read(kattcmd_path)
assert 'options' in config
assert 'kattisrc' in config['options']
assert 'plugins' in config['options']
@with_custom_home
def test_touch_twice():
assert core.TouchStructure()
assert not core.TouchStructure()
@with_custom_home
def test_lists_plugins():
assert core.TouchStructure()
plugins = core.ListPlugins()
assert isinstance(plugins, list)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment