|
1 | | -# SPDX-License-Identifier: Apache-2.0 |
2 | | -# Copyright Contributors to the OpenTimelineIO project |
3 | | - |
4 | | -"""Unit tests for the OTIO to SVG adapter""" |
5 | | - |
6 | | -import os |
7 | | -import unittest |
8 | | -import tempfile |
9 | | -import xml.etree.ElementTree as ET |
10 | | - |
11 | | -import opentimelineio as otio |
12 | | - |
13 | | -SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data") |
14 | | -SIMPLE_CUT_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.otio') |
15 | | -SIMPLE_CUT_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.svg') |
16 | | -MULTIPLE_TRACK_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.otio') |
17 | | -MULTIPLE_TRACK_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.svg') |
18 | | -TRANSITION_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.otio') |
19 | | -TRANSITION_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.svg') |
20 | | - |
21 | | - |
22 | | -def _svg_equal(e1, e2): |
23 | | - if e1.tag != e2.tag: |
24 | | - return False |
25 | | - if e1.text != e2.text: |
26 | | - return False |
27 | | - if e1.tail != e2.tail: |
28 | | - return False |
29 | | - if e1.attrib != e2.attrib: |
30 | | - return False |
31 | | - if len(e1) != len(e2): |
32 | | - return False |
33 | | - return all(_svg_equal(c1, c2) for c1, c2 in zip(e1, e2)) |
34 | | - |
35 | | - |
36 | | -class SVGAdapterTest(unittest.TestCase): |
37 | | - def test_simple_cut(self): |
38 | | - self.maxDiff = None |
39 | | - tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
40 | | - timeline = otio.core.deserialize_json_from_file(SIMPLE_CUT_OTIO_PATH) |
41 | | - otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
42 | | - |
43 | | - test_tree = ET.parse(SIMPLE_CUT_SVG_PATH) |
44 | | - test_root = test_tree.getroot() |
45 | | - |
46 | | - reference_tree = ET.parse(tmp_path) |
47 | | - reference_root = reference_tree.getroot() |
48 | | - |
49 | | - self.assertTrue(_svg_equal(test_root, reference_root)) |
50 | | - |
51 | | - def test_multiple_tracks(self): |
52 | | - self.maxDiff = None |
53 | | - tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
54 | | - timeline = otio.core.deserialize_json_from_file( |
55 | | - MULTIPLE_TRACK_OTIO_PATH |
56 | | - ) |
57 | | - otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
58 | | - |
59 | | - test_tree = ET.parse(MULTIPLE_TRACK_SVG_PATH) |
60 | | - test_root = test_tree.getroot() |
61 | | - |
62 | | - reference_tree = ET.parse(tmp_path) |
63 | | - reference_root = reference_tree.getroot() |
64 | | - |
65 | | - self.assertTrue(_svg_equal(test_root, reference_root)) |
66 | | - |
67 | | - def test_transition(self): |
68 | | - self.maxDiff = None |
69 | | - tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
70 | | - timeline = otio.core.deserialize_json_from_file(TRANSITION_OTIO_PATH) |
71 | | - otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
72 | | - |
73 | | - test_tree = ET.parse(TRANSITION_SVG_PATH) |
74 | | - test_root = test_tree.getroot() |
75 | | - |
76 | | - reference_tree = ET.parse(tmp_path) |
77 | | - reference_root = reference_tree.getroot() |
78 | | - |
79 | | - self.assertTrue(_svg_equal(test_root, reference_root)) |
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# Copyright Contributors to the OpenTimelineIO project |
| 3 | + |
| 4 | +"""Unit tests for the OTIO to SVG adapter""" |
| 5 | + |
| 6 | +import os |
| 7 | +import unittest |
| 8 | +import tempfile |
| 9 | +import xml.etree.ElementTree as ET |
| 10 | + |
| 11 | +import opentimelineio as otio |
| 12 | + |
| 13 | +os.environ['OTIO_PLUGIN_MANIFEST_PATH'] = os.pathsep.join( |
| 14 | + ["$OTIO_PLUGIN_MANIFEST_PATH", "../src/otio_svg_adapter/plugin_manifest.json"] |
| 15 | +) |
| 16 | + |
| 17 | +SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data") |
| 18 | +SIMPLE_CUT_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.otio') |
| 19 | +SIMPLE_CUT_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.svg') |
| 20 | +MULTIPLE_TRACK_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.otio') |
| 21 | +MULTIPLE_TRACK_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.svg') |
| 22 | +TRANSITION_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.otio') |
| 23 | +TRANSITION_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.svg') |
| 24 | + |
| 25 | + |
| 26 | +def _svg_equal(e1, e2): |
| 27 | + if e1.tag != e2.tag: |
| 28 | + return False |
| 29 | + if e1.text != e2.text: |
| 30 | + return False |
| 31 | + if e1.tail != e2.tail: |
| 32 | + return False |
| 33 | + if e1.attrib != e2.attrib: |
| 34 | + return False |
| 35 | + if len(e1) != len(e2): |
| 36 | + return False |
| 37 | + return all(_svg_equal(c1, c2) for c1, c2 in zip(e1, e2)) |
| 38 | + |
| 39 | + |
| 40 | +class SVGAdapterTest(unittest.TestCase): |
| 41 | + def test_simple_cut(self): |
| 42 | + self.maxDiff = None |
| 43 | + tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
| 44 | + timeline = otio.core.deserialize_json_from_file(SIMPLE_CUT_OTIO_PATH) |
| 45 | + otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
| 46 | + |
| 47 | + test_tree = ET.parse(SIMPLE_CUT_SVG_PATH) |
| 48 | + test_root = test_tree.getroot() |
| 49 | + |
| 50 | + reference_tree = ET.parse(tmp_path) |
| 51 | + reference_root = reference_tree.getroot() |
| 52 | + |
| 53 | + self.assertTrue(_svg_equal(test_root, reference_root)) |
| 54 | + |
| 55 | + def test_multiple_tracks(self): |
| 56 | + self.maxDiff = None |
| 57 | + tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
| 58 | + timeline = otio.core.deserialize_json_from_file( |
| 59 | + MULTIPLE_TRACK_OTIO_PATH |
| 60 | + ) |
| 61 | + otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
| 62 | + |
| 63 | + test_tree = ET.parse(MULTIPLE_TRACK_SVG_PATH) |
| 64 | + test_root = test_tree.getroot() |
| 65 | + |
| 66 | + reference_tree = ET.parse(tmp_path) |
| 67 | + reference_root = reference_tree.getroot() |
| 68 | + |
| 69 | + self.assertTrue(_svg_equal(test_root, reference_root)) |
| 70 | + |
| 71 | + def test_transition(self): |
| 72 | + self.maxDiff = None |
| 73 | + tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] |
| 74 | + timeline = otio.core.deserialize_json_from_file(TRANSITION_OTIO_PATH) |
| 75 | + otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) |
| 76 | + |
| 77 | + test_tree = ET.parse(TRANSITION_SVG_PATH) |
| 78 | + test_root = test_tree.getroot() |
| 79 | + |
| 80 | + reference_tree = ET.parse(tmp_path) |
| 81 | + reference_root = reference_tree.getroot() |
| 82 | + |
| 83 | + self.assertTrue(_svg_equal(test_root, reference_root)) |
0 commit comments