This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech-tests.py
94 lines (79 loc) · 3.81 KB
/
speech-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
#!/usr/bin/python
# Copyright 2013 Sumana Harihareswara
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This file contains the unit tests for the speech generator.
"""
import unittest
from speech import *
class item_insertion_test_case(unittest.TestCase):
def test_valid_item_insertion(self):
#Try taking an empty list and make sure that when we insert a new valid item,
#it works.
testlist = CuratedList()
testitem = "bottle"
expectedresult = ["bottle"]
testlist.addToList(testitem)
self.assertEqual(testlist.contents, expectedresult)
def test_invalid_item_insertion(self):
#Insert an invalid item into a list and ensure it gives the right
#errors: "that's not one English word" if it's not all alphabetical characters,
#"try again; what did you mean?" if it's empty. Rerun the raw_input.
testlist = CuratedList()
testnumber = "6"
self.assertRaisesRegexp(ValueError, ".*word.*", testlist.addToList, testnumber)
self.assertRaisesRegexp(ValueError, ".*empty.*", testlist.addToList, "")
class bug_test_case(unittest.TestCase):
def test_make_bug(self):
#The makeBugValues function is too trivial to test.
#Update: Not too trivial to test (it emits a tuple. Who would have
#thought this? but anyway that's the only tricky thing.)
testnumber = 1
testowner = "Martin Pool"
testtitle = "bad version number"
expectedbug = {"id":1,"title":"bad version number","owner":"Martin Pool"}
self.assertEqual(Bug(testnumber,testtitle,testowner),expectedbug)
def test_extract_bug_info(self):
#Check whether, given a mock bug, we can extract the bug number, title,
#and reporter name.
testbug = Bug(1,"bad version number","Martin Pool")
testnumber = 1
testowner = "Martin Pool"
testtitle = "bad version number"
self.assertEqual(testbug.getBugNumber(),testnumber)
self.assertEqual(testbug.getBugTitle(),testtitle)
self.assertEqual(testbug.getBugReporter(),testowner)
def test_insert_bug_number(self):
#Given a mock bug # and mock template, check that inserting the bug # into
#the template gives us a template with the bug # stringified and filled in.
#All the other insertions (buzzwords, owners, and titles) are already
#strings, so I don't expect any trouble with them.
bugnumber = 567
template = "I know %s is more important than ever."
expectedresult = "I know 567 is more important than ever."
self.assertEqual(insertThing(bugnumber, template), expectedresult)
class buzzword_test_case(unittest.TestCase):
def test_buzzword_grab(self):
testlist = CuratedList()
testlist.contents = ["NoSQL","distributed"]
self.assertIn(testlist.buzzGrab(),testlist.contents)
def test_buzzword_insert(self):
#Check that the buzzword inserted into the template is the one you
#wanted to insert.
testword = "NoSQL"
template = "I know %s is more important than ever."
expectedresult = "I know NoSQL is more important than ever."
self.assertIn(insertThing(testword,template),expectedresult)
def main():
unittest.main()
if __name__ == "__main__":
main()