Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flake8 Linting #29

Merged
merged 18 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
per-file-ignores =
wavinfo/__init__.py: F401
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ jobs:
- name: Test with pytest
run: |
pytest
flake8 wavinfo
5 changes: 4 additions & 1 deletion tests/test_adm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ def test_chna(self):
adm = info.adm
self.assertIsNotNone(adm)

assert adm is not None
self.assertEqual(len(adm.channel_uids), 14)

def test_to_dict(self):
info = wavinfo.WavInfoReader(self.protools_adm_wav)
adm = info.adm
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
assert adm is not None
pdict = adm.programme()
self.assertIn("programme_id", pdict.keys())
self.assertIn("programme_name", pdict.keys())
Expand All @@ -37,7 +40,7 @@ def test_programme(self):
def test_track_info(self):
info = wavinfo.WavInfoReader(self.protools_adm_wav)
adm = info.adm

assert adm is not None
t1 = adm.track_info(0)
self.assertTrue("channel_format_name" in t1.keys())
self.assertEqual("RoomCentricLeft", t1["channel_format_name"])
Expand Down
1 change: 1 addition & 0 deletions tests/test_cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def test_enumerate(self):
file1 = "tests/test_files/cue_chunks/STE-000.wav"
w1 = wavinfo.WavInfoReader(file1)
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)])

Expand Down
20 changes: 14 additions & 6 deletions tests/test_dolby.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

import wavinfo
from wavinfo.wave_dbmd_reader import SegmentType, DolbyAtmosMetadata, DolbyDigitalPlusMetadata
from wavinfo.wave_dbmd_reader import SegmentType, DolbyDigitalPlusMetadata

class TestDolby(TestCase):
def setUp(self):
Expand All @@ -19,8 +19,10 @@ def test_segments(self):
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)
Expand All @@ -38,15 +40,21 @@ def test_ddp(self):
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.assertTrue( ddp[0].audio_coding_mode, DolbyDigitalPlusMetadata.AudioCodingMode.CH_ORD_3_2 )
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)

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


3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def test_a_file(self):

def test_ixml(self):
with patch.object(sys, 'argv',
['TEST', '--ixml', 'tests/test_files/sounddevices/A101_1.WAV']):
['TEST', '--ixml',
'tests/test_files/sounddevices/A101_1.WAV']):
try:
main()
except:
Expand Down
87 changes: 62 additions & 25 deletions tests/test_wave_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ 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):
Expand All @@ -24,14 +26,21 @@ def test_fmt_against_ffprobe(self):
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'))
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
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):
Expand All @@ -40,7 +49,8 @@ def test_data_against_ffprobe(self):
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():
Expand All @@ -50,39 +60,63 @@ def test_bext_against_ffprobe(self):

if info.bext:
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:
self.assertEqual(info.bext.description, '')

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:
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'])
self.assertEqual(info.bext.originator_ref,
ffprobe_info['format']['tags']\
['originator_reference'])
else:
self.assertEqual(info.bext.originator_ref, '')

# these don't always reflect the bext info
# 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.time_reference, int(ffprobe_info['format']['tags']['time_reference']))
# 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.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'])
self.assertEqual(info.bext.coding_history,
ffprobe_info['format']['tags']\
['coding_history'])
else:
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():
Expand Down Expand Up @@ -112,7 +146,8 @@ def test_steinberg_ixml(self):
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.media_company,
"https://github.com/iluvcapra/wavinfo")
self.assertFalse(info.ixml.steinberg.media_drop_frames)
self.assertEqual(info.ixml.steinberg.media_duration, 1200.0)

Expand All @@ -124,7 +159,8 @@ def test_steinberg_missing(self):
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

Expand All @@ -138,7 +174,8 @@ def test_info_metadata(self):
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.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)
Expand Down
6 changes: 4 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


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:
process = subprocess.Popen(arguments, stdout=PIPE)
process.wait()
Expand All @@ -20,7 +21,8 @@ def ffprobe(path):
else:
return None
else:
process = subprocess.run(arguments, stdin=None, stdout=PIPE, stderr=PIPE)
process = subprocess.run(arguments, stdin=None,
stdout=PIPE, stderr=PIPE)
if process.returncode == 0:
output_str = process.stdout.decode('utf-8')
return json.loads(output_str)
Expand Down
33 changes: 19 additions & 14 deletions wavinfo/__main__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
from optparse import OptionParser, OptionGroup
import datetime
from . import WavInfoReader
from . import __version__

from optparse import OptionParser
import sys
import json
from enum import Enum


class MyJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Enum):
return o._name_
else:
return super().default(o)


class MissingDataError(RuntimeError):
pass


def main():
parser = OptionParser()

parser.usage = 'wavinfo (--adm | --ixml) <FILE> +'

# parser.add_option('-f', dest='output_format', help='Set the output format',
# default='json',
# metavar='FORMAT')

parser.add_option('--adm', dest='adm', help='Output ADM XML',
default=False, action='store_true')
parser.add_option('--adm', dest='adm',
help='Output ADM XML',
default=False,
action='store_true')

parser.add_option('--ixml', dest='ixml', help='Output iXML',
default=False, action='store_true')
parser.add_option('--ixml', dest='ixml',
help='Output iXML',
default=False,
action='store_true')

(options, args) = parser.parse_args(sys.argv)
for arg in args[1:]:
try:
this_file = WavInfoReader(path=arg)
this_file = WavInfoReader(f=arg)
if options.adm:
if this_file.adm:
sys.stdout.write(this_file.adm.xml_str())
Expand All @@ -47,9 +51,9 @@
raise MissingDataError("ixml")
else:
ret_dict = {
'filename': arg,
'run_date': datetime.datetime.now().isoformat() ,
'application': "wavinfo " + __version__,
'filename': arg,
'run_date': datetime.datetime.now().isoformat(),
'application': "wavinfo " + __version__,
'scopes': {}
}
for scope, name, value in this_file.walk():
Expand All @@ -60,7 +64,8 @@

json.dump(ret_dict, cls=MyJSONEncoder, fp=sys.stdout, indent=2)
except MissingDataError as e:
print("MissingDataError: Missing metadata (%s) in file %s" % (e, arg), file=sys.stderr)
print("MissingDataError: Missing metadata (%s) in file %s" %

Check warning on line 67 in wavinfo/__main__.py

View check run for this annotation

Codecov / codecov/patch

wavinfo/__main__.py#L67

Added line #L67 was not covered by tests
(e, arg), file=sys.stderr)
continue
except Exception as e:
raise e
Expand Down
Loading
Loading