Skip to content

Commit

Permalink
Changed how animations are tested. No reliable way to compare actual
Browse files Browse the repository at this point in the history
movies, becuase of different encoders/libraries/etc. Instead, just draw
one frame from the animation (defined by the animation function), and
compare that with a saved imaged on disk.
  • Loading branch information
bnaecker committed Nov 16, 2016
1 parent 72f8c52 commit 3c05fd7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: python
python:
- "3.5"
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y ffmpeg
install:
- sudo apt-get -qq update
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
else
Expand Down
Binary file added tests/test-images/baseline-rates-movie-frame.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/test-images/baseline-rates-movie.mp4
Binary file not shown.
Binary file added tests/test-images/baseline-sta-movie-frame.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/test-images/baseline-sta-movie.mp4
Binary file not shown.
38 changes: 21 additions & 17 deletions tests/test_visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os

from matplotlib.testing.compare import compare_images
from matplotlib.animation import writers
from matplotlib.patches import Ellipse
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -120,19 +119,24 @@ def test_raster_and_psth():
plt.close('all')


@pytest.mark.skipif(not writers.is_available('ffmpeg'),
reason='Requires ffmpeg to test animations')
def test_playsta():
"""Test playing an STA as a movie."""
"""Test playing an STA as a movie.
Matplotlib doesn't yet have a way to compare movies, and the formats
and precise bytes written by different encoding libraries are too variable
to test reliably. Instead, we write a specific frame of the animation
to disk as an image, and compare it with a baseline.
"""
nx, ny, nt = 10, 10, 50
sta = utils.create_spatiotemporal_filter(nx, ny, nt)[-1]
anim = viz.playsta(sta)
filename = os.path.join(IMG_DIR, 'test-sta-movie.mp4')
anim.save(filename)

with open(os.path.join(IMG_DIR, 'baseline-sta-movie.mp4'), 'rb') as base:
with open(filename, 'rb') as test:
assert base.read() == test.read()
filename = os.path.join(IMG_DIR, 'test-sta-movie.png')
frame = 10
anim._func(frame)
plt.savefig(filename)
assert not compare_images(
os.path.join(IMG_DIR, 'baseline-sta-movie-frame.png'),
filename, 1)
os.remove(filename)
plt.close('all')

Expand Down Expand Up @@ -167,8 +171,6 @@ def test_plotcells():
plt.close('all')


@pytest.mark.skipif(not writers.is_available('ffmpeg'),
reason='Requires ffmpeg to test animations')
def test_playrates():
"""Test playing firing rates for cells as a movie."""
nx, ny, nt = 10, 10, 50
Expand All @@ -182,11 +184,13 @@ def test_playrates():
fig, axes = viz.ellipse(sta)
patch = plt.findobj(axes, Ellipse)[0]
anim = viz.playrates(rate, patch)
filename = os.path.join(IMG_DIR, 'test-rates-movie.mp4')
anim.save(filename)
with open(os.path.join(IMG_DIR, 'baseline-rates-movie.mp4'), 'rb') as base:
with open(filename, 'rb') as test:
assert base.read() == test.read()
filename = os.path.join(IMG_DIR, 'test-rates-movie.png')
frame = 10
anim._func(frame)
plt.savefig(filename)
assert not compare_images(
os.path.join(IMG_DIR, 'baseline-rates-movie-frame.png'),
filename, 1)
os.remove(filename)
plt.close('all')

0 comments on commit 3c05fd7

Please sign in to comment.