generated from OpenTimelineIO/otio-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch unit tests by updating
OTIO_PLUGIN_MANIFEST_PATH
env var
Signed-off-by: Doug Halley <[email protected]>
- Loading branch information
1 parent
031b1e5
commit 48f052d
Showing
2 changed files
with
84 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,83 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Contributors to the OpenTimelineIO project | ||
|
||
"""Unit tests for the OTIO to SVG adapter""" | ||
|
||
import os | ||
import unittest | ||
import tempfile | ||
import xml.etree.ElementTree as ET | ||
|
||
import opentimelineio as otio | ||
|
||
SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data") | ||
SIMPLE_CUT_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.otio') | ||
SIMPLE_CUT_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.svg') | ||
MULTIPLE_TRACK_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.otio') | ||
MULTIPLE_TRACK_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.svg') | ||
TRANSITION_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.otio') | ||
TRANSITION_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.svg') | ||
|
||
|
||
def _svg_equal(e1, e2): | ||
if e1.tag != e2.tag: | ||
return False | ||
if e1.text != e2.text: | ||
return False | ||
if e1.tail != e2.tail: | ||
return False | ||
if e1.attrib != e2.attrib: | ||
return False | ||
if len(e1) != len(e2): | ||
return False | ||
return all(_svg_equal(c1, c2) for c1, c2 in zip(e1, e2)) | ||
|
||
|
||
class SVGAdapterTest(unittest.TestCase): | ||
def test_simple_cut(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file(SIMPLE_CUT_OTIO_PATH) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(SIMPLE_CUT_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) | ||
|
||
def test_multiple_tracks(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file( | ||
MULTIPLE_TRACK_OTIO_PATH | ||
) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(MULTIPLE_TRACK_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) | ||
|
||
def test_transition(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file(TRANSITION_OTIO_PATH) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(TRANSITION_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Contributors to the OpenTimelineIO project | ||
|
||
"""Unit tests for the OTIO to SVG adapter""" | ||
|
||
import os | ||
import unittest | ||
import tempfile | ||
import xml.etree.ElementTree as ET | ||
|
||
import opentimelineio as otio | ||
|
||
os.environ['OTIO_PLUGIN_MANIFEST_PATH'] = os.pathsep.join( | ||
["$OTIO_PLUGIN_MANIFEST_PATH", "../src/otio_svg_adapter/plugin_manifest.json"] | ||
) | ||
|
||
SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data") | ||
SIMPLE_CUT_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.otio') | ||
SIMPLE_CUT_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'simple_cut.svg') | ||
MULTIPLE_TRACK_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.otio') | ||
MULTIPLE_TRACK_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'multiple_track.svg') | ||
TRANSITION_OTIO_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.otio') | ||
TRANSITION_SVG_PATH = os.path.join(SAMPLE_DATA_DIR, 'transition.svg') | ||
|
||
|
||
def _svg_equal(e1, e2): | ||
if e1.tag != e2.tag: | ||
return False | ||
if e1.text != e2.text: | ||
return False | ||
if e1.tail != e2.tail: | ||
return False | ||
if e1.attrib != e2.attrib: | ||
return False | ||
if len(e1) != len(e2): | ||
return False | ||
return all(_svg_equal(c1, c2) for c1, c2 in zip(e1, e2)) | ||
|
||
|
||
class SVGAdapterTest(unittest.TestCase): | ||
def test_simple_cut(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file(SIMPLE_CUT_OTIO_PATH) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(SIMPLE_CUT_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) | ||
|
||
def test_multiple_tracks(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file( | ||
MULTIPLE_TRACK_OTIO_PATH | ||
) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(MULTIPLE_TRACK_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) | ||
|
||
def test_transition(self): | ||
self.maxDiff = None | ||
tmp_path = tempfile.mkstemp(suffix=".svg", text=True)[1] | ||
timeline = otio.core.deserialize_json_from_file(TRANSITION_OTIO_PATH) | ||
otio.adapters.write_to_file(input_otio=timeline, filepath=tmp_path) | ||
|
||
test_tree = ET.parse(TRANSITION_SVG_PATH) | ||
test_root = test_tree.getroot() | ||
|
||
reference_tree = ET.parse(tmp_path) | ||
reference_root = reference_tree.getroot() | ||
|
||
self.assertTrue(_svg_equal(test_root, reference_root)) |