-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathoutTest.py
165 lines (138 loc) · 5.27 KB
/
outTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
import sys
import unittest
from cStringIO import StringIO
from geeknote.config import VERSION
from geeknote.out import printDate, printLine, printAbout,\
separator, failureMessage, successMessage, showUser, showNote, \
printList, SearchResult
from geeknote import out
class AccountingStub(object):
uploadLimit = 100
uploadLimitEnd = 100000
class UserStub(object):
username = 'testusername'
name = 'testname'
email = 'testemail'
accounting = AccountingStub()
class NoteStub(object):
title = 'testnote'
created = 10000
updated = 100000
content = '##note content'
tagNames = ['tag1', 'tag2', 'tag3']
guid = 12345
class outTestsWithHackedStdout(unittest.TestCase):
def setUp(self):
sys.stdout = StringIO() # set fake stdout
def test_print_line(self):
printLine('test')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), 'test\n')
def test_print_line_other_endline_success(self):
printLine('test', endLine='\n\r')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), 'test\n\r')
def test_print_about_success(self):
about = '''Version: %s
Geeknote - a command line client for Evernote.
Use geeknote --help to read documentation.
And visit www.geeknote.me to check for updates.\n''' % VERSION
printAbout()
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), about)
def test_separator_with_title_success(self):
line = '------------------- test ------------------\n'
separator(symbol='-', title='test')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), line)
def test_separator_without_title_success(self):
line = '----------------------------------------\n\n'
separator(symbol='-')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), line)
def test_separator_empty_args_success(self):
separator()
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), '\n\n')
def test_failure_message_success(self):
failureMessage('fail')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), 'fail\n')
def test_success_message_success(self):
successMessage('success')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), 'success\n')
def test_show_user_without_fullinfo_success(self):
showUser(UserStub(), {})
info = '''################ USER INFO ################
Username : testusername
Name : testname
Email : testemail\n'''
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), info)
def test_show_user_with_fullinfo_success(self):
showUser(UserStub(), True)
info = '''################ USER INFO ################
Username : testusername
Name : testname
Email : testemail
Upload limit : 0.00
Upload limit end : 01.01.1970\n'''
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), info)
def test_show_note_success(self):
note = '''################## TITLE ##################
testnote
=================== META ==================
Created: 01.01.1970 Updated:01.01.1970 \n'''\
'''----------------- CONTENT -----------------
Tags: tag1, tag2, tag3
##note content\n\n\n'''
showNote(NoteStub())
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), note)
def test_print_list_without_title_success(self):
notes_list = '''Total found: 2
1 : 01.01.1970 testnote
2 : 01.01.1970 testnote\n'''
printList([NoteStub() for _ in xrange(2)])
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), notes_list)
def test_print_list_with_title_success(self):
notes_list = '''=================== test ==================
Total found: 2
1 : 01.01.1970 testnote
2 : 01.01.1970 testnote\n'''
printList([NoteStub() for _ in xrange(2)], title='test')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), notes_list)
def test_print_list_with_urls_success(self):
notes_list = '''=================== test ==================
Total found: 2
1 : 01.01.1970 testnote >>> https://www.evernote.com/Home.action?#n=12345
2 : 01.01.1970 testnote >>> https://www.evernote.com/Home.action?#n=12345
'''
printList([NoteStub() for _ in xrange(2)], title='test', showUrl=True)
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), notes_list)
def test_print_list_with_selector_success(self):
out.rawInput = lambda x: 2
notes_list = '''=================== test ==================
Total found: 2
1 : 01.01.1970 testnote
2 : 01.01.1970 testnote
0 : -Cancel-\n'''
out.printList([NoteStub() for _ in xrange(2)], title='test', showSelector=True)
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), notes_list)
def test_search_result_success(self):
result = '''Search request: test
Total found: 2
1 : 01.01.1970 testnote
2 : 01.01.1970 testnote\n'''
SearchResult([NoteStub() for _ in xrange(2)], 'test')
sys.stdout.seek(0)
self.assertEquals(sys.stdout.read(), result)
def test_print_date(self):
self.assertEquals(printDate(1000000), '12.01.1970')