コード例 #1
0
    def test_getVerse(self):
        text = texts.Text('testing')
        text.loadFromString(self.bookWithChaptersText)

        # This should return all of chapter 1.
        result = text.getVerse(addrs.Addr(1))
        self.assertEqual(result, [
            ((1, 1), u'In principio creavit Deus cælum et terram.'),
            ((1, 2), u'Terra autem erat inanis et vacua...'),
            ((1, 3), u'Dixitque Deus...'),
        ])

        # This should return all of chapter 2.
        result = text.getVerse(addrs.Addr(2))
        self.assertEqual(result, [
            ((2, 1), u'Igitur perfecti sunt cæli et terra...'),
            ((2, 2),
             u'Complevitque Deus die septimo opus suum quod fecerat...'),
            ((2, 3), u'Et benedixit diei septimo...'),
        ])

        # This should return verse 1:1.
        result = text.getVerse(addrs.Addr(1, 1))
        self.assertEqual(result, [
            ((1, 1), u'In principio creavit Deus cælum et terram.'),
        ])

        # This should return verse 1:2.
        result = text.getVerse(addrs.Addr(1, 2))
        self.assertEqual(result, [
            ((1, 2), u'Terra autem erat inanis et vacua...'),
        ])

        # This should return verse 2:3:
        result = text.getVerse(addrs.Addr(2, 3))
        self.assertEqual(result, [
            ((2, 3), u'Et benedixit diei septimo...'),
        ])

        text = texts.Text('testing', False)
        text.loadFromString(self.bookWithoutChaptersText)

        # This should return only verse 1.
        result = text.getVerse(addrs.Addr(1))
        self.assertEqual(result, [
            (1, u'Judas Jesu Christi servus...'),
        ])

        # This should return only verse 2.
        result = text.getVerse(addrs.Addr(2))
        self.assertEqual(result, [
            (2, u'Misericordia vobis...'),
        ])

        # A request for 1:2 should also return verse 2, but the
        # 'address' should have the shape of the reference.
        result = text.getVerse(addrs.Addr(1, 2))
        self.assertEqual(result, [
            ((1, 2), u'Misericordia vobis...'),
        ])
コード例 #2
0
    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)
コード例 #3
0
    def write(self, outputFile=sys.stdout):
        '''
        Write the entire text of the book to `outputFile` in a format
        that resembles the original input.
        '''

        for chapterKey, verses in self._text.iteritems():
            for verseKey, verseText in verses.iteritems():
                outputFile.write(
                    '%s %s\n' % (addrs.Addr(chapterKey, verseKey), verseText))
コード例 #4
0
    def test_getRangeOfVerses(self):
        text = texts.Text('testing')
        text.loadFromString(self.bookWithChaptersText)

        # Here are a few ranges entirely within the same chapter,
        # starting with 1:1-1:3.
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(1, 3)))
        self.assertEqual(
            [((1, 1), u'In principio creavit Deus cælum et terram.'),
             ((1, 2), u'Terra autem erat inanis et vacua...'),
             ((1, 3), u'Dixitque Deus...')], verses)

        # 2:1-2:2
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(2, 1), addrs.Addr(2, 2)))
        self.assertEqual(
            [((2, 1), u'Igitur perfecti sunt cæli et terra...'),
             ((2, 2),
              u'Complevitque Deus die septimo opus suum quod fecerat...')],
            verses)

        # 3:2-3:3
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(3, 2), addrs.Addr(3, 3)))
        self.assertEqual(
            [((3, 2), u'Cui respondit mulier...'),
             ((3, 3), u'de fructu vero ligni quod est in medio paradisi...')],
            verses)

        # Here are some ranges in adjacent chapters, starting with
        # 1:1-2:1:
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(2, 1)))
        self.assertEqual(
            [((1, 1), u'In principio creavit Deus cælum et terram.'),
             ((1, 2), u'Terra autem erat inanis et vacua...'),
             ((1, 3), u'Dixitque Deus...'),
             ((2, 1), u'Igitur perfecti sunt cæli et terra...')], verses)

        # 2:2-3:2
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(2, 2), addrs.Addr(3, 2)))
        self.assertEqual([
            ((2, 2),
             u'Complevitque Deus die septimo opus suum quod fecerat...'),
            ((2, 3), u'Et benedixit diei septimo...'),
            ((3, 1),
             u'Sed et serpens erat callidior cunctis animantibus terræ quæ fecerat Dominus Deus...'
             ), ((3, 2), u'Cui respondit mulier...')
        ], verses)

        # Finally, here is the case of a book in the middle: 1:3-3:1:
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(1, 3), addrs.Addr(3, 1)))
        self.assertEqual([
            ((1, 3), u'Dixitque Deus...'),
            ((2, 1), u'Igitur perfecti sunt cæli et terra...'),
            ((2, 2),
             u'Complevitque Deus die septimo opus suum quod fecerat...'),
            ((2, 3), u'Et benedixit diei septimo...'),
            ((3, 1),
             u'Sed et serpens erat callidior cunctis animantibus terræ quæ fecerat Dominus Deus...'
             )
        ], verses)

        # Now let's see if we can handle whole-chapter ranges like
        # 1-2:
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(1), addrs.Addr(2)))
        self.assertEqual(
            [((1, 1), u'In principio creavit Deus cælum et terram.'),
             ((1, 2), u'Terra autem erat inanis et vacua...'),
             ((1, 3), u'Dixitque Deus...'),
             ((2, 1), u'Igitur perfecti sunt cæli et terra...'),
             ((2, 2),
              u'Complevitque Deus die septimo opus suum quod fecerat...'),
             ((2, 3), u'Et benedixit diei septimo...')], verses)

        # What about a range like 1-1?  We don't expect this from a
        # human, but it can happen when we normalize a mix of
        # addresses and address ranges to address ranges.
        expectedVerses = [((1, 1),
                           u'In principio creavit Deus cælum et terram.'),
                          ((1, 2), u'Terra autem erat inanis et vacua...'),
                          ((1, 3), u'Dixitque Deus...')]
        self.assertEqual(
            expectedVerses,
            text.getRangeOfVerses(addrs.AddrRange(addrs.Addr(1),
                                                  addrs.Addr(1))))

        # What about a range that begins on a chapter, but ends on a
        # verse, like 1-2:2:
        verses = text.getRangeOfVerses(
            addrs.AddrRange(addrs.Addr(1), addrs.Addr(2, 2)))
        self.assertEqual(
            [((1, 1), u'In principio creavit Deus cælum et terram.'),
             ((1, 2), u'Terra autem erat inanis et vacua...'),
             ((1, 3), u'Dixitque Deus...'),
             ((2, 1), u'Igitur perfecti sunt cæli et terra...'),
             ((2, 2),
              u'Complevitque Deus die septimo opus suum quod fecerat...')],
            verses)
コード例 #5
0
    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)
コード例 #6
0
 def test_chapterIsLetter(self):
     self.assertEqual([addrs.Addr('C', 12)], addrs.parse('C:12'))
コード例 #7
0
 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)
コード例 #8
0
 def test_syntheticAndMinimal(self):
     self.assertEqual([addrs.Addr(1)], addrs.parse('1'))
     self.assertEqual([addrs.AddrRange(addrs.Addr(1), addrs.Addr(2))],
                      addrs.parse('1-2'))
     self.assertEqual([addrs.Addr(1), addrs.Addr(3)], addrs.parse('1,3'))
     self.assertEqual(
         [addrs.AddrRange(addrs.Addr(1), addrs.Addr(2)),
          addrs.Addr(4)], addrs.parse('1-2,4'))
     self.assertEqual([addrs.Addr(1, 1)], addrs.parse('1:1'))
     self.assertEqual([addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(1, 2))],
                      addrs.parse('1:1-2'))
     self.assertEqual([addrs.Addr(1, 1), addrs.Addr(1, 3)],
                      addrs.parse('1:1,3'))
     self.assertEqual([
         addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(1, 2)),
         addrs.Addr(1, 4)
     ], addrs.parse('1:1-2,4'))
     self.assertEqual([addrs.AddrRange(addrs.Addr(1, 1), addrs.Addr(2, 1))],
                      addrs.parse('1:1-2:1'))
     self.assertEqual([addrs.Addr(1, 1), addrs.Addr(2, 1)],
                      addrs.parse('1:1,2:1'))
     self.assertEqual(
         [addrs.Addr(1, 1),
          addrs.Addr(1, 3),
          addrs.Addr(2, 1)], addrs.parse('1:1,3,2:1'))
     self.assertEqual([
         addrs.Addr(1, 1),
         addrs.AddrRange(addrs.Addr(1, 3), addrs.Addr(2, 1))
     ], addrs.parse('1:1,3-2:1'))
コード例 #9
0
 def test_str(self):
     self.assertEqual(
         '1:2-3:4', str(addrs.AddrRange(addrs.Addr(1, 2), addrs.Addr(3,
                                                                     4))))
コード例 #10
0
 def test_eq(self):
     self.assertTrue(addrs.AddrRange(1, 2) == addrs.AddrRange(1, 2))
     self.assertTrue(
         addrs.AddrRange(addrs.Addr(1), addrs.Addr(2)) == \
             addrs.AddrRange(addrs.Addr(1), addrs.Addr(2)))
コード例 #11
0
 def test_str(self):
     self.assertEqual('1', str(addrs.Addr(1)))
     self.assertEqual('2', str(addrs.Addr(2)))
     self.assertEqual('1:2', str(addrs.Addr(1, 2)))
コード例 #12
0
 def test_eq(self):
     self.assertTrue(addrs.Addr(1) == addrs.Addr(1))
     self.assertTrue(addrs.Addr(2) == addrs.Addr(2))