Exemplo n.º 1
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'))
Exemplo n.º 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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def normalize(loc):
     if isinstance(loc, addrs.AddrRange):
         return loc
     else:
         return addrs.AddrRange(loc, loc)
Exemplo n.º 7
0
 def test_str(self):
     self.assertEqual(
         '1:2-3:4', str(addrs.AddrRange(addrs.Addr(1, 2), addrs.Addr(3,
                                                                     4))))
Exemplo n.º 8
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)))