mirror of
https://github.com/iluvcapra/wavinfo.git
synced 2025-12-31 08:50:41 +00:00
Add tests
This commit is contained in:
@@ -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'
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ from unittest import TestCase
|
|||||||
|
|
||||||
import wavinfo
|
import wavinfo
|
||||||
|
|
||||||
|
|
||||||
class TestZoomF8(TestCase):
|
class TestZoomF8(TestCase):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user