예제 #1
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)
예제 #2
0
    def set_bad_body(self):
        d = model.Document()

        b = model.Body()

        with self.assertRaises(ValueError):
            d.set_body(b)
예제 #3
0
    def add_bad_initial_value(self):
        d = model.Document()

        c1 = styles.ColorType((12, 23, 43, 56))

        with self.assertRaises(ValueError):
            d.put_initial_value(styles.StyleProperties.Extent, c1)
예제 #4
0
    def add_detached_region(self):
        d = model.Document()

        r = model.Region("hello")

        with self.assertRaises(ValueError):
            d.put_region(r)
예제 #5
0
    def add_region(self):
        d = model.Document()

        r = model.Region("hello", d)

        d.put_region(r)

        self.assertIs(d.get_region(r.get_id()), r)
예제 #6
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())
예제 #7
0
    def add_initial_value(self):
        d = model.Document()

        c = styles.ColorType((12, 23, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c)

        c2 = d.get_initial_value(styles.StyleProperties.Color)

        self.assertEqual(c, c2)
예제 #8
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)
예제 #9
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())
예제 #10
0
    def iter_region(self):
        d = model.Document()

        r1 = model.Region("hello1", d)

        r2 = model.Region("hello2", d)

        d.put_region(r1)

        d.put_region(r2)

        self.assertCountEqual(d.iter_regions(), [r1, r2])
예제 #11
0
    def add_dup_region(self):
        d = model.Document()

        r1 = model.Region("hello", d)

        r2 = model.Region("hello", d)

        d.put_region(r1)

        d.put_region(r2)

        self.assertIs(d.get_region(r2.get_id()), r2)
예제 #12
0
    def set_body(self):
        d = model.Document()

        b = model.Body(d)

        d.set_body(b)

        self.assertEqual(d.get_body(), b)

        d.set_body(None)

        self.assertIsNone(d.get_body())
예제 #13
0
    def process(context, ttml_elem):

        context.doc = model.Document()

        # process attributes

        space = XMLSpaceAttribute.extract(
            ttml_elem) or model.WhiteSpaceHandling.DEFAULT

        lang = XMLLangAttribute.extract(ttml_elem)

        if lang is None:
            LOGGER.warning("xml:lang not specified on tt")
            lang = ""

        context.doc.set_cell_resolution(
            CellResolutionAttribute.extract(ttml_elem))

        px_resolution = ExtentAttribute.extract(ttml_elem)

        if px_resolution is not None:
            context.doc.set_px_resolution(px_resolution)

        # process children elements elements

        has_body = False
        has_head = False

        for child_element in ttml_elem:

            if child_element.tag == BodyElement.qn:

                if not has_body:

                    context.doc.set_body(
                        ContentElement.process(context, space, lang,
                                               child_element))

                    has_body = True

                else:
                    LOGGER.error("More than one body element present")

            elif child_element.tag == HeadElement.qn:

                if not has_head:
                    HeadElement.process(context, space, lang, child_element)

                    has_head = True

                else:
                    LOGGER.error("More than one head element present")
예제 #14
0
    def add_dup_initial_value(self):
        d = model.Document()

        c1 = styles.ColorType((12, 23, 43, 56))

        c2 = styles.ColorType((12, 96, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c1)

        d.put_initial_value(styles.StyleProperties.Color, c2)

        self.assertIsNot(d.get_initial_value(styles.StyleProperties.Color), c1)

        self.assertIs(d.get_initial_value(styles.StyleProperties.Color), c2)
예제 #15
0
    def remove_region(self):
        d = model.Document()

        r = model.Region("hello", d)

        d.put_region(r)

        self.assertIs(d.get_region(r.get_id()), r)

        d.remove_region(r.get_id())

        self.assertFalse(d.has_region(r.get_id()))

        self.assertIsNone(d.get_region(r.get_id()))
예제 #16
0
    def iter_initial_values(self):
        d = model.Document()

        c1 = styles.ColorType((12, 23, 43, 56))

        c2 = styles.ColorType((12, 96, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c1)

        d.put_initial_value(styles.StyleProperties.BackgroundColor, c2)

        self.assertCountEqual([(styles.StyleProperties.Color, c1),
                               (styles.StyleProperties.BackgroundColor, c2)],
                              d.iter_initial_values())
예제 #17
0
    def test_init(self):
        d = model.Document()

        self.assertIsNone(d.get_body())

        self.assertEqual(d.get_px_resolution(),
                         model.PixelResolutionType(width=1920, height=1080))

        self.assertEqual(len(d.iter_initial_values()), 0)

        self.assertEqual(len(d.iter_regions()), 0)

        self.assertEqual(d.get_cell_resolution(),
                         model.CellResolutionType(rows=15, columns=32))
예제 #18
0
    def add_null_initial_value(self):
        d = model.Document()

        c = styles.ColorType((12, 23, 43, 56))

        d.put_initial_value(styles.StyleProperties.Color, c)

        c2 = d.get_initial_value(styles.StyleProperties.Color)

        self.assertEqual(c, c2)

        d.put_initial_value(styles.StyleProperties.Color, None)

        self.assertFalse(d.has_initial_value(styles.StyleProperties.Color))

        self.assertIsNone(d.get_initial_value(styles.StyleProperties.Color))