Skip to content

Commit

Permalink
Broke ffmpeg tests out as conditional on having the binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric J. Humphrey committed Feb 29, 2016
1 parent 06429a1 commit fba5e2e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ language: python
notifications:
email: false

before_script:
- "sudo apt-get install -y ffmpeg"

python:
- "2.7"
- "3.4"
Expand Down
19 changes: 15 additions & 4 deletions claudio/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import claudio.formats as formats
import claudio.util as util

try:
FileNotFoundError
except NameError:
FileNotFoundError = OSError

logging.basicConfig(level=logging.DEBUG)

Expand Down Expand Up @@ -40,10 +44,17 @@ def _check():
success : bool
True if it looks like ffmpeg exists.
"""
info = subprocess.check_output([__BIN__(), '-version'])
status = 'fmpeg version' in str(info)
if not status:
logging.warning(__NO_FFMPEG__)
try:
info = subprocess.check_output([__BIN__(), '-version'])
status = 'ffmpeg version' in str(info)
message = __NO_FFMPEG__
except (FileNotFoundError, subprocess.CalledProcessError) as derp:
status = False
message = __NO_FFMPEG__ + "\n{}".format(derp)
if status:
logging.info(message)
else:
logging.warning(message)
return status


Expand Down
3 changes: 3 additions & 0 deletions claudio/tests/test_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def test___BIN__():
assert ffmpeg.__BIN__()


@pytest.mark.skipif(not ffmpeg._check(), reason="Cannot find ffmpeg.")
def test_ffmpeg__check():
assert ffmpeg._check()


@pytest.mark.skipif(not ffmpeg._check(), reason="Cannot find ffmpeg.")
def test_ffmpeg_check_ffmpeg():
ffmpeg.check_ffmpeg()


@pytest.mark.skipif(not ffmpeg._check(), reason="Cannot find ffmpeg.")
def test_ffmpeg_convert(sample_wav):
fout = util.temp_file(formats.WAVE)
fin = str(sample_wav)
Expand Down
17 changes: 10 additions & 7 deletions claudio/tests/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
TODO: Update this to py.test, fixtures and standalone methods. This is pretty
old-school right here.
"""

import pytest
import unittest
import numpy as np
import os
import six
import tempfile
import wave

import claudio.ffmpeg as ffmpeg
import claudio.formats as formats
import claudio.fileio as fileio
import claudio.util as util
Expand Down Expand Up @@ -155,12 +156,6 @@ def test_read_real_aiff(self):
assert len(signal)
assert samplerate

def test_read_real_aiff_ffmpeg(self):
aiff_file = os.path.join(self.test_dir, 'sample.aiff')
signal, samplerate = fileio.read(aiff_file, converter='ffmpeg')
assert len(signal)
assert samplerate

def test_write_wave(self):
wav_file = os.path.join(self.test_dir, 'sample.wav')
x, fs1 = fileio.read(wav_file)
Expand All @@ -172,5 +167,13 @@ def test_write_wave(self):
assert fs1 == fs2


@pytest.mark.skipif(not ffmpeg._check(), reason="Cannot find ffmpeg.")
def test_read_real_aiff_ffmpeg():
aiff_file = os.path.join(os.path.dirname(__file__), 'sample.aiff')
signal, samplerate = fileio.read(aiff_file, converter='ffmpeg')
assert len(signal)
assert samplerate


if __name__ == "__main__":
unittest.main()

0 comments on commit fba5e2e

Please sign in to comment.