forked from blob42/howto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
63 lines (48 loc) · 1.8 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
import unittest
from stackexchange import StackOverflow
import stackexchange
from pyquery import PyQuery as pq
from howto.howto import SOSearch
from random import choice
class SOSearchTests(unittest.TestCase):
'''Test case for Stackoverflow searches'''
def setUp(self):
self.so_search = SOSearch('singleton pattern', 'java')
def test_issubclass_of_stackexchangeSite(self):
self.assertIsInstance(self.so_search, stackexchange.Site)
def test_init_values(self):
with self.assertRaises(Exception):
so = SOSearch()
def test_fist_question(self):
first = self.so_search.first_q()
self.assertEqual(first, self.so_search.qs[0])
def test_questions_ordered_by_votes(self):
for (qs, next) in zip(self.so_search.qs[:-2], self.so_search.qs[1:]):
self.assertGreaterEqual(qs.score,
next.score)
def test_extracted_code(self):
question = self.so_search.first_q()
answer = choice(question.answers)
html = pq(answer.body)
el = html('code')
code = el.text()
self.assertEqual(code, answer.code)
def test_has_code(self):
q = self.so_search.first_q()
a = choice(q.answers)
a.body = 'This is a test<code>Magic</code>'
self.assertEqual(self.so_search.has_code(a), True)
a.body = 'This is a test'
self.assertEqual(self.so_search.has_code(a), False)
def test_best_answer(self):
question = self.so_search.first_q()
best = question.best_answer
for answer in question.answers:
self.assertGreaterEqual(best.score, answer.score)
def test_get_next_answer(self):
self.failUnless(False)
def main():
"""docstring for main"""
unittest.main()
if __name__ == '__main__':
main()