importing reddit-py into git
[redditcloud.py.git] / test.py
blobca1bab3515832416d8ee569d92ac4fc9fc91ead2
1 # Run this with nose
3 import reddit
5 url = "http://reddit.com/"
7 def non_empty_string(s):
8 return type(s) in [str, unicode] and len(s.strip()) > 0
11 def test_url_get():
12 val = reddit.get_url(url)
13 assert type(val) is str and len(val) > 0
15 def test_reddit_links():
16 r = reddit.Reddit(url)
17 for link in r.links:
18 valid_link(link)
20 def test_guess_time():
21 cases = [
22 ("21 hours", 21*60*60),
23 ("7 Days 21 hours", 7*24*60*60 + 21*60*60),
24 ("1 day", 24*60*60),
26 for s,t in cases:
27 g = reddit.guess_time(s)
28 assert type(g) is int, "Must return time in seconds"
29 assert g == t, \
30 "guess_time(s) returned %d, while expected %d" % (g, t)
33 def valid_link(l):
34 assert non_empty_string(l.href)
35 assert non_empty_string(l.title)
36 assert non_empty_string(l.user)
37 assert non_empty_string(l.comments_href)
38 assert type(l.comments) is int
39 assert type(l.score) is int or l.score is None