forked from gleitz/howdoi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added howdoi unittests. pegged requirement version numbers
- Loading branch information
Showing
3 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
argparse==1.2.1 | ||
cssselect==0.7.1 | ||
lxml==3.0.1 | ||
pyquery==1.2.2 | ||
requests==1.1.0 | ||
wsgiref==0.1.2 | ||
argparse | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Tests for Howdoi.""" | ||
|
||
import unittest | ||
|
||
from howdoi import howdoi | ||
|
||
|
||
class HowdoiTestCase(unittest.TestCase): | ||
|
||
def call_howdoi(self, query): | ||
parser = howdoi.get_parser() | ||
args = vars(parser.parse_args(query.split(' '))) | ||
return howdoi.howdoi(args) | ||
|
||
def setUp(self): | ||
self.queries = ['format date bash', | ||
'print stack trace python', | ||
'convert mp4 to animated gif' | ||
'create tar archive'] | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_get_link_at_pos(self): | ||
self.assertEqual(howdoi.get_link_at_pos(['/questions/42/'], 1), | ||
'/questions/42/') | ||
self.assertEqual(howdoi.get_link_at_pos(['/questions/42/'], 2), | ||
'/questions/42/') | ||
self.assertEqual(howdoi.get_link_at_pos(['/howdoi', '/questions/42/'], 1), | ||
'/questions/42/') | ||
self.assertEqual(howdoi.get_link_at_pos(['/howdoi', '/questions/42/'], 2), | ||
'/questions/42/') | ||
self.assertEqual(howdoi.get_link_at_pos(['/questions/42/', '/questions/142/'], 1), | ||
'/questions/42/') | ||
|
||
def test_answers(self): | ||
for query in self.queries: | ||
self.assertTrue(self.call_howdoi(query)) | ||
|
||
def test_answer_links(self): | ||
for query in self.queries: | ||
self.assertTrue('http://' in self.call_howdoi(query + ' -l')) | ||
|
||
def test_position(self): | ||
query = self.queries[0] | ||
first_answer = self.call_howdoi(query) | ||
second_answer = self.call_howdoi(query + ' -p2') | ||
self.assertNotEqual(first_answer, second_answer) | ||
|
||
def test_all_text(self): | ||
query = self.queries[0] | ||
first_answer = self.call_howdoi(query) | ||
second_answer = self.call_howdoi(query + ' -a') | ||
self.assertNotEqual(first_answer, second_answer) | ||
|
||
def test_multiple_answers(self): | ||
query = self.queries[0] | ||
first_answer = self.call_howdoi(query) | ||
second_answer = self.call_howdoi(query + ' -n3') | ||
self.assertNotEqual(first_answer, second_answer) | ||
|
||
def test_unicode_answer(self): | ||
assert self.call_howdoi('make a log scale d3') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |