import os import re import tempfile import vimrunner from tasklib.task import TaskWarrior, Task server = vimrunner.Server() class IntegrationTest(object): viminput = None vimoutput = None tasks = [] def add_plugin(self, name): plugin_base = os.path.expanduser('~/.vim/bundle/') plugin_path = os.path.join(plugin_base, name) self.client.add_plugin(plugin_path) def write_buffer(self, lines, position=0): result = self.client.write_buffer(position + 1, lines) assert result == u"0" def read_buffer(self, start=0, end=1000): return self.client.read_buffer( unicode(start+1), unicode(end+1) ).splitlines() def generate_data(self): self.dir = tempfile.mkdtemp(dir='/tmp/') self.tw = TaskWarrior(data_location=self.dir) for task_kwargs in self.tasks: Task(self.tw, **task_kwargs).save() def setup(self): self.generate_data() self.client = server.start_gvim() self.add_plugin('taskwiki') self.add_plugin('vimwiki') self.command('let g:taskwiki_data_location="{0}"'.format(self.dir)) self.client.edit(os.path.join(self.dir, 'testwiki.txt')) self.command('set filetype=vimwiki', silent=False) # TODO: fix these vimwiki loading errors def teardown(self): self.client.quit() def command(self, command, silent=True, regex=None, lines=None): result = self.client.command(command) # Specifying regex or lines cancels expectations of silence if regex or lines: silent = False # For silent commands, there should be no output assert silent == bool(not result) # Multiline-evaluate the regex if regex: assert re.search(regex, result, re.MULTILINE) if lines: assert lines == len(result.splitlines()) return result def check_sanity(self): """ Makes sanity checks upon the vim instance. """ # Assert all the important files were loaded scriptnames = self.client.command('scriptnames').splitlines() expected_loaded_files = [ 'vimwiki/autoload/vimwiki/base.vim', 'vimwiki/ftplugin/vimwiki.vim', 'vimwiki/autoload/vimwiki/u.vim', 'vimwiki/syntax/omnipresent_syntax.vim', 'vimwiki/syntax/vimwiki.vim', 'taskwiki/ftplugin/vimwiki.vim', ] # Do a partial match for each line from scriptnames for scriptfile in expected_loaded_files: assert any([scriptfile in line for line in scriptnames]) # Assert only note about Bram being maintainer is in messages bramline = u'Messages maintainer: Bram Moolenaar ' assert self.client.command('messages') == bramline # Assert that TW and cache objects exist tw_class = self.client.command('py print(tw.__class__.__name__)') cache_class = self.client.command('py print(cache.__class__.__name__)') assert tw_class == 'TaskWarrior' assert cache_class == 'TaskCache' def test_execute(self): # Helper function that fills in {uuid} placeholders with correct UUIDs def fill_uuid(line): # Tasks in testing can have only alphanumerical descriptions match = re.match(r'\s*\* \[ \] (?P[a-zA-Z0-9 ]*)(?