Updated unit tests

This commit is contained in:
Jamie Hardt
2021-06-02 11:06:18 -07:00
parent 8d4058d026
commit 24c5a87358
10 changed files with 165 additions and 206 deletions

View File

@@ -1,25 +1 @@
from typing import Generator, Callable, Iterator
from enum import Enum
def apply_appends(source: Iterator,
should_append: Callable,
do_append: Callable) -> Generator:
"""
:param source:
:param should_append: Called with two variables a and b, your
function should return true if b should be
appended to a
:param do_append: Called with two variables a and b, your function
should return
:returns: A Generator
"""
this_element = next(source)
for element in source:
if should_append(this_element, element):
this_element = do_append(this_element, element)
else:
yield this_element
this_element = element
yield this_element
from .doc_parser_visitor import parse_document

View File

@@ -1,9 +1,6 @@
from fractions import Fraction
from ptulsconv.broadcast_timecode import smpte_to_frame_count
from typing import Tuple, List, Iterator
from collections import namedtuple
from . import apply_appends
from .tagged_string_parser_visitor import parse_tags
class SessionDescriptor:

View File

@@ -4,6 +4,18 @@ from .doc_entity import SessionDescriptor, HeaderDescriptor, TrackDescriptor, Fi
TrackClipDescriptor, ClipDescriptor, PluginDescriptor, MarkerDescriptor
def parse_document(path: str) -> SessionDescriptor:
"""
Parse a Pro Tools text export.
:param path: path to a file
:return: the session descriptor
"""
from .ptuls_grammar import protools_text_export_grammar
with open(path, 'r') as f:
ast = protools_text_export_grammar.parse(f.read())
return DocParserVisitor().visit(ast)
class DocParserVisitor(NodeVisitor):
@staticmethod

View File

@@ -1,10 +1,9 @@
from collections import namedtuple
from fractions import Fraction
from typing import Iterator, Tuple
from typing import Iterator, Tuple, Callable, Generator
from ptulsconv.docparser import apply_appends
from ptulsconv.docparser.doc_entity import SessionDescriptor
from ptulsconv.docparser.tagged_string_parser_visitor import parse_tags, TagPreModes
import ptulsconv.docparser.doc_entity as doc_entity
from .tagged_string_parser_visitor import parse_tags, TagPreModes
class Event(namedtuple('Event', 'clip_name track_name session_name tags start finish')):
@@ -12,7 +11,7 @@ class Event(namedtuple('Event', 'clip_name track_name session_name tags start fi
class TagCompiler:
session: SessionDescriptor
session: doc_entity.SessionDescriptor
def compile_events(self) -> Iterator[Event]:
step0 = self.parse_data()
@@ -121,3 +120,25 @@ class TagCompiler:
yield event.clip_content, event.track_content, session_parsed.content, tags, event.start, event.finish
def apply_appends(source: Iterator,
should_append: Callable,
do_append: Callable) -> Generator:
"""
:param source:
:param should_append: Called with two variables a and b, your
function should return true if b should be
appended to a
:param do_append: Called with two variables a and b, your function
should return
:returns: A Generator
"""
this_element = next(source)
for element in source:
if should_append(this_element, element):
this_element = do_append(this_element, element)
else:
yield this_element
this_element = element
yield this_element