Merge pull request #23 from iluvcapra/maint-rm-umid

Removed UMID parsing for now, to improve test coverage
This commit is contained in:
Jamie Hardt
2023-11-08 08:04:01 -08:00
committed by GitHub
3 changed files with 53 additions and 19 deletions

33
tests/test_main.py Normal file
View File

@@ -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")

View File

@@ -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:
@@ -22,8 +22,8 @@ class UMIDParser:
# 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:

View File

@@ -1,5 +1,5 @@
import struct
from .umid_parser import UMIDParser
# from .umid_parser import UMIDParser
from typing import Optional
@@ -80,10 +80,11 @@ class WavBextReader:
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:
# 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,