PageRenderTime 336ms CodeModel.GetById 133ms app.highlight 8ms RepoModel.GetById 112ms app.codeStats 1ms

/passage_list/test_passage_entry.py

http://bpbible.googlecode.com/
Python | 66 lines | 64 code | 2 blank | 0 comment | 0 complexity | e994e7dced65e33af16e36a241803e50 MD5 | raw file
 1from swlib.pysw import VK
 2import unittest
 3from passage_entry import PassageEntry, InvalidPassageError, \
 4		lookup_passage_entry
 5
 6class TestPassageEntry(unittest.TestCase):
 7	def setUp(self):
 8		self._passage_entry = PassageEntry("gen 2:2")
 9		self._passage_entry2 = PassageEntry("gen 3:5 - 10")
10	
11	def testConstructorShouldCreateEmptyComment(self):
12		self.assertEqual(self._passage_entry.comment, "")
13	
14	def testPassageCanBeSetFromStringInConstructor(self):
15		passage_entry = PassageEntry("gen 2:3 - 5")
16		self.assertEqual(str(passage_entry), "Genesis 2:3-5")
17
18	def testConstructorShouldAllowSettingComment(self):
19		self._passage_entry = PassageEntry("gen 3:2", "some comment")
20		self.assertEqual(self._passage_entry.comment, "some comment")
21	
22	def testContainsVerseWorksWithSingleVerse(self):
23		self.assert_(self._passage_entry.contains_verse(VK("gen 2:2")))
24		self.assert_(not self._passage_entry.contains_verse(VK("gen 2:1")))
25	
26	def testContainsVerseWorksWithRange(self):
27		self.assert_(self._passage_entry2.contains_verse(VK("gen 3:5")))
28		self.assert_(self._passage_entry2.contains_verse(VK("gen 3:6")))
29		self.assert_(self._passage_entry2.contains_verse(VK("gen 3:9")))
30		self.assert_(self._passage_entry2.contains_verse(VK("gen 3:10")))
31		self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:4")))
32		self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:11")))
33	
34	def testStringMethodWorksOnVerses(self):
35		self.assertEqual(str(self._passage_entry), "Genesis 2:2")
36	
37	def testStringMethodWorksOnRanges(self):
38		self.assertEqual(str(self._passage_entry2), "Genesis 3:5-10")
39	
40	def testStringMethodWorksOnEmptyPassage(self):
41		self.assertEqual(str(PassageEntry(None)), "")
42	
43	def testPassageCanBeSetFromString(self):
44		self._passage_entry.passage = "exodus 4:4"
45		self.assertEquals(str(self._passage_entry), "Exodus 4:4")
46	
47	def testPassageRangeCanBeSetFromString(self):
48		self._passage_entry.passage = "exodus 4:4 - 5:7"
49		self.assertEquals(str(self._passage_entry), "Exodus 4:4-5:7")
50
51	def testPassageCannotBeSetFromInvalidString(self):
52		self.assertRaises(InvalidPassageError,
53				self._setPassage, "invalid reference")
54
55	def testPassageCanBeSetFromStringWithMultiplePassages(self):
56		self._setPassage("gen 3:5 - 7, 9, 11")
57
58	def testPassageGlobalLookup(self):
59		passage_entry = lookup_passage_entry(self._passage_entry.get_id())
60		self.assert_(passage_entry is self._passage_entry)
61	
62	def _setPassage(self, passage):
63		self._passage_entry.passage = passage
64
65if __name__ == "__main__":
66	unittest.main()