Skip to content

Commit

Permalink
Rearrange the commandline files into a submodule. (#299)
Browse files Browse the repository at this point in the history
* Rearrange the commandline files into a submodule.
* Add basic unit tests for console module.
  • Loading branch information
ssteinbach committed Aug 1, 2018
1 parent 54f43fb commit f1e53e5
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 10 deletions.
Empty file removed bin/__init__.py
Empty file.
1 change: 1 addition & 0 deletions opentimelineio/__init__.py
Expand Up @@ -41,4 +41,5 @@
adapters,
algorithms,
test_utils,
console,
)
38 changes: 38 additions & 0 deletions opentimelineio/console/__init__.py
@@ -0,0 +1,38 @@
#
# Copyright 2018 Pixar Animation Studios
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

"""Console scripts for OpenTimelineIO
.. moduleauthor:: Pixar Animation Studios <opentimelineio@pixar.com>
"""

# flake8: noqa

# in dependency hierarchy
from . import (
otioconvert,
otiocat,
otiostat,
)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 6 additions & 10 deletions setup.py
Expand Up @@ -162,9 +162,10 @@ def test_otio():
'opentimelineio.core',
'opentimelineio.schema',
'opentimelineio.plugins',
'opentimelineio.console',
'opentimelineio_contrib',
'opentimelineio_contrib.adapters',
'opentimelineview'
'opentimelineview',
],

package_data={
Expand All @@ -176,20 +177,15 @@ def test_otio():
]
},

scripts=[
'bin/otiocat.py',
'bin/otioconvert.py',
'bin/otioview.py'
],

install_requires=[
# PyAAF2 to go here eventually
],
entry_points={
'console_scripts': [
'otioview = bin.otioview:main',
'otiocat = bin.otiocat:main',
'otioconvert = bin.otioconvert:main',
'otioview = opentimelineview.console:main',
'otiocat = opentimelineio.console.otiocat:main',
'otioconvert = opentimelineio.console.otioconvert:main',
'otiostat = opentimelineio.console.otiostat:main',
],
},
extras_require={
Expand Down
90 changes: 90 additions & 0 deletions tests/test_console.py
@@ -0,0 +1,90 @@
#
# Copyright 2017 Pixar Animation Studios
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

"""Unit tests for the 'console' module."""

import unittest
import sys
import os
import tempfile

try:
# python2
import StringIO as io
except ImportError:
# python3
import io

import opentimelineio as otio

SAMPLE_DATA_DIR = os.path.join(os.path.dirname(__file__), "sample_data")
SCREENING_EXAMPLE_PATH = os.path.join(SAMPLE_DATA_DIR, "screening_example.edl")


class ConsoleTester(otio.test_utils.OTIOAssertions):
def setUp(self):
self.saved_args = sys.argv
self.old_stdout = sys.stdout
self.old_stderr = sys.stderr
sys.stdout = io.StringIO()
sys.stderr = io.StringIO()

def tearDown(self):
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
sys.argv = self.saved_args


class OTIOStatTest(ConsoleTester, unittest.TestCase):
def test_basic(self):
sys.argv = ['otiostat', SCREENING_EXAMPLE_PATH]
otio.console.otiostat.main()
self.assertIn("top level object: Timeline.1", sys.stdout.getvalue())


class OTIOCatTests(ConsoleTester, unittest.TestCase):
def test_basic(self):
sys.argv = ['otiocat', SCREENING_EXAMPLE_PATH]
otio.console.otiocat.main()
self.assertIn('"name": "Example_Screening.01",', sys.stdout.getvalue())


class OTIOConvertTests(unittest.TestCase):
def test_basic(self):
with tempfile.NamedTemporaryFile() as tf:
sys.argv = [
'otioconvert',
'-i', SCREENING_EXAMPLE_PATH,
'-o', tf.name,
'-O', 'otio_json'
]
otio.console.otioconvert.main()

# read results back in
with open(tf.name, 'r') as fi:
self.assertIn('"name": "Example_Screening.01",', fi.read())


if __name__ == '__main__':
unittest.main()

0 comments on commit f1e53e5

Please sign in to comment.