<commit_before>import matplotlib
matplotlib.use('Agg')

import traceback, sys
from os import path
from glob import glob


def test_examples(): 
    print example_files()
    for path in example_files():
        yield check_example, path


def example_files():
    import pymc
    d = path.dirname(pymc.__file__)

    return glob(path.join(d, "../examples/*.py"))





def check_example(path):
    with open(path) as f :
        c = compile(f.read(), path, 'exec')
        exec(c)<commit_msg>examples now found recursively<commit_after>import matplotlib
matplotlib.use('Agg')

import os
from os import path
from glob import glob
import fnmatch

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


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 pymc
    d = path.dirname(pymc.__file__)

    return path.join(d, '../examples/')


def check_example(p):
    with open(p) as f :
        #c = compile(f.read(), p, 'exec')
        #exec(c)
        os.chdir(path.dirname(p))
        execfile(path.basename(p))
{'fraction_non_alphanumeric': 0.12150943396226416, 'fraction_numerical': 0.0, 'mean_word_length': 2.981981981981982, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2606332', 'n_tokens_mistral': 456, 'n_tokens_neox': 432, 'n_words': 117}