Esempio n. 1
0
    def test_descendants(self):
        desc = list(descendants(self.xc1[0]['p']))
        self.assertEqual(desc, [])

        desc = list(descendants(self.xc2[0]['p']))
        self.assertEqual(len(desc), 1)
        self.check(desc[0], 'p', 'alignment', 't', ['t1'])

        desc = list(descendants(self.xc3[0]['p']))
        self.assertEqual(len(desc), 3)
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[2], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])

        desc = list(descendants(self.xc3[0]['w']['w1']))
        self.assertEqual(len(desc), 2)
        self.check(desc[0], 'w', 'segmentation', 'm', ['m1', 'm2'])
        self.check(desc[1], 'm', 'alignment', 'g', ['g1', 'g2'])

        desc = list(descendants(self.xc3[0]['p'], follow='all'))
        self.assertEqual(len(desc), 5)
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'p', 'alignment', 't', ['t1'])
        self.check(desc[2], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[3], 'w', 'alignment', 'x',
                   ['x1', 'x2', 'x3'])
        self.check(desc[4], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])

        desc = list(
            descendants(self.xc3[0]['p'],
                        refattrs=('segmentation', 'alignment', 'children'),
                        follow='all')
        )
        self.assertEqual(len(desc), 6)
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'p', 'alignment', 't', ['t1'])
        self.check(desc[2], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[3], 'w', 'alignment', 'x',
                   ['x1', 'x2', 'x3'])
        self.check(desc[4], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])
        self.check(desc[5], 'x', 'children', 'x',
                   ['x4', 'x5'])
Esempio n. 2
0
    def test_descendants(self):
        desc = list(descendants(xc1[0]['p']))
        assert desc == []

        desc = list(descendants(xc2[0]['p']))
        assert len(desc) == 1
        self.check(desc[0], 'p', 'alignment', 't', ['t1'])

        desc = list(descendants(xc3[0]['p']))
        assert len(desc) == 3
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[2], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])

        desc = list(descendants(xc3[0]['w']['w1']))
        assert len(desc) == 2
        self.check(desc[0], 'w', 'segmentation', 'm', ['m1', 'm2'])
        self.check(desc[1], 'm', 'alignment', 'g', ['g1', 'g2'])

        desc = list(descendants(xc3[0]['p'], follow='all'))
        assert len(desc) == 5
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'p', 'alignment', 't', ['t1'])
        self.check(desc[2], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[3], 'w', 'alignment', 'x',
                   ['x1', 'x2', 'x3'])
        self.check(desc[4], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])

        desc = list(
            descendants(xc3[0]['p'],
                        refattrs=('segmentation', 'alignment', 'children'),
                        follow='all')
        )
        assert len(desc) == 6
        self.check(desc[0], 'p', 'segmentation', 'w', ['w1', 'w2', 'w3'])
        self.check(desc[1], 'p', 'alignment', 't', ['t1'])
        self.check(desc[2], 'w', 'segmentation', 'm',
                   ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'])
        self.check(desc[3], 'w', 'alignment', 'x',
                   ['x1', 'x2', 'x3'])
        self.check(desc[4], 'm', 'alignment', 'g',
                   ['g1', 'g2', 'g3', 'g4', 'g5', 'g6'])
        self.check(desc[5], 'x', 'children', 'x',
                   ['x4', 'x5'])

        desc = list(descendants(xc4[0]['w']))
        assert len(desc) == 1
        self.check(desc[0], 'w', 'segmentation', 'w', ['w1'])

        desc = list(descendants(xc4[0]['w'], follow='all'))
        assert len(desc) == 1
        self.check(desc[0], 'w', 'segmentation', 'w', ['w1'])

        desc = list(descendants(xc5[0]['w']))
        assert len(desc) == 1
        self.check(desc[0], 'w', 'segmentation', 'w', ['w1', 'w2'])

        desc = list(descendants(xc5[0]['w'], follow='all'))
        assert len(desc) == 1
        self.check(desc[0], 'w', 'segmentation', 'w', ['w1', 'w2'])