Ejemplo n.º 1
0
    def test_remove(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        self.assertEqual(sum(1 for _ in p), 2)

        c2.remove()

        self.assertIsNone(c2.parent())

        self.assertIsNone(c2.next_sibling())

        self.assertIsNone(c2.previous_sibling())

        self.assertEqual(sum(1 for _ in p), 1)

        for a_child in p:
            self.assertEqual(a_child, c1)
Ejemplo n.º 2
0
    def test_remove_child(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        p.push_child(c3)

        c1.remove()

        self.assertEqual(sum(1 for _ in p), 2)

        c3.remove()

        self.assertEqual(sum(1 for _ in p), 1)

        c2.remove()

        self.assertEqual(sum(1 for _ in p), 0)
Ejemplo n.º 3
0
    def test_copy_to(self):
        src = model.ContentElement()

        src.set_begin(Fraction(1, 2))
        src.set_end(Fraction(1, 3))
        src.set_lang("fr")
        src.set_space(model.WhiteSpaceHandling.PRESERVE)
        src.set_id("hello")

        src.add_animation_step(
            model.DiscreteAnimationStep(styles.StyleProperties.Color, 0, 1,
                                        styles.NamedColors.aqua.value))
        src.set_style(styles.StyleProperties.Color,
                      styles.NamedColors.green.value)

        dest = model.ContentElement()

        src.copy_to(dest)

        self.assertEqual(dest.get_begin(), src.get_begin())
        self.assertEqual(dest.get_end(), src.get_end())
        self.assertEqual(dest.get_lang(), src.get_lang())
        self.assertEqual(dest.get_space(), src.get_space())
        self.assertEqual(dest.get_id(), src.get_id())

        self.assertSequenceEqual(list(dest.iter_animation_steps()),
                                 list(src.iter_animation_steps()))

        self.assertSequenceEqual(list(dest.iter_styles()),
                                 list(src.iter_styles()))
Ejemplo n.º 4
0
    def test_failed_child_detach(self):
        doc = model.Document()

        e = model.ContentElement(doc)

        c = model.ContentElement(doc)

        e.push_child(c)

        with self.assertRaises(RuntimeError):
            c.set_doc(None)
Ejemplo n.º 5
0
    def test_push_child(self):
        p = model.ContentElement()

        c = model.ContentElement()

        p.push_child(c)

        self.assertEqual(p, c.root())

        self.assertTrue(p.has_children())

        self.assertEqual(sum(1 for _ in p), 1)

        for a_child in p:
            self.assertEqual(a_child, c)
Ejemplo n.º 6
0
    def test_init(self):
        e = model.ContentElement()

        self.assertTrue(e.root() is e)
        self.assertIsNone(e.parent())
        self.assertFalse(e.has_children())
        self.assertIsNone(e.get_doc())
Ejemplo n.º 7
0
    def test_push_child_with_existing_parent(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        c1.push_child(c3)

        with self.assertRaises(RuntimeError):
            p.push_child(c3)
Ejemplo n.º 8
0
    def test_dfs(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        c1.push_child(c3)

        dfs = list(p.dfs_iterator())

        self.assertListEqual([p, c1, c3, c2], dfs)
Ejemplo n.º 9
0
    def test_remove_children(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        p.push_child(c3)

        p.remove_children()

        self.assertFalse(p.has_children())
Ejemplo n.º 10
0
    def test_attach(self):
        doc = model.Document()

        e = model.ContentElement()

        e.set_doc(doc)

        self.assertTrue(e.get_doc() is doc)
        self.assertTrue(e.is_attached())
Ejemplo n.º 11
0
    def test_already_attached(self):
        doc = model.Document()
        doc2 = model.Document()

        e = model.ContentElement()

        e.set_doc(doc)

        with self.assertRaises(RuntimeError):
            e.set_doc(doc2)
Ejemplo n.º 12
0
    def test_lang(self):
        p = model.ContentElement()

        self.assertEqual(p.get_lang(), "")

        lang = "fr-CA"

        p.set_lang(lang)

        self.assertEqual(p.get_lang(), lang)
Ejemplo n.º 13
0
    def test_space(self):
        p = model.ContentElement()

        self.assertEqual(p.get_space(), model.WhiteSpaceHandling.DEFAULT)

        space = model.WhiteSpaceHandling.PRESERVE

        p.set_space(space)

        self.assertEqual(p.get_space(), space)
Ejemplo n.º 14
0
    def test_begin(self):
        p = model.ContentElement()

        self.assertIsNone(p.get_begin())

        f = Fraction(1, 2)

        p.set_begin(f)

        self.assertEqual(p.get_begin(), f)
Ejemplo n.º 15
0
    def test_end(self):
        p = model.ContentElement()

        self.assertIsNone(p.get_end())

        f = Fraction(1, 3)

        p.set_end(f)

        self.assertEqual(p.get_end(), f)
Ejemplo n.º 16
0
    def test_detach(self):
        doc = model.Document()

        e = model.ContentElement()

        e.set_doc(doc)

        e.set_doc(None)

        self.assertIsNone(e.get_doc())
        self.assertFalse(e.is_attached())
Ejemplo n.º 17
0
    def test_children_accessors(self):
        p = model.ContentElement()

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        p.push_child(c3)

        self.assertEqual(len(p), 3)

        self.assertEqual(p[0], c1)

        self.assertRaises(IndexError, lambda key: p[key], 5)
Ejemplo n.º 18
0
    def test_first_last_child(self):
        p = model.ContentElement()

        self.assertIsNone(p.first_child())

        self.assertIsNone(p.last_child())

        c1 = model.ContentElement()

        c2 = model.ContentElement()

        c3 = model.ContentElement()

        p.push_child(c1)

        p.push_child(c2)

        p.push_child(c3)

        self.assertEqual(p.first_child(), c1)

        self.assertEqual(p.last_child(), c3)
Ejemplo n.º 19
0
    def test_id(self):
        p = model.ContentElement()

        self.assertIsNone(p.get_id())

        # good id
        good_id = "a"
        p.set_id(good_id)
        self.assertEqual(p.get_id(), good_id)

        # None
        p.set_id(None)
        self.assertIsNone(p.get_id())

        # bad id
        with self.assertRaises(TypeError):
            bad_id = " "
            p.set_id(bad_id)
Ejemplo n.º 20
0
    def test_add_remove_animation_step(self):
        p = model.ContentElement()

        s1 = model.DiscreteAnimationStep(styles.StyleProperties.Color, 0, 1,
                                         styles.NamedColors.aqua.value)

        s2 = model.DiscreteAnimationStep(styles.StyleProperties.Color, 2, None,
                                         styles.NamedColors.black.value)

        s3 = model.DiscreteAnimationStep(styles.StyleProperties.TextAlign, 1,
                                         None, styles.TextAlignType.center)

        p.add_animation_step(s1)

        p.add_animation_step(s2)

        p.add_animation_step(s3)

        self.assertListEqual([s1, s2, s3], list(p.iter_animation_steps()))

        p.remove_animation_step(s2)

        self.assertListEqual([s1, s3], list(p.iter_animation_steps()))
Ejemplo n.º 21
0
    def test_push_child_as_self(self):
        p = model.ContentElement()

        with self.assertRaises(RuntimeError):
            p.push_child(p)