Skip to content

Commit

Permalink
TST: Added unittest that runs all examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
twiecki authored and Eddie Hebert committed May 2, 2013
1 parent 3711bf3 commit b8b21b3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright 2013 Quantopian, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This code is based on a unittest written by John Salvatier:
# https://github.com/pymc-devs/pymc/blob/pymc3/tests/test_examples.py

# Disable plotting
#
import matplotlib
matplotlib.use('Agg')

from os import path
import os
import fnmatch
import imp


def test_examples():
os.chdir(example_dir())
for fname in all_matching_files('.', '*.py'):
yield check_example, fname


def all_matching_files(d, pattern):
def addfiles(fls, dir, nfiles):
nfiles = fnmatch.filter(nfiles, pattern)
nfiles = [path.join(dir, f) for f in nfiles]
fls.extend(nfiles)

files = []
path.walk(d, addfiles, files)
return files


def example_dir():
import zipline
d = path.dirname(zipline.__file__)
return path.join(path.abspath(d), 'examples/')


def check_example(p):
imp.load_source('__main__', path.basename(p))

0 comments on commit b8b21b3

Please sign in to comment.