Ruffification and fixed bug

This commit is contained in:
2026-09-17 10:19:11 -07:00
parent 13d9cd4914
commit e6320e84c6
25 changed files with 787 additions and 659 deletions
+1 -3
View File
@@ -19,7 +19,7 @@ from contextlib import contextmanager
# @property
# def arch_path(self):
# return os.path.join(self.base_path, self.test_file_arch_name)
# return os.path.join(self.base_path, self.test_file_arch_name)
# @contextmanager
# def open(self, name) -> Generator[BytesIO]:
@@ -40,5 +40,3 @@ from contextlib import contextmanager
# p = os.path.join(root, name)
# zip.write(p)
# os.unlink(p)
+4 -5
View File
@@ -2,8 +2,8 @@ from unittest import TestCase
import wavinfo
class TestADMWave(TestCase):
class TestADMWave(TestCase):
def setUp(self) -> None:
self.protools_adm_wav = "tests/test_files/protools/Test_ADM_ProTools.wav"
return super().setUp()
@@ -24,7 +24,7 @@ class TestADMWave(TestCase):
assert adm is not None
dict = adm.to_dict()
self.assertIsNotNone(dict)
def test_programme(self):
info = wavinfo.WavInfoReader(self.protools_adm_wav)
adm = info.adm
@@ -32,8 +32,8 @@ class TestADMWave(TestCase):
pdict = adm.programme()
self.assertIn("programme_id", pdict.keys())
self.assertIn("programme_name", pdict.keys())
self.assertEqual(pdict['programme_id'], 'APR_1001')
self.assertEqual(pdict['programme_name'], 'Atmos_Master')
self.assertEqual(pdict["programme_id"], "APR_1001")
self.assertEqual(pdict["programme_name"], "Atmos_Master")
self.assertIn("contents", pdict.keys())
self.assertEqual(len(pdict["contents"]), 3)
@@ -51,4 +51,3 @@ class TestADMWave(TestCase):
t10 = adm.track_info(10)
self.assertTrue("content_name" in t10.keys())
self.assertEqual("Dialog", t10["content_name"])
+14 -15
View File
@@ -3,9 +3,10 @@ from glob import glob
import wavinfo
class TestCue(TestCase):
def setUp(self) -> None:
self.test_files = glob("tests/test_files/cue_chunks/*.wav")
self.test_files = glob("tests/test_files/cue_chunks/*.wav")
return super().setUp()
def test_enumerate(self):
@@ -14,7 +15,7 @@ class TestCue(TestCase):
self.assertIsNotNone(w1.cues)
assert w1.cues is not None
vals = list(w1.cues.each_cue())
self.assertEqual(vals, [(1,29616),(2,74592),(3,121200)])
self.assertEqual(vals, [(1, 29616), (2, 74592), (3, 121200)])
def test_labels_notes(self):
file = "tests/test_files/cue_chunks/izotoperx_cues_test.wav"
@@ -23,7 +24,7 @@ class TestCue(TestCase):
assert w1.cues is not None
for name, _ in w1.cues.each_cue():
self.assertIn(name,[1,2,3])
self.assertIn(name, [1, 2, 3])
label, note = w1.cues.label_and_note(name)
if name == 1:
self.assertEqual("Marker 1", label)
@@ -35,18 +36,20 @@ class TestCue(TestCase):
self.assertIsNotNone(w1.cues)
assert w1.cues is not None
self.assertEqual(w1.cues.range(3), 10000)
self.assertEqual(w1.cues.range(3), 10000)
def test_encoding_fallback(self):
"""
Added this after I noticed that iZotope RX seems to just encode "notes"
as utf-8 without bothering to dump this info into the ltxt or
as utf-8 without bothering to dump this info into the ltxt or
specifying an encoding by some other means.
"""
file = "tests/test_files/cue_chunks/izotoperx_cues_test.wav"
w = wavinfo.WavInfoReader(file, info_encoding='utf-8')
expected = ("Лорем ипсум долор сит амет, тимеам вивендум хас ет, "
"цу адолесценс дефинитионес еам.")
w = wavinfo.WavInfoReader(file, info_encoding="utf-8")
expected = (
"Лорем ипсум долор сит амет, тимеам вивендум хас ет, "
"цу адолесценс дефинитионес еам."
)
assert w.cues is not None
note = [n for n in w.cues.notes if n.name == 3]
@@ -56,20 +59,16 @@ class TestCue(TestCase):
def test_label(self):
file = "tests/test_files/cue_chunks/izotoperx_cues_test.wav"
w = wavinfo.WavInfoReader(file)
self.assertIsNotNone(w.cues)
assert w.cues is not None
assert w.cues is not None
self.assertEqual(len(w.cues.labels), 3)
for label in w.cues.labels:
self.assertIn(label.name, [1,2,3])
self.assertIn(label.name, [1, 2, 3])
if label.name == 1:
self.assertEqual(label.text, "Marker 1")
elif label.name == 2:
self.assertEqual(label.text, "Marker 2")
elif label.name == 3:
self.assertEqual(label.text, "Marker 3")
+19 -18
View File
@@ -3,6 +3,7 @@ from unittest import TestCase
import wavinfo
from wavinfo.wave_dbmd_reader import SegmentType, DolbyDigitalPlusMetadata
class TestDolby(TestCase):
def setUp(self):
self.test_file = "tests/test_files/protools/Test_ADM_ProTools.wav"
@@ -10,19 +11,17 @@ class TestDolby(TestCase):
def test_version(self):
t1 = wavinfo.WavInfoReader(self.test_file)
d = t1.dolby
assert d is not None
self.assertEqual((1,0,0,6), d.version)
self.assertEqual((1, 0, 0, 6), d.version)
def test_segments(self):
t1 = wavinfo.WavInfoReader(self.test_file)
d = t1.dolby
assert d is not None
ddp = [x for x in d.segment_list \
if x[0] == SegmentType.DolbyDigitalPlus]
atmos = [x for x in d.segment_list \
if x[0] == SegmentType.DolbyAtmos]
ddp = [x for x in d.segment_list if x[0] == SegmentType.DolbyDigitalPlus]
atmos = [x for x in d.segment_list if x[0] == SegmentType.DolbyAtmos]
self.assertEqual(len(ddp), 1)
self.assertEqual(len(atmos), 1)
@@ -40,21 +39,23 @@ class TestDolby(TestCase):
d = t1.dolby
assert d is not None
ddp = d.dolby_digital_plus()
self.assertEqual(len(ddp), 1,
("Failed to find exactly one Dolby Digital Plus "
"metadata segment")
)
self.assertEqual(
len(ddp),
1,
("Failed to find exactly one Dolby Digital Plus metadata segment"),
)
self.assertTrue(
ddp[0].audio_coding_mode,
DolbyDigitalPlusMetadata.AudioCodingMode.CH_ORD_3_2,
)
self.assertTrue(ddp[0].lfe_on)
self.assertTrue( ddp[0].audio_coding_mode,
DolbyDigitalPlusMetadata.AudioCodingMode.CH_ORD_3_2 )
self.assertTrue( ddp[0].lfe_on)
def test_atmos(self):
t1 = wavinfo.WavInfoReader(self.test_file)
d = t1.dolby
assert d is not None
atmos = d.dolby_atmos()
self.assertEqual(len(atmos), 1,
"Failed to find exactly one Atmos metadata segment")
self.assertEqual(
len(atmos), 1, "Failed to find exactly one Atmos metadata segment"
)
+9 -9
View File
@@ -7,10 +7,10 @@ from wavinfo.__main__ import main
import sys
import glob
class MainTest(unittest.TestCase):
def test_empty_argv(self):
with patch.object(sys, 'argv', []):
def test_empty_argv(self):
with patch.object(sys, "argv", []):
try:
main()
except:
@@ -18,17 +18,17 @@ class MainTest(unittest.TestCase):
def test_a_file(self):
for path in glob.glob("tests/test_files/**/*.wav"):
with patch.object(sys, 'argv', ["TEST", path]):
with patch.object(sys, "argv", ["TEST", path]):
try:
main()
except:
self.fail("main() throwing an exception")
self.fail("main() throwing an exception")
def test_ixml(self):
with patch.object(sys, 'argv',
['TEST', '--ixml',
'tests/test_files/sounddevices/A101_1.WAV']):
with patch.object(
sys, "argv", ["TEST", "--ixml", "tests/test_files/sounddevices/A101_1.WAV"]
):
try:
main()
except:
self.fail("main() throwing an exception")
self.fail("main() throwing an exception")
+1 -3
View File
@@ -9,17 +9,15 @@ from unittest import TestCase
import wavinfo
class TestRf64(TestCase):
class TestRf64(TestCase):
def setUp(self) -> None:
return super().setUp()
def test_open(self):
for path in glob("tests/test_files/rf64/*.wav.gz"):
gz = gzip.open(path)
wav_info = wavinfo.WavInfoReader(gz)
self.assertIsNotNone(wav_info)
# self.assertIsNotNone(wav_info.bext)
+1
View File
@@ -3,6 +3,7 @@ from glob import glob
import wavinfo
class TestSmpl(TestCase):
def setUp(self) -> None:
self.test_files = glob("tests/test_files/smpl/*.wav")
+11 -11
View File
@@ -3,35 +3,35 @@ import wavinfo
import glob
class TestWalk(unittest.TestCase):
def test_walk_metadata(self):
test_file = 'tests/test_files/protools/PT A101_4.A1.wav'
test_file = "tests/test_files/protools/PT A101_4.A1.wav"
info = wavinfo.WavInfoReader(test_file)
tested_data , tested_format = False, False
tested_data, tested_format = False, False
for scope, key, value in info.walk():
if scope == 'fmt':
if key == 'channel_count':
if scope == "fmt":
if key == "channel_count":
tested_format = True
self.assertEqual(value, 2)
if scope == 'data':
if key == 'frame_count':
if scope == "data":
if key == "frame_count":
tested_data = True
self.assertEqual(value, 144140)
self.assertTrue(tested_data and tested_format)
def test_walk_all(self):
for file in glob.glob('tests/test_files/**/*.wav'):
for file in glob.glob("tests/test_files/**/*.wav"):
info = wavinfo.WavInfoReader(file)
try:
for _, _, _ in info.walk():
pass
pass
except:
self.fail(f"Failed to walk metadata in file {file}")
if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
+113 -92
View File
@@ -13,9 +13,10 @@ class TestWaveInfo(TestCase):
def test_sanity(self):
for wav_file in all_files():
info = wavinfo.WavInfoReader(wav_file)
self.assertEqual(info.__repr__(),
'WavInfoReader({}, latin_1, ascii)'
.format(os.path.abspath(wav_file)))
self.assertEqual(
info.__repr__(),
"WavInfoReader({}, latin_1, ascii)".format(os.path.abspath(wav_file)),
)
self.assertIsNotNone(info)
def test_fmt_against_ffprobe(self):
@@ -26,31 +27,39 @@ class TestWaveInfo(TestCase):
assert info.fmt is not None
assert ffprobe_info is not None
self.assertEqual(info.fmt.channel_count,
ffprobe_info['streams'][0]['channels'])
self.assertEqual(info.fmt.sample_rate,
int(ffprobe_info['streams'][0]['sample_rate']))
self.assertEqual(info.fmt.bits_per_sample,
int(ffprobe_info['streams'][0]['bits_per_sample']
))
self.assertEqual(
info.fmt.channel_count, ffprobe_info["streams"][0]["channels"]
)
self.assertEqual(
info.fmt.sample_rate, int(ffprobe_info["streams"][0]["sample_rate"])
)
self.assertEqual(
info.fmt.bits_per_sample,
int(ffprobe_info["streams"][0]["bits_per_sample"]),
)
if info.fmt.audio_format == 1:
self.assertTrue(ffprobe_info['streams'][0]['codec_name']\
.startswith('pcm'))
streams = ffprobe_info['streams'][0]
byte_rate = int(streams['sample_rate']) * \
streams['channels'] * \
int(streams['bits_per_sample']) / 8
self.assertTrue(
ffprobe_info["streams"][0]["codec_name"].startswith("pcm")
)
streams = ffprobe_info["streams"][0]
byte_rate = (
int(streams["sample_rate"])
* streams["channels"]
* int(streams["bits_per_sample"])
/ 8
)
self.assertEqual(info.fmt.byte_rate, byte_rate)
def test_data_against_ffprobe(self):
for wav_file in all_files():
info = wavinfo.WavInfoReader(wav_file)
ffprobe_info = cast(Dict[str,Any], ffprobe(wav_file))
ffprobe_info = cast(Dict[str, Any], ffprobe(wav_file))
assert ffprobe_info is not None
assert info.data is not None
self.assertEqual(info.data.frame_count,
int(ffprobe_info['streams'][0]['duration_ts']))
self.assertEqual(
info.data.frame_count, int(ffprobe_info["streams"][0]["duration_ts"])
)
def test_bext_against_ffprobe(self):
for wav_file in all_files():
@@ -59,65 +68,78 @@ class TestWaveInfo(TestCase):
assert ffprobe_info is not None
if info.bext:
if 'comment' in ffprobe_info['format']['tags']:
self.assertEqual(info.bext.description,
ffprobe_info['format']['tags']\
['comment'])
if "comment" in ffprobe_info["format"]["tags"]:
self.assertEqual(
info.bext.description, ffprobe_info["format"]["tags"]["comment"]
)
else:
self.assertEqual(info.bext.description, '')
self.assertEqual(info.bext.description, "")
if 'encoded_by' in ffprobe_info['format']['tags']:
self.assertEqual(info.bext.originator,
ffprobe_info['format']['tags']\
['encoded_by'])
if "encoded_by" in ffprobe_info["format"]["tags"]:
self.assertEqual(
info.bext.originator,
ffprobe_info["format"]["tags"]["encoded_by"],
)
else:
self.assertEqual(info.bext.originator, '')
self.assertEqual(info.bext.originator, "")
if 'originator_reference' in ffprobe_info['format']['tags']:
self.assertEqual(info.bext.originator_ref,
ffprobe_info['format']['tags']\
['originator_reference'])
if "originator_reference" in ffprobe_info["format"]["tags"]:
self.assertEqual(
info.bext.originator_ref,
ffprobe_info["format"]["tags"]["originator_reference"],
)
else:
self.assertEqual(info.bext.originator_ref, '')
self.assertEqual(info.bext.originator_ref, "")
# these don't always reflect the bext info
# self.assertEqual(info.bext.originator_date,
# self.assertEqual(info.bext.originator_date,
# ffprobe_info['format']['tags']['date'])
# self.assertEqual(info.bext.originator_time,
# self.assertEqual(info.bext.originator_time,
# ffprobe_info['format']['tags']['creation_time'])
self.assertEqual(info.bext.time_reference,
int(ffprobe_info['format']['tags']\
['time_reference']))
self.assertEqual(
info.bext.time_reference,
int(ffprobe_info["format"]["tags"]["time_reference"]),
)
if 'coding_history' in ffprobe_info['format']['tags']:
self.assertEqual(info.bext.coding_history,
ffprobe_info['format']['tags']\
['coding_history'])
if "coding_history" in ffprobe_info["format"]["tags"]:
self.assertEqual(
info.bext.coding_history,
ffprobe_info["format"]["tags"]["coding_history"],
)
else:
self.assertEqual(info.bext.coding_history, '')
self.assertEqual(info.bext.coding_history, "")
def test_ixml(self):
expected = {'A101_4.WAV': {'project': 'BMH',
'scene': 'A101', 'take': '4',
'tape': '18Y12M31',
'family_uid':
'USSDVGR1112089007124015008231000'},
'A101_3.WAV': {'project': 'BMH',
'scene': 'A101', 'take': '3',
'tape': '18Y12M31',
'family_uid':
'USSDVGR1112089007124014008228300'},
'A101_2.WAV': {'project': 'BMH',
'scene': 'A101', 'take': '2',
'tape': '18Y12M31',
'family_uid':
'USSDVGR1112089007124004008218600'},
'A101_1.WAV': {'project': 'BMH',
'scene': 'A101', 'take': '1',
'tape': '18Y12M31',
'family_uid':
'USSDVGR1112089007124001008206300'},
}
expected = {
"A101_4.WAV": {
"project": "BMH",
"scene": "A101",
"take": "4",
"tape": "18Y12M31",
"family_uid": "USSDVGR1112089007124015008231000",
},
"A101_3.WAV": {
"project": "BMH",
"scene": "A101",
"take": "3",
"tape": "18Y12M31",
"family_uid": "USSDVGR1112089007124014008228300",
},
"A101_2.WAV": {
"project": "BMH",
"scene": "A101",
"take": "2",
"tape": "18Y12M31",
"family_uid": "USSDVGR1112089007124004008218600",
},
"A101_1.WAV": {
"project": "BMH",
"scene": "A101",
"take": "1",
"tape": "18Y12M31",
"family_uid": "USSDVGR1112089007124001008206300",
},
}
for wav_file in all_files():
basename = os.path.basename(wav_file)
@@ -125,29 +147,31 @@ class TestWaveInfo(TestCase):
info = wavinfo.WavInfoReader(wav_file)
e = expected[basename]
self.assertIsNotNone(info.ixml)
assert info.ixml is not None
self.assertEqual(e['project'], info.ixml.project)
self.assertEqual(e['scene'], info.ixml.scene)
self.assertEqual(e['take'], info.ixml.take)
self.assertEqual(e['tape'], info.ixml.tape)
self.assertEqual(e['family_uid'], info.ixml.family_uid)
assert info.ixml is not None
self.assertEqual(e["project"], info.ixml.project)
self.assertEqual(e["scene"], info.ixml.scene)
self.assertEqual(e["take"], info.ixml.take)
self.assertEqual(e["tape"], info.ixml.tape)
self.assertEqual(e["family_uid"], info.ixml.family_uid)
for track in info.ixml.track_list:
self.assertIsNotNone(track.channel_index)
if basename == 'A101_4.WAV' and track.channel_index == '1':
self.assertEqual(track.name, 'MKH516 A')
if basename == "A101_4.WAV" and track.channel_index == "1":
self.assertEqual(track.name, "MKH516 A")
def test_steinberg_ixml(self):
nuendo_files = 'tests/test_files/nuendo/*.wav'
nuendo_files = "tests/test_files/nuendo/*.wav"
for file in glob(nuendo_files):
info = wavinfo.WavInfoReader(file)
assert info.ixml is not None
assert info.ixml is not None
self.assertIsNotNone(info.ixml.steinberg)
assert info.ixml.steinberg is not None
self.assertIsNotNone(info.ixml.steinberg.audio_speaker_arrangement)
self.assertEqual(info.ixml.steinberg.sample_format_size, 3)
self.assertEqual(info.ixml.steinberg.media_company,
"https://github.com/iluvcapra/wavinfo")
self.assertEqual(info.ixml.steinberg.sample_format_size, 3)
self.assertEqual(
info.ixml.steinberg.media_company,
"https://github.com/iluvcapra/wavinfo",
)
self.assertFalse(info.ixml.steinberg.media_drop_frames)
self.assertEqual(info.ixml.steinberg.media_duration, 1200.0)
@@ -159,24 +183,21 @@ class TestWaveInfo(TestCase):
self.assertIsNone(info.ixml.steinberg)
def test_info_metadata(self):
file_with_metadata = \
'tests/test_files/sound_grinder_pro/new_camera bumb 1.wav'
file_with_metadata = "tests/test_files/sound_grinder_pro/new_camera bumb 1.wav"
self.assertTrue(os.path.exists(file_with_metadata))
info = wavinfo.WavInfoReader(file_with_metadata).info
assert info is not None
self.assertEqual(info.title, 'camera bumb 1')
self.assertEqual(info.artist, 'Jamie Hardt')
self.assertEqual(info.copyright, '© 2010 Jamie Hardt')
self.assertEqual(info.product, 'Test Sounds') # album
self.assertEqual(info.title, "camera bumb 1")
self.assertEqual(info.artist, "Jamie Hardt")
self.assertEqual(info.copyright, "© 2010 Jamie Hardt")
self.assertEqual(info.product, "Test Sounds") # album
self.assertEqual(info.album, info.product)
self.assertEqual(info.comment, 'Comments')
self.assertEqual(info.software, 'Sound Grinder Pro')
self.assertEqual(info.created_date, '2010-12-28')
self.assertEqual(info.engineer, 'JPH')
self.assertEqual(info.keywords,
'Sound Effect, movement, microphone, bump')
self.assertEqual(info.title, 'camera bumb 1')
self.assertEqual(info.comment, "Comments")
self.assertEqual(info.software, "Sound Grinder Pro")
self.assertEqual(info.created_date, "2010-12-28")
self.assertEqual(info.engineer, "JPH")
self.assertEqual(info.keywords, "Sound Effect, movement, microphone, bump")
self.assertEqual(info.title, "camera bumb 1")
self.assertEqual(type(info.to_dict()), dict)
self.assertEqual(type(info.__repr__()), str)
+9 -11
View File
@@ -4,35 +4,33 @@ import subprocess
from subprocess import PIPE
import json
FFPROBE = 'ffprobe'
FFPROBE = "ffprobe"
def ffprobe(path):
arguments = [FFPROBE, "-of", "json",
"-show_format", "-show_streams", path]
if int(sys.version[0]) < 3:
arguments = [FFPROBE, "-of", "json", "-show_format", "-show_streams", path]
if int(sys.version[0]) < 3:
process = subprocess.Popen(arguments, stdout=PIPE)
process.wait()
if process.returncode == 0:
output = process.communicate()[0]
if output:
output_str = output.decode('utf-8')
output_str = output.decode("utf-8")
return json.loads(output_str)
else:
return None
else:
process = subprocess.run(arguments, stdin=None,
stdout=PIPE, stderr=PIPE)
else:
process = subprocess.run(arguments, stdin=None, stdout=PIPE, stderr=PIPE)
if process.returncode == 0:
output_str = process.stdout.decode('utf-8')
output_str = process.stdout.decode("utf-8")
return json.loads(output_str)
else:
return None
def all_files():
for dirpath, _, filenames in os.walk('tests/test_files'):
for dirpath, _, filenames in os.walk("tests/test_files"):
for filename in filenames:
_, ext = os.path.splitext(filename)
if ext in ['.wav', '.WAV']:
if ext in [".wav", ".WAV"]:
yield os.path.join(dirpath, filename)