Skip to content

Commit

Permalink
(feat) supress stdout in test
Browse files Browse the repository at this point in the history
  • Loading branch information
azai91 committed Nov 22, 2015
1 parent 0690032 commit 4736f5e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/venmo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ def show_options(cls, user_input):
user_input, user inputted string in Alfred bar.
"""

if 'login'.startswith(user_input):
if 'login'.startswith(user_input.lower()):
cls.show_login()
if 'logout'.startswith(user_input):
if 'logout'.startswith(user_input.lower()):
cls.show_logout()
if 'clear cache'.startswith(user_input):
if 'clear cache'.startswith(user_input.lower()):
cls.show_clear_cache()

if len(wf._items) == 0:
Expand Down
132 changes: 126 additions & 6 deletions tests/venmo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import unittest
import sys
from src.config import LOGIN, LOGOUT, INVALID, CLEAR_CACHE
import os
import sys

from src.venmo import main
from src.venmo_api import wf

class TestVenmo(unittest.TestCase):

def test_settings(self):
wf._items = []
sys.argv = ['venmo.py','>']
main(None)
self.assertEqual(len(wf._items), 3)
Expand All @@ -20,24 +23,141 @@ def test_settings(self):
self.assertEqual(wf._items[2].title, CLEAR_CACHE['title'])
wf._items = []


def test_invalid_options(self):
sys.argv = ['venmo.py.py','not here']
wf._items = []

sys.argv = ['venmo.py.py','> not here']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, INVALID['title'])
self.assertFalse(wf._items[0].valid)
self.assertFalse(wf._items[0].arg)
wf._items = []

def xtest_add_account(self):
sys.argv = ['venmo.py.py','add']
def test_login(self):
sys.argv = ['venmo.py.py','> login']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, 'Add Account')
self.assertEqual(wf._items[0].title, LOGIN['title'])
self.assertEqual(wf._items[0].arg, LOGIN['arg'])
self.assertTrue(wf._items[0].valid)
self.assertTrue(wf._items[0].arg)
wf._items = []

sys.argv = ['venmo.py.py','>login']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGIN['title'])
self.assertEqual(wf._items[0].arg, LOGIN['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> login']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGIN['title'])
self.assertEqual(wf._items[0].arg, LOGIN['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> Login']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGIN['title'])
self.assertEqual(wf._items[0].arg, LOGIN['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> LOGIN']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGIN['title'])
self.assertEqual(wf._items[0].arg, LOGIN['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

def test_logout(self):
wf._items = []

sys.argv = ['venmo.py.py','> logout']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGOUT['title'])
self.assertEqual(wf._items[0].arg, LOGOUT['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','>logout']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGOUT['title'])
self.assertEqual(wf._items[0].arg, LOGOUT['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> logout']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGOUT['title'])
self.assertEqual(wf._items[0].arg, LOGOUT['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> Logout']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGOUT['title'])
self.assertEqual(wf._items[0].arg, LOGOUT['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> LOGOUT']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, LOGOUT['title'])
self.assertEqual(wf._items[0].arg, LOGOUT['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

def test_clear_cache(self):
wf._items = []

sys.argv = ['venmo.py.py','> cl']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])
self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> clear C']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])
self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','>cl']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])
self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

sys.argv = ['venmo.py.py','> clear cache']
main(None)
self.assertEqual(len(wf._items), 1)
self.assertEqual(wf._items[0].title, CLEAR_CACHE['title'])
self.assertEqual(wf._items[0].arg, CLEAR_CACHE['arg'])
self.assertTrue(wf._items[0].valid)
wf._items = []

def setUp(self):

# supress stdout of feedback
f = open(os.devnull, 'w')
sys.stdout = f

if __name__ == '__main__':
unittest.main()

0 comments on commit 4736f5e

Please sign in to comment.