tests: Add tests for util

This commit is contained in:
Tomas Babej 2015-03-23 20:29:10 +01:00
parent 31d5b718c1
commit 22172e7ae3
2 changed files with 32 additions and 0 deletions

5
tests/__init__.py Normal file
View file

@ -0,0 +1,5 @@
import os
import sys
path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, path)

27
tests/test_util.py Normal file
View file

@ -0,0 +1,27 @@
import sys
# Mock vim to test vim-nonrelated functions
class MockVim(object):
def eval(*args, **kwargs):
return 42
sys.modules['vim'] = MockVim()
from taskwiki import util
def test_modstring_to_args():
assert util.tw_modstring_to_args("") == []
assert util.tw_modstring_to_args("project:Random") == ["project:Random"]
assert util.tw_modstring_to_args("project:Random area:admin") == ["project:Random", "area:admin"]
assert util.tw_modstring_to_args("project:Random +test") == ["project:Random", "+test"]
assert util.tw_modstring_to_args("project:'Random +test'") == ["project:Random +test"]
def test_modstring_to_kwargs():
assert util.tw_modstring_to_kwargs("") == {}
assert util.tw_modstring_to_kwargs("project:Random") == {"project":"Random"}
assert util.tw_modstring_to_kwargs("project:Random area:admin") == {"project":"Random", "area":"admin"}
assert util.tw_modstring_to_kwargs("project:Random +test") == {"project":"Random", "tags":["test"]}
assert util.tw_modstring_to_kwargs("project:Random +test +home") == {"project":"Random", "tags":["test", "home"]}
assert util.tw_modstring_to_kwargs("project:'Random +test'") == {"project":"Random +test"}