Add tests

This commit is contained in:
Elijah Lopez
2020-08-14 15:03:06 -04:00
parent 6d8e717f42
commit f8bf6cb4a0
4 changed files with 46 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
import unittest import unittest
import wavinfo import wavinfo
class TestWalk(unittest.TestCase): class TestWalk(unittest.TestCase):
def test_walk_metadata(self): 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'

View File

@@ -7,33 +7,34 @@ from .utils import all_files, ffprobe
import wavinfo import wavinfo
class TestWaveInfo(TestCase): class TestWaveInfo(TestCase):
def test_sanity(self): def test_sanity(self):
for wav_file in all_files(): for wav_file in all_files():
info = wavinfo.WavInfoReader(wav_file) info = wavinfo.WavInfoReader(wav_file)
self.assertTrue(info is not None) self.assertEqual(info.__repr__(), 'WavInfoReader(%s, %s, %s)'.format(wav_file, 'latin_1', 'ascii'))
self.assertIsNotNone(info)
def test_fmt_against_ffprobe(self): def test_fmt_against_ffprobe(self):
for wav_file in all_files(): for wav_file in all_files():
info = wavinfo.WavInfoReader(wav_file) info = wavinfo.WavInfoReader(wav_file)
ffprobe_info = ffprobe(wav_file) ffprobe_info = ffprobe(wav_file)
self.assertEqual( info.fmt.channel_count , ffprobe_info['streams'][0]['channels'] ) 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.sample_rate, int(ffprobe_info['streams'][0]['sample_rate']))
self.assertEqual( info.fmt.bits_per_sample, int(ffprobe_info['streams'][0]['bits_per_raw_sample']) ) self.assertEqual(info.fmt.bits_per_sample, int(ffprobe_info['streams'][0]['bits_per_raw_sample']))
if info.fmt.audio_format == 1: if info.fmt.audio_format == 1:
self.assertTrue(ffprobe_info['streams'][0]['codec_name'].startswith('pcm') ) self.assertTrue(ffprobe_info['streams'][0]['codec_name'].startswith('pcm'))
byte_rate = int(ffprobe_info['streams'][0]['sample_rate']) \ streams = ffprobe_info['streams'][0]
* ffprobe_info['streams'][0]['channels'] \ byte_rate = int(streams['sample_rate']) * streams['channels'] * int(streams['bits_per_raw_sample']) / 8
* int(ffprobe_info['streams'][0]['bits_per_raw_sample']) / 8 self.assertEqual(info.fmt.byte_rate, byte_rate)
self.assertEqual( info.fmt.byte_rate , byte_rate )
def test_data_against_ffprobe(self): def test_data_against_ffprobe(self):
for wav_file in all_files(): for wav_file in all_files():
info = wavinfo.WavInfoReader(wav_file) info = wavinfo.WavInfoReader(wav_file)
ffprobe_info = ffprobe(wav_file) ffprobe_info = ffprobe(wav_file)
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): def test_bext_against_ffprobe(self):
for wav_file in all_files(): for wav_file in all_files():
@@ -41,40 +42,40 @@ class TestWaveInfo(TestCase):
ffprobe_info = ffprobe(wav_file) ffprobe_info = ffprobe(wav_file)
if info.bext: if info.bext:
if 'comment' in ffprobe_info['format']['tags']: if 'comment' in ffprobe_info['format']['tags']:
self.assertEqual( info.bext.description, ffprobe_info['format']['tags']['comment'] ) self.assertEqual(info.bext.description, ffprobe_info['format']['tags']['comment'])
else: else:
self.assertEqual( info.bext.description , '') self.assertEqual(info.bext.description, '')
if 'encoded_by' in ffprobe_info['format']['tags']: if 'encoded_by' in ffprobe_info['format']['tags']:
self.assertEqual( info.bext.originator, ffprobe_info['format']['tags']['encoded_by'] ) self.assertEqual(info.bext.originator, ffprobe_info['format']['tags']['encoded_by'])
else: else:
self.assertEqual( info.bext.originator, '') self.assertEqual(info.bext.originator, '')
if 'originator_reference' in ffprobe_info['format']['tags']: if 'originator_reference' in ffprobe_info['format']['tags']:
self.assertEqual( info.bext.originator_ref, ffprobe_info['format']['tags']['originator_reference'] ) self.assertEqual(info.bext.originator_ref, ffprobe_info['format']['tags']['originator_reference'])
else: else:
self.assertEqual( info.bext.originator_ref, '') self.assertEqual(info.bext.originator_ref, '')
# these don't always reflect the bext info # these don't always reflect the bext info
# self.assertEqual( info.bext.originator_date, ffprobe_info['format']['tags']['date'] ) # self.assertEqual(info.bext.originator_date, ffprobe_info['format']['tags']['date'])
# self.assertEqual( info.bext.originator_time, ffprobe_info['format']['tags']['creation_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']: if 'coding_history' in ffprobe_info['format']['tags']:
self.assertEqual( info.bext.coding_history, ffprobe_info['format']['tags']['coding_history'] ) self.assertEqual(info.bext.coding_history, ffprobe_info['format']['tags']['coding_history'])
else: else:
self.assertEqual( info.bext.coding_history, '' ) self.assertEqual(info.bext.coding_history, '')
def test_ixml(self): def test_ixml(self):
expected = {'A101_4.WAV': {'project' : 'BMH', 'scene': 'A101', 'take': '4', expected = {'A101_4.WAV': {'project': 'BMH', 'scene': 'A101', 'take': '4',
'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124015008231000'}, 'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124015008231000'},
'A101_3.WAV': {'project' : 'BMH', 'scene': 'A101', 'take': '3', 'A101_3.WAV': {'project': 'BMH', 'scene': 'A101', 'take': '3',
'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124014008228300'}, 'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124014008228300'},
'A101_2.WAV': {'project' : 'BMH', 'scene': 'A101', 'take': '2', 'A101_2.WAV': {'project': 'BMH', 'scene': 'A101', 'take': '2',
'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124004008218600'}, 'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124004008218600'},
'A101_1.WAV': {'project' : 'BMH', 'scene': 'A101', 'take': '1', 'A101_1.WAV': {'project': 'BMH', 'scene': 'A101', 'take': '1',
'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124001008206300'}, 'tape': '18Y12M31', 'family_uid': 'USSDVGR1112089007124001008206300'},
} }
for wav_file in all_files(): for wav_file in all_files():
basename = os.path.basename(wav_file) basename = os.path.basename(wav_file)
@@ -82,15 +83,13 @@ class TestWaveInfo(TestCase):
info = wavinfo.WavInfoReader(wav_file) info = wavinfo.WavInfoReader(wav_file)
e = expected[basename] e = expected[basename]
self.assertEqual( e['project'], info.ixml.project ) self.assertEqual(e['project'], info.ixml.project)
self.assertEqual( e['scene'], info.ixml.scene ) self.assertEqual(e['scene'], info.ixml.scene)
self.assertEqual( e['take'], info.ixml.take ) self.assertEqual(e['take'], info.ixml.take)
self.assertEqual( e['tape'], info.ixml.tape ) self.assertEqual(e['tape'], info.ixml.tape)
self.assertEqual( e['family_uid'], info.ixml.family_uid ) self.assertEqual(e['family_uid'], info.ixml.family_uid)
for track in info.ixml.track_list: for track in info.ixml.track_list:
self.assertIsNotNone(track.channel_index) self.assertIsNotNone(track.channel_index)
if basename == 'A101_4.WAV' and track.channel_index == '1': if basename == 'A101_4.WAV' and track.channel_index == '1':
self.assertTrue(track.name == 'MKH516 A') self.assertEqual(track.name, 'MKH516 A')

View File

@@ -8,5 +8,6 @@ from unittest import TestCase
import wavinfo import wavinfo
class TestZoomF8(TestCase): class TestZoomF8(TestCase):
pass pass

View File

@@ -4,10 +4,11 @@ import subprocess
from subprocess import PIPE from subprocess import PIPE
import json import json
FFPROBE='ffprobe' FFPROBE = 'ffprobe'
def ffprobe(path): def ffprobe(path):
arguments = [ FFPROBE , "-of", "json" , "-show_format", "-show_streams", path ] arguments = [FFPROBE, "-of", "json", "-show_format", "-show_streams", path]
if int(sys.version[0]) < 3: if int(sys.version[0]) < 3:
process = subprocess.Popen(arguments, stdout=PIPE) process = subprocess.Popen(arguments, stdout=PIPE)
process.wait() process.wait()
@@ -27,13 +28,9 @@ def ffprobe(path):
return None return None
def all_files(): 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: for filename in filenames:
_, ext = os.path.splitext(filename) _, ext = os.path.splitext(filename)
if ext in ['.wav','.WAV']: if ext in ['.wav','.WAV']:
yield os.path.join(dirpath, filename) yield os.path.join(dirpath, filename)