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,11 +7,13 @@ 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():
@@ -24,9 +26,8 @@ class TestWaveInfo(TestCase):
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):
@@ -91,6 +92,4 @@ class TestWaveInfo(TestCase):
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

@@ -6,6 +6,7 @@ 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:
@@ -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)