File: xkcd_test.py

package info (click to toggle)
python-xkcd 2.4.2-5
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: python: 302; makefile: 134
file content (40 lines) | stat: -rwxr-xr-x 973 bytes parent folder | download | duplicates (4)
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
# unit test suite for python-xkcd

import os
import unittest

import xkcd

class TestXkcd(unittest.TestCase):

	def test_no_such_comic(self):
		bad = xkcd.getComic(-100)
		self.assertEqual(bad.number, -1)

	def test_comic(self):
		# Get a comic to test.
		test = xkcd.getComic(869)
		self.assertEqual(test.number, 869)
		self.assertEqual(test.title, "Server Attention Span")
		self.assertEqual(test.imageName, "server_attention_span.png")

	def test_download_comic(self):
		# Try to download a comic.
		dlname = "xkcd-unittestserver_attention_span.png"
		test = xkcd.getComic(869)
		test.download(outputFile=dlname)

		path = os.path.join(os.path.expanduser("~"), "Downloads", dlname)
		self.assertTrue(os.path.exists(path))

		# Delete the downloaded file
		os.remove(path)

	def test_whatif(self):
		# Get a What If to test.
		test = xkcd.getWhatIf(3)
		self.assertEqual(test.number, 3)
		self.assertEqual(test.title, "Yoda")

if __name__ == '__main__':
	unittest.main()