Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Added unit tests for completions
Browse files Browse the repository at this point in the history
  • Loading branch information
demotivated committed Aug 30, 2015
1 parent 4aa71c0 commit f3a4ca3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
13 changes: 0 additions & 13 deletions exceptions.py

This file was deleted.

65 changes: 65 additions & 0 deletions tests/test_completions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import unittest

from completer import CommandCompleter
from api import PushBullet


class CompleterTestCase(unittest.TestCase):

def setUp(self):
self.pushbullet = PushBullet()
self.completer = CommandCompleter(self.pushbullet)

def test_command_list(self):
document = MockDocument('')
words = [i.text for i in self.completer.get_completions(document, None)]
self.assertIn('help', words)
self.assertIn('quit', words)
self.assertIn('note', words)
self.assertIn('link', words)
self.assertIn('devices', words)

def test_device_list(self):
document = MockDocument('note ')
words = [i.text for i in self.completer.get_completions(document, None)]
devices = [i.name.lower() for i in self.pushbullet.devices]
for d in devices:
self.assertIn(d, words)
self.assertIn('all', words)

def test_device_list_partial_match(self):
document = MockDocument('note al')
words = [i.text for i in self.completer.get_completions(document, None)]
self.assertIn('all', words)
self.assertLess(len(words), len(self.pushbullet.devices))

def test_note_message(self):
document = MockDocument('note all dsfewfg')
words = [i.display for i in self.completer.get_completions(document, None)]
self.assertEqual(['Message to push'], words)

def test_link_url_message(self):
document = MockDocument('link all http://xkcd')
words = [i.display for i in self.completer.get_completions(document, None)]
self.assertEqual(['URL to push'], words)

def test_link_url_optional_body(self):
document = MockDocument('link all http://xkcd.com ')
words = [i.display for i in self.completer.get_completions(document, None)]
self.assertEqual(['[Optional] Message to push'], words)


class MockDocument(object):

def __init__(self, line):
self.current_line = line

def get_word_before_cursor(self):
"""
Give the word before the cursor.
If we have whitespace before the cursor this returns an empty string.
"""
if self.current_line[-1:].isspace():
return ''
else:
return self.current_line.split(' ')[-1]

0 comments on commit f3a4ca3

Please sign in to comment.