-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
114 lines (87 loc) · 3.28 KB
/
tests.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
import unittest
import tweets
import sys
from subprocess import call
import speech
def halt():
import pdb; pdb.set_trace()
class EnvironmentTests(unittest.TestCase):
def testPython3Exists(self):
version = sys.version_info.major
self.assertTrue(version >= 3, 'Make sure you run with Python 3!')
def testMplayerExists(self):
import os
with open(os.devnull, 'w') as null:
out = call(['which', 'mplayer'], stdout=null)
self.assertEqual(out, 0, 'Mplayer is needed for speech.')
class TwitterTests(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testTrue(self):
self.assertTrue(True)
def testGetAnythingFromTwitter(self):
alstweets = tweets.get_tweets(name='allieehenry')
self.assertTrue(len(alstweets) >= 1)
def testNumberRequest(self):
from tweets import get_tweets
t = get_tweets(name='JennyJarv', count=7)
self.assertTrue(len(t) == 7)
def testNoName(self):
t = tweets.get_tweets()
self.assertTrue(t is None)
class SayTests(unittest.TestCase):
def testSayIsFound(self):
from speech import say
def testRemoveUrls(self):
s = 'this is a tweet https://twitpic.com/whtever #hash tweet'
processed = speech.clean(s)
self.assertEqual(processed, 'this is a tweet #hash tweet')
s = 'this is a tweet http://twitpic.com/whtever'
processed = speech.clean(s)
self.assertEqual(processed, 'this is a tweet ')
s = 'http://twitpic.com/whtever more #taga'
processed = speech.clean(s)
self.assertEqual(processed, 'more #taga')
class SettingsTests(unittest.TestCase):
def setUp(self):
with open('testsettings', 'w') as fh:
print('name = steve', file=fh)
print('tweets = stevenjarvis|allieehenry', file=fh)
print('# this is a comment', file=fh)
print('tweet_no_space=stevenjarvis|allieehenry', file=fh)
print('tweet_lots_space = stevenjarvis | allieehenry', file=fh)
print('city = marquette,mi', file=fh)
def tearDown(self):
import os
os.remove('testsettings')
def testGetName(self):
import settings
settings.initialize('testsettings')
self.assertEqual(settings.get_preference('name'), 'steve')
def testIgnoreComments(self):
import settings
settings.initialize('testsettings')
self.assertEqual(len(settings.prefs), 5)
def testListPref(self):
import settings
settings.initialize('testsettings')
handles = settings.get_preference('tweets')
desired = ['stevenjarvis', 'allieehenry']
self.assertEqual(handles, desired)
def testLotsOfSpaces(self):
import settings
settings.initialize('testsettings')
handles = settings.get_preference('tweet_lots_space')
desired = ['stevenjarvis', 'allieehenry']
self.assertEqual(handles, desired)
class WeatherTests(unittest.TestCase):
def testGetSomeInfo(self):
import weather
w = weather.get_weather('marquette,mi')
desc = w['comment']
self.assertTrue(type(desc) == str)
self.assertTrue(type(w['max']) == int)
if __name__ == '__main__':
unittest.main()