コード例 #1
0
    def test_hiero_flavored_xml(self):
        timeline = adapters.read_from_file(HIERO_XML_PATH)
        self.assertTrue(len(timeline.tracks), 1)
        self.assertTrue(timeline.tracks[0].name == 'Video 1')

        clips = [c for c in timeline.tracks[0].each_clip()]
        self.assertTrue(len(clips), 2)

        self.assertTrue(clips[0].name == 'A160C005_171213_R0MN')
        self.assertTrue(clips[1].name == '/')

        self.assertTrue(
            isinstance(
                clips[0].media_reference,
                schema.ExternalReference
            )
        )

        self.assertTrue(
            isinstance(
                clips[1].media_reference,
                schema.MissingReference
            )
        )

        source_range = opentime.TimeRange(
            start_time=opentime.RationalTime(1101071, 24),
            duration=opentime.RationalTime(1055, 24)
        )
        self.assertTrue(clips[0].source_range == source_range)

        available_range = opentime.TimeRange(
            start_time=opentime.RationalTime(1101071, 24),
            duration=opentime.RationalTime(1055, 24)
        )
        self.assertTrue(clips[0].available_range() == available_range)

        clip_1_range = clips[1].available_range()
        self.assertEqual(
            clip_1_range,
            opentime.TimeRange(
                opentime.RationalTime(),
                opentime.RationalTime(1, 24),
            )
        )

        # Test serialization
        tmp_path = tempfile.mkstemp(suffix=".xml", text=True)[1]
        adapters.write_to_file(timeline, tmp_path)

        # Similar to the test_roundtrip_disk2mem2disk above
        # the track name element among others will not be present in a new xml.
        with open(HIERO_XML_PATH, "r") as original_file:
            with open(tmp_path, "r") as output_file:
                self.assertNotEqual(original_file.read(), output_file.read())
コード例 #2
0
    def test_roundtrip_disk2mem2disk(self):
        # somefile.xml -> OTIO
        timeline = adapters.read_from_file(FCP7_XML_EXAMPLE_PATH)
        tmp_path = tempfile.mkstemp(suffix=".xml", text=True)[1]

        # somefile.xml -> OTIO -> tempfile.xml
        adapters.write_to_file(timeline, tmp_path)

        # somefile.xml -> OTIO -> tempfile.xml -> OTIO
        result = adapters.read_from_file(tmp_path)

        # TODO: OTIO doesn't support linking items for the moment, so the
        # adapter reads links to the metadata, but doesn't write them.
        # See _dict_to_xml_tree for more information.
        def scrub_md_dicts(timeline):
            def scrub_displayformat(md_dict):
                for ignore_key in {"link"}:
                    try:
                        del(md_dict[ignore_key])
                    except KeyError:
                        pass

                for value in list(md_dict.values()):
                    try:
                        value.items()
                        scrub_displayformat(value)
                    except AttributeError:
                        pass

            for child in timeline.tracks.each_child():
                scrub_displayformat(child.metadata)
                try:
                    scrub_displayformat(child.media_reference.metadata)
                except AttributeError:
                    pass

        # media reference bug, ensure that these match
        self.assertJsonEqual(
            result.tracks[0][1].media_reference,
            timeline.tracks[0][1].media_reference
        )

        scrub_md_dicts(result)
        scrub_md_dicts(timeline)

        self.assertJsonEqual(result, timeline)
        self.assertIsOTIOEquivalentTo(result, timeline)

        # But the xml text on disk is not identical because otio has a subset
        # of features to xml and we drop all the nle specific preferences.
        with open(FCP7_XML_EXAMPLE_PATH, "r") as original_file:
            with open(tmp_path, "r") as output_file:
                self.assertNotEqual(original_file.read(), output_file.read())