From f166277b69e07a942a70101a8d79032aac6be4d1 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 27 Apr 2019 09:35:10 -0700 Subject: Initial commit --- tests/test.py | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/test.py (limited to 'tests/test.py') diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..9cf45f7 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,191 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2019 James E. Blair +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import logging +import struct +import tempfile + +import testtools +import fixtures + +from editty.segment import * +from editty.program import * +import editty.source + +class BaseTestCase(testtools.TestCase): + def setUp(self): + super().setUp() + fs = '%(asctime)s %(levelname)s [%(name)s] %(message)s' + self.useFixture(fixtures.FakeLogger(level=logging.DEBUG, + format=fs)) + self.log = logging.getLogger("test") + +class FileTypeTests: + def get_frames(self, source): + ret = [] + for (timecode, frame) in source.getFrames(0, source.length): + ret.append((timecode, b''.join([x[2] for x in frame.content[0]]).strip())) + return ret + + def test_load(self): + source = self.setup() + self.assertEqual( + [(1.0, b'a'), (2.0, b'ab'), (3.0, b'abc'), (4.0, b'abcd')], + self.get_frames(source)) + +class TestScriptFile(BaseTestCase, FileTypeTests): + def setup(self): + size = (80, 24) + with tempfile.NamedTemporaryFile() as stream: + with tempfile.NamedTemporaryFile() as timing: + stream.write(b"\nabcd") + for x in range(4): + timing.write(b"1.0 1\n") + stream.flush() + timing.flush() + source = editty.source.ScriptFile().load( + size, stream.name, timing.name, 'color') + return source + +class TestTtyrecFile(BaseTestCase, FileTypeTests): + def setup(self): + size = (80, 24) + frames = [(1.0, b'a'), (2.0, b'b'), (3.0, b'c'), (4.0, b'd')] + with tempfile.NamedTemporaryFile() as stream: + for (timecode, data) in frames: + tc_secs, tc_usecs = map(int, ('%0.6f' % timecode).split('.')) + stream.write(struct.pack('