Skip to content

Commit

Permalink
Merge pull request #23 from iluvcapra/maint-rm-umid
Browse files Browse the repository at this point in the history
Removed UMID parsing for now, to improve test coverage
  • Loading branch information
iluvcapra committed Nov 8, 2023
2 parents af5b538 + 069666e commit 6654a19
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
33 changes: 33 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest

from unittest.mock import patch

from wavinfo.__main__ import main

import sys
import glob

class MainTest(unittest.TestCase):

def test_empty_argv(self):
with patch.object(sys, 'argv', []):
try:
main()
except:
self.fail("main() throwing an exception")

def test_a_file(self):
for path in glob.glob("tests/test_files/**/*.wav"):
with patch.object(sys, 'argv', ["TEST", path]):
try:
main()
except:
self.fail("main() throwing an exception")

def test_ixml(self):
with patch.object(sys, 'argv',
['TEST', '--ixml', 'tests/test_files/sounddevices/A101_1.WAV']):
try:
main()
except:
self.fail("main() throwing an exception")
26 changes: 13 additions & 13 deletions wavinfo/umid_parser.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from functools import reduce
# from functools import reduce


def binary_to_string(binary_value):
return reduce(lambda val, el: val + "{:02x}".format(el), binary_value, '')
# def binary_to_string(binary_value):
# return reduce(lambda val, el: val + "{:02x}".format(el), binary_value, '')


class UMIDParser:
"""
Parse a raw binary SMPTE 330M Universal Materials Identifier
This implementation is based on SMPTE ST 330:2011
"""
def __init__(self, raw_umid: bytes):
self.raw_umid = raw_umid
# class UMIDParser:
# """
# Parse a raw binary SMPTE 330M Universal Materials Identifier
#
# This implementation is based on SMPTE ST 330:2011
# """
# def __init__(self, raw_umid: bytes):
# self.raw_umid = raw_umid
#
# @property
# def universal_label(self) -> bytearray:
Expand All @@ -22,8 +22,8 @@ def __init__(self, raw_umid: bytes):
# def basic_umid(self):
# return self.raw_umid[0:32]

def basic_umid_to_str(self):
return binary_to_string(self.raw_umid[0:32])
# def basic_umid_to_str(self):
# return binary_to_string(self.raw_umid[0:32])
#
# @property
# def universal_label_is_valid(self) -> bool:
Expand Down
13 changes: 7 additions & 6 deletions wavinfo/wave_bext_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import struct
from .umid_parser import UMIDParser
# from .umid_parser import UMIDParser

from typing import Optional

Expand Down Expand Up @@ -80,11 +80,12 @@ def sanitize_bytes(b : bytes) -> str:
self.max_shortterm_loudness = unpacked[12] / 100.0

def to_dict(self):
if self.umid is not None:
umid_parsed = UMIDParser(self.umid)
umid_str = umid_parsed.basic_umid_to_str()
else:
umid_str = None
# if self.umid is not None:
# umid_parsed = UMIDParser(self.umid)
# umid_str = umid_parsed.basic_umid_to_str()
# else:

umid_str = None

return {'description': self.description,
'originator': self.originator,
Expand Down

0 comments on commit 6654a19

Please sign in to comment.