def test_parseSpecialCitations(self): readingCount = 0 for mass in lectionary.getLectionary()._allSpecialMasses: for reading in mass.allReadings: readingCount += 1 citations.parse(reading.citation) # $ grep --count /reading special-lectionary.xml self.assertEqual(84, readingCount)
def test_parseWeekdayCitations(self): readingCount = 0 for mass in lectionary.getLectionary()._allWeekdayMasses: for reading in mass.allReadings: readingCount += 1 # TODO: Here is one we cannot parse yet! if reading.citation == 'Est C:12,14-16,23-25': continue citations.parse(reading.citation) # $ grep --count /reading weekday-lectionary.xml self.assertEqual(863, readingCount)
def getVerses(query): ''' Return an object representation of the verses associated with `query` that you can format according to your needs. The `query` is parsed by :func:`citations.parse`. The representation of the returned verses is a ``list`` of pairs. The first element in each pair is the **address** of a verse. The second element in each pair is the **text** of the same verse. The address of the verse is itself a pair of integers representing the **chapter** and **verse** respectively. (This will have to change to handle the insertions into Esther.) ''' citation = citations.parse(query) book = getBible().findBook(citation.book) if citation.addrs is None: # This is the citation of an entire book. return book.text.getAllVerses() try: return list( itertools.chain.from_iterable( book.text.getRangeOfVerses(addrRange) for addrRange in citation.addrRanges)) except KeyError as e: raise InvalidCitation(citation, e), None, sys.exc_info()[2]
def test_parseSundayCitations(self): ''' Prove that the number of readings we find in the Sunday Lectionary by invoking ``grep`` on the XML equals the number of readings we find in our object representation of the Sunday Lectionary. Furthermore, prove that we can parse every one of the citations. ''' readingCount = 0 for mass in lectionary.getLectionary().allSundayMasses: for reading in mass.allReadings: readingCount += 1 citations.parse(reading.citation) # $ grep --count /reading sunday-lectionary.xml self.assertEqual(535, readingCount)
def title(self): ''' The title of the reading. ''' tokens = [citations.parse(self._citation).displayString] if self._optionSetIndex is not None: tokens.append('(Option %d of %d)' % (self._optionIndex + 1, self._optionSetSize)) return ' '.join(tokens)
def test_songOfSongs(self): ''' This case requires that the parsing of the book tokens be 'greedy'. Because 'song' is both an abbreviations for this book and the first word in its full name, a non-greedy approach to parsing-out the name of the book will leave too many tokens behind. ''' ref = citations.parse('song of songs 1:2-3:4') self.assertEqual('songofsongs', ref.book) self.assertEqual([addrs.AddrRange(addrs.Addr(1, 2), addrs.Addr(3, 4))], ref.addrs)
def test_syntheticAndMinimal(self): ''' This is exact same series appears in parseVersesTokenTestCase, but here we add the name of a book. ''' ref = citations.parse('gn 1') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.Addr(1)], ref.addrs) ref = citations.parse('gn 1-2') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.AddrRange(addrs.Addr(1), addrs.Addr(2))], ref.addrs) ref = citations.parse('gn 1,3') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.Addr(1), addrs.Addr(3)], ref.addrs) ref = citations.parse('gn 1-2,4') self.assertEqual('genesis', ref.book) self.assertEqual( [addrs.AddrRange(addrs.Addr(1), addrs.Addr(2)), addrs.Addr(4)], ref.addrs) ref = citations.parse('gn 1:1') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.Addr(1, 1)], ref.addrs) ref = citations.parse('gn 1:1-2') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(1, 2))], ref.addrs) ref = citations.parse('gn 1:1,3') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.Addr(1, 1), addrs.Addr(1, 3)], ref.addrs) ref = citations.parse('gn 1:1-2,4') self.assertEqual('genesis', ref.book) self.assertEqual([ addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(1, 2)), addrs.Addr(1, 4) ], ref.addrs) ref = citations.parse('gn 1:1-2:1') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(2, 1))], ref.addrs) ref = citations.parse('gn 1:1,2:1') self.assertEqual('genesis', ref.book) self.assertEqual([addrs.Addr(1, 1), addrs.Addr(2, 1)], ref.addrs) ref = citations.parse('gn 1:1,3,2:1') self.assertEqual('genesis', ref.book) self.assertEqual( [addrs.Addr(1, 1), addrs.Addr(1, 3), addrs.Addr(2, 1)], ref.addrs) ref = citations.parse('gn 1:1,3-2:1') self.assertEqual('genesis', ref.book) self.assertEqual([ addrs.Addr(1, 1), addrs.AddrRange(addrs.Addr(1, 3), addrs.Addr(2, 1)) ], ref.addrs)
def test_twoTokenBookPlus(self): ref = citations.parse('1 samuel 1:2-3:4') self.assertEqual('1samuel', ref.book) self.assertEqual([addrs.AddrRange(addrs.Addr(1, 2), addrs.Addr(3, 4))], ref.addrs)
def test_twoTokenBookOnly(self): ref = citations.parse('1 samuel') self.assertEqual('1samuel', ref.book) self.assertEqual(None, ref.addrs)
def test_singleTokenBookOnly(self): ref = citations.parse('gn') self.assertEqual('genesis', ref.book) self.assertEqual(None, ref.addrs)
def test_actualMistakes(self): with self.assertRaises(citations.ParsingError): citations.parse('Ez` 37:12-14') with self.assertRaises(citations.ParsingError): citations.parse('3 Lk 24:13-35') with self.assertRaises(citations.ParsingError): citations.parse('Acts 2:14:22-33') with self.assertRaises(citations.ParsingError): citations.parse('1 Pt2:20b-25') with self.assertRaises(citations.ParsingError): citations.parse('Zep 2:3,3:12--13') with self.assertRaises(citations.ParsingError): citations.parse('I s58:7-10') with self.assertRaises(citations.ParsingError): citations.parse('Cor 5:6b-8') with self.assertRaises(citations.ParsingError): citations.parse('Is 49L1-6')
def test_emptyString(self): with self.assertRaises(citations.ParsingError): citations.parse('')
def test_None(self): with self.assertRaises(citations.ParsingError): citations.parse(None)