PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1, GPL-2.0
  1. from swlib.pysw import VK
  2. import unittest
  3. from passage_entry import PassageEntry, InvalidPassageError, \
  4. lookup_passage_entry
  5. class TestPassageEntry(unittest.TestCase):
  6. def setUp(self):
  7. self._passage_entry = PassageEntry("gen 2:2")
  8. self._passage_entry2 = PassageEntry("gen 3:5 - 10")
  9. def testConstructorShouldCreateEmptyComment(self):
  10. self.assertEqual(self._passage_entry.comment, "")
  11. def testPassageCanBeSetFromStringInConstructor(self):
  12. passage_entry = PassageEntry("gen 2:3 - 5")
  13. self.assertEqual(str(passage_entry), "Genesis 2:3-5")
  14. def testConstructorShouldAllowSettingComment(self):
  15. self._passage_entry = PassageEntry("gen 3:2", "some comment")
  16. self.assertEqual(self._passage_entry.comment, "some comment")
  17. def testContainsVerseWorksWithSingleVerse(self):
  18. self.assert_(self._passage_entry.contains_verse(VK("gen 2:2")))
  19. self.assert_(not self._passage_entry.contains_verse(VK("gen 2:1")))
  20. def testContainsVerseWorksWithRange(self):
  21. self.assert_(self._passage_entry2.contains_verse(VK("gen 3:5")))
  22. self.assert_(self._passage_entry2.contains_verse(VK("gen 3:6")))
  23. self.assert_(self._passage_entry2.contains_verse(VK("gen 3:9")))
  24. self.assert_(self._passage_entry2.contains_verse(VK("gen 3:10")))
  25. self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:4")))
  26. self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:11")))
  27. def testStringMethodWorksOnVerses(self):
  28. self.assertEqual(str(self._passage_entry), "Genesis 2:2")
  29. def testStringMethodWorksOnRanges(self):
  30. self.assertEqual(str(self._passage_entry2), "Genesis 3:5-10")
  31. def testStringMethodWorksOnEmptyPassage(self):
  32. self.assertEqual(str(PassageEntry(None)), "")
  33. def testPassageCanBeSetFromString(self):
  34. self._passage_entry.passage = "exodus 4:4"
  35. self.assertEquals(str(self._passage_entry), "Exodus 4:4")
  36. def testPassageRangeCanBeSetFromString(self):
  37. self._passage_entry.passage = "exodus 4:4 - 5:7"
  38. self.assertEquals(str(self._passage_entry), "Exodus 4:4-5:7")
  39. def testPassageCannotBeSetFromInvalidString(self):
  40. self.assertRaises(InvalidPassageError,
  41. self._setPassage, "invalid reference")
  42. def testPassageCanBeSetFromStringWithMultiplePassages(self):
  43. self._setPassage("gen 3:5 - 7, 9, 11")
  44. def testPassageGlobalLookup(self):
  45. passage_entry = lookup_passage_entry(self._passage_entry.get_id())
  46. self.assert_(passage_entry is self._passage_entry)
  47. def _setPassage(self, passage):
  48. self._passage_entry.passage = passage
  49. if __name__ == "__main__":
  50. unittest.main()