mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Reorganized trst sources
This commit is contained in:
38
tests/unittests/test_adr_entity.py
Normal file
38
tests/unittests/test_adr_entity.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import unittest
|
||||
|
||||
from ptulsconv.docparser.tag_compiler import Event
|
||||
from ptulsconv.docparser.adr_entity import ADRLine, make_entity
|
||||
from fractions import Fraction
|
||||
|
||||
|
||||
class TestADREntity(unittest.TestCase):
|
||||
def test_event2line(self):
|
||||
tags = {
|
||||
'Ver': '1.0',
|
||||
'Actor': "Bill",
|
||||
'CN': "1",
|
||||
'QN': 'J1001',
|
||||
'R': 'Noise',
|
||||
'EFF': 'EFF'
|
||||
}
|
||||
event = Event(clip_name='"This is a test." (sotto voce)',
|
||||
track_name="Justin",
|
||||
session_name="Test Project",
|
||||
tags=tags,
|
||||
start=Fraction(0, 1), finish=Fraction(1, 1))
|
||||
|
||||
line = make_entity(event)
|
||||
|
||||
self.assertIsInstance(line, ADRLine)
|
||||
self.assertEqual('Bill', line.actor_name)
|
||||
self.assertEqual('Justin', line.character_name)
|
||||
self.assertEqual('"This is a test." (sotto voce)', line.prompt)
|
||||
self.assertEqual('Noise', line.reason)
|
||||
self.assertEqual('J1001', line.cue_number)
|
||||
self.assertEqual(True, line.effort)
|
||||
self.assertEqual('Test Project', line.title)
|
||||
self.assertEqual('1.0', line.version)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
75
tests/unittests/test_broadcast_timecode.py
Normal file
75
tests/unittests/test_broadcast_timecode.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import unittest
|
||||
from ptulsconv import broadcast_timecode
|
||||
from fractions import Fraction
|
||||
|
||||
class TestBroadcastTimecode(unittest.TestCase):
|
||||
def test_basic_to_frame_count(self):
|
||||
r1 = "01:00:00:00"
|
||||
f1 = broadcast_timecode.smpte_to_frame_count(r1, 24, False)
|
||||
self.assertEqual(f1, 86_400)
|
||||
f2 = broadcast_timecode.smpte_to_frame_count(r1, 30)
|
||||
self.assertEqual(f2, 108_000)
|
||||
|
||||
r2 = "0:00:00:01"
|
||||
f3 = broadcast_timecode.smpte_to_frame_count(r2, 24)
|
||||
self.assertEqual(f3, 1)
|
||||
|
||||
def test_basic_to_string(self):
|
||||
c1 = 24
|
||||
s1 = broadcast_timecode.frame_count_to_smpte(c1, 24)
|
||||
self.assertEqual(s1, "00:00:01:00")
|
||||
s2 = broadcast_timecode.frame_count_to_smpte(c1, 30)
|
||||
self.assertEqual(s2, "00:00:00:24")
|
||||
c2 = 108_000
|
||||
s3 = broadcast_timecode.frame_count_to_smpte(c2, 30)
|
||||
self.assertEqual(s3, "01:00:00:00")
|
||||
c3 = 86401
|
||||
s4 = broadcast_timecode.frame_count_to_smpte(c3, 24)
|
||||
self.assertEqual(s4, "01:00:00:01")
|
||||
|
||||
def test_drop_frame_to_string(self):
|
||||
c1 = 108_000
|
||||
s1 = broadcast_timecode.frame_count_to_smpte(c1, 30, drop_frame=True)
|
||||
self.assertEqual(s1, "01:00:03;18")
|
||||
|
||||
def test_drop_frame_to_frame_count(self):
|
||||
r1 = "01:00:00;00"
|
||||
z1 = broadcast_timecode.smpte_to_frame_count(r1, 30, drop_frame_hint=True)
|
||||
self.assertEqual(z1, 107_892)
|
||||
|
||||
r11 = "01:00:00;01"
|
||||
f11 = broadcast_timecode.smpte_to_frame_count(r11, 30)
|
||||
self.assertEqual(f11, 107_893)
|
||||
|
||||
r2 = "00:01:00;02"
|
||||
f2 = broadcast_timecode.smpte_to_frame_count(r2, 30, True)
|
||||
self.assertEqual(f2, 1800)
|
||||
|
||||
r3 = "00:00:59;29"
|
||||
f3 = broadcast_timecode.smpte_to_frame_count(r3, 30, True)
|
||||
self.assertEqual(f3, 1799)
|
||||
|
||||
def test_footage_to_frame_count(self):
|
||||
s1 = "194+11"
|
||||
f1 = broadcast_timecode.footage_to_frame_count(s1)
|
||||
self.assertEqual(f1, 3115)
|
||||
|
||||
s3 = "0+0.1"
|
||||
f3 = broadcast_timecode.footage_to_frame_count(s3)
|
||||
self.assertEqual(f3, 0)
|
||||
|
||||
def test_frame_count_to_footage(self):
|
||||
c1 = 19
|
||||
s1 = broadcast_timecode.frame_count_to_footage(c1)
|
||||
self.assertEqual(s1, "1+03")
|
||||
|
||||
def test_seconds_to_smpte(self):
|
||||
secs = Fraction(25, 24)
|
||||
frame_duration = Fraction(1, 24)
|
||||
tc_format = broadcast_timecode.TimecodeFormat(frame_duration=frame_duration, logical_fps=24, drop_frame=False)
|
||||
s1 = tc_format.seconds_to_smpte(secs)
|
||||
self.assertEqual(s1, "00:00:01:01")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
24
tests/unittests/test_doc_entities.py
Normal file
24
tests/unittests/test_doc_entities.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import unittest
|
||||
from ptulsconv.docparser.doc_entity import HeaderDescriptor
|
||||
from fractions import Fraction
|
||||
|
||||
|
||||
class DocParserTestCase(unittest.TestCase):
|
||||
|
||||
def test_header(self):
|
||||
header = HeaderDescriptor(session_name="Test Session",
|
||||
sample_rate=48000.0,
|
||||
bit_depth=24,
|
||||
start_timecode="00:59:52:00",
|
||||
timecode_format="30",
|
||||
timecode_drop_frame=False,
|
||||
count_audio_tracks=0,
|
||||
count_clips=0,
|
||||
count_files=0)
|
||||
|
||||
self.assertEqual(header.session_name, "Test Session")
|
||||
self.assertEqual(header.start_time, Fraction((59 * 60 + 52) * 30, 30))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
124
tests/unittests/test_tag_compiler.py
Normal file
124
tests/unittests/test_tag_compiler.py
Normal file
@@ -0,0 +1,124 @@
|
||||
import unittest
|
||||
|
||||
import ptulsconv.docparser.tag_compiler
|
||||
from ptulsconv.docparser import doc_entity
|
||||
from fractions import Fraction
|
||||
|
||||
|
||||
class TestTagCompiler(unittest.TestCase):
|
||||
|
||||
def test_one_track(self):
|
||||
c = ptulsconv.docparser.tag_compiler.TagCompiler()
|
||||
|
||||
test_session = self.make_test_session()
|
||||
|
||||
c.session = test_session
|
||||
|
||||
events = c.compile_events()
|
||||
event1 = next(events)
|
||||
self.assertEqual('This is clip 1', event1.clip_name)
|
||||
self.assertEqual('Track 1', event1.track_name)
|
||||
self.assertEqual('Test Session', event1.session_name)
|
||||
self.assertEqual(dict(A='A',
|
||||
Color='Blue',
|
||||
Ver='1.1',
|
||||
Mode='2',
|
||||
Comment='This is some text in the comments',
|
||||
Part='1'), event1.tags)
|
||||
self.assertEqual(Fraction(3600, 1), event1.start)
|
||||
|
||||
event2 = next(events)
|
||||
self.assertEqual("This is the second clip ...and this is the last clip", event2.clip_name)
|
||||
self.assertEqual('Track 1', event2.track_name)
|
||||
self.assertEqual('Test Session', event2.session_name)
|
||||
self.assertEqual(dict(R='Noise', A='A', B='B',
|
||||
Color='Red',
|
||||
Comment='This is some text in the comments',
|
||||
N='1', Mode='2',
|
||||
Ver='1.1',
|
||||
M1='M1',
|
||||
Part='2'), event2.tags)
|
||||
|
||||
self.assertEqual(c.session.header.convert_timecode('01:00:01:10'), event2.start)
|
||||
self.assertEqual(c.session.header.convert_timecode('01:00:03:00'), event2.finish)
|
||||
|
||||
self.assertIsNone(next(events, None))
|
||||
|
||||
def test_tag_list(self):
|
||||
session = self.make_test_session()
|
||||
c = ptulsconv.docparser.tag_compiler.TagCompiler()
|
||||
c.session = session
|
||||
|
||||
all_tags = c.compile_tag_list()
|
||||
|
||||
self.assertTrue(all_tags['Mode'] == {'2', '1'})
|
||||
|
||||
@staticmethod
|
||||
def make_test_session():
|
||||
test_header = doc_entity.HeaderDescriptor(session_name="Test Session $Ver=1.1",
|
||||
sample_rate=48000,
|
||||
timecode_format="24",
|
||||
timecode_drop_frame=False,
|
||||
bit_depth=24,
|
||||
start_timecode='00:59:00:00',
|
||||
count_audio_tracks=1,
|
||||
count_clips=3,
|
||||
count_files=0
|
||||
)
|
||||
test_clips = [
|
||||
doc_entity.TrackClipDescriptor(channel=1, event=1,
|
||||
clip_name='This is clip 1 {Color=Blue} $Mode=2',
|
||||
start_time='01:00:00:00',
|
||||
finish_time='01:00:01:03',
|
||||
duration='00:00:01:03',
|
||||
state='Unmuted',
|
||||
timestamp=None),
|
||||
doc_entity.TrackClipDescriptor(channel=1, event=2,
|
||||
clip_name='This is the second clip {R=Noise} [B] $Mode=2',
|
||||
start_time='01:00:01:10',
|
||||
finish_time='01:00:02:00',
|
||||
duration='00:00:00:14',
|
||||
state='Unmuted',
|
||||
timestamp=None),
|
||||
doc_entity.TrackClipDescriptor(channel=1, event=3,
|
||||
clip_name='& ...and this is the last clip $N=1 $Mode=2',
|
||||
start_time='01:00:02:00',
|
||||
finish_time='01:00:03:00',
|
||||
duration='00:00:01:00',
|
||||
state='Unmuted',
|
||||
timestamp=None),
|
||||
]
|
||||
test_track = doc_entity.TrackDescriptor(name="Track 1 [A] {Color=Red} $Mode=1",
|
||||
comments="{Comment=This is some text in the comments}",
|
||||
user_delay_samples=0,
|
||||
plugins=[],
|
||||
state=[],
|
||||
clips=test_clips)
|
||||
|
||||
markers = [doc_entity.MarkerDescriptor(number=1,
|
||||
location="01:00:00:00",
|
||||
time_reference=48000 * 60,
|
||||
units="Samples",
|
||||
name="Marker 1 {Part=1}",
|
||||
comments=""
|
||||
),
|
||||
doc_entity.MarkerDescriptor(number=2,
|
||||
location="01:00:01:00",
|
||||
time_reference=48000 * 61,
|
||||
units="Samples",
|
||||
name="Marker 2 {Part=2}",
|
||||
comments="[M1]"
|
||||
),
|
||||
]
|
||||
|
||||
test_session = doc_entity.SessionDescriptor(header=test_header,
|
||||
tracks=[test_track],
|
||||
clips=[],
|
||||
files=[],
|
||||
markers=markers,
|
||||
plugins=[])
|
||||
return test_session
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
39
tests/unittests/test_tag_interpreter.py
Normal file
39
tests/unittests/test_tag_interpreter.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import unittest
|
||||
|
||||
from ptulsconv.docparser.tagged_string_parser_visitor import parse_tags, TagPreModes
|
||||
|
||||
|
||||
class TestTagInterpreter(unittest.TestCase):
|
||||
def test_line(self):
|
||||
s1 = parse_tags("this is a test")
|
||||
self.assertEqual(s1.content, "this is a test")
|
||||
self.assertEqual(s1.mode, TagPreModes.NORMAL)
|
||||
self.assertEqual(len(s1.tag_dict), 0)
|
||||
|
||||
s2 = parse_tags("this! IS! Me! ** Typing! 123 <> |||")
|
||||
self.assertEqual(s2.content, "this! IS! Me! ** Typing! 123 <> |||")
|
||||
self.assertEqual(s2.mode, TagPreModes.NORMAL)
|
||||
self.assertEqual(len(s2.tag_dict), 0)
|
||||
|
||||
def test_tags(self):
|
||||
s1 = parse_tags("{a=100}")
|
||||
self.assertEqual(s1.tag_dict['a'], "100")
|
||||
|
||||
s2 = parse_tags("{b=This is a test} [option] $X=9")
|
||||
self.assertEqual(s2.tag_dict['b'], 'This is a test')
|
||||
self.assertEqual(s2.tag_dict['option'], 'option')
|
||||
self.assertEqual(s2.tag_dict['X'], "9")
|
||||
|
||||
def test_modes(self):
|
||||
s1 = parse_tags("@ Monday Tuesday {a=1}")
|
||||
self.assertEqual(s1.mode, TagPreModes.TIMESPAN)
|
||||
|
||||
s2 = parse_tags("Monday Tuesday {a=1}")
|
||||
self.assertEqual(s2.mode, TagPreModes.NORMAL)
|
||||
|
||||
s3 = parse_tags("&Monday Tuesday {a=1}")
|
||||
self.assertEqual(s3.mode, TagPreModes.APPEND)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
70
tests/unittests/test_tagging.py
Normal file
70
tests/unittests/test_tagging.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import unittest
|
||||
from ptulsconv.docparser import doc_entity, doc_parser_visitor, ptuls_grammar, tag_compiler
|
||||
import os.path
|
||||
|
||||
|
||||
class TaggingIntegratedTests(unittest.TestCase):
|
||||
path = os.path.dirname(__file__) + '/../export_cases/Tag Tests/Tag Tests.txt'
|
||||
|
||||
def test_event_list(self):
|
||||
with open(self.path, 'r') as f:
|
||||
document_ast = ptuls_grammar.protools_text_export_grammar.parse(f.read())
|
||||
document: doc_entity.SessionDescriptor = doc_parser_visitor.DocParserVisitor().visit(document_ast)
|
||||
compiler = tag_compiler.TagCompiler()
|
||||
compiler.session = document
|
||||
|
||||
events = list(compiler.compile_events())
|
||||
|
||||
self.assertEqual(9, len(events))
|
||||
self.assertEqual("Clip Name", events[0].clip_name)
|
||||
self.assertEqual("Lorem ipsum", events[1].clip_name)
|
||||
self.assertEqual("Dolor sic amet the rain in spain", events[2].clip_name)
|
||||
self.assertEqual("A B C", events[3].clip_name)
|
||||
self.assertEqual("Silver Bridge", events[4].clip_name)
|
||||
self.assertEqual("Region 02", events[5].clip_name)
|
||||
self.assertEqual("Region 12", events[6].clip_name)
|
||||
self.assertEqual("Region 22", events[7].clip_name)
|
||||
self.assertEqual("Region 04", events[8].clip_name)
|
||||
|
||||
def test_append(self):
|
||||
with open(self.path, 'r') as f:
|
||||
document_ast = ptuls_grammar.protools_text_export_grammar.parse(f.read())
|
||||
document: doc_entity.SessionDescriptor = doc_parser_visitor.DocParserVisitor().visit(document_ast)
|
||||
compiler = tag_compiler.TagCompiler()
|
||||
compiler.session = document
|
||||
|
||||
events = list(compiler.compile_events())
|
||||
|
||||
self.assertTrue(len(events) > 2)
|
||||
|
||||
self.assertEqual("Dolor sic amet the rain in spain", events[2].clip_name)
|
||||
|
||||
self.assertEqual(document.header.convert_timecode("01:00:10:00"), events[2].start)
|
||||
self.assertEqual(document.header.convert_timecode("01:00:25:00"), events[2].finish)
|
||||
|
||||
self.assertIn('X', events[2].tags.keys())
|
||||
self.assertIn('ABC', events[2].tags.keys())
|
||||
self.assertIn('A', events[2].tags.keys())
|
||||
self.assertEqual('302', events[2].tags['X'])
|
||||
self.assertEqual('ABC', events[2].tags['ABC'])
|
||||
self.assertEqual('1', events[2].tags['A'])
|
||||
|
||||
def test_successive_appends(self):
|
||||
with open(self.path, 'r') as f:
|
||||
document_ast = ptuls_grammar.protools_text_export_grammar.parse(f.read())
|
||||
document: doc_entity.SessionDescriptor = doc_parser_visitor.DocParserVisitor().visit(document_ast)
|
||||
compiler = tag_compiler.TagCompiler()
|
||||
compiler.session = document
|
||||
|
||||
events = list(compiler.compile_events())
|
||||
|
||||
self.assertTrue(len(events) > 3)
|
||||
|
||||
self.assertEqual("A B C", events[3].clip_name)
|
||||
|
||||
self.assertEqual(document.header.convert_timecode("01:00:15:00"), events[3].start)
|
||||
self.assertEqual(document.header.convert_timecode("01:00:45:00"), events[3].finish)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
20
tests/unittests/test_utils.py
Normal file
20
tests/unittests/test_utils.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import unittest
|
||||
|
||||
from ptulsconv.docparser.tag_compiler import apply_appends
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_something(self):
|
||||
v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
expected = [1, 2, 7, 5, 6, 15, 9, 10]
|
||||
|
||||
should = (lambda x, y: y % 4 == 0)
|
||||
do_combine = (lambda x, y: x + y)
|
||||
|
||||
r = apply_appends(iter(v), should, do_combine)
|
||||
r1 = list(r)
|
||||
self.assertEqual(r1, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user