
from __future__ import print_function

import shutil
import os

from model_test_helper import ModelTestHelper

tests = {'om_360x300-valgrind' : ('om'),
         'cm_360x300-valgrind' : ('cm')}

class TestValgrind(ModelTestHelper):
    """
    Run the model in valgrind.
    """

    def __init__(self):
        super(TestBasicRun, self).__init__()

    def pre_run_cleanup(self, exp):

        paths = self.make_paths(exp)

        try:
            shutil.rmtree(paths['archive'])
            os.remove(paths['archive_link'])
        except OSError, e:
            if not e.strerror == 'No such file or directory':
                raise e

    def check_run(self, key):

        print('############ Running {} ############'.format(key))
        self.pre_run_cleanup(key)
        self.do_basic_access_run(key, model=tests[key][0])

        # FIXME: check that valgrind does not find any problems.

    def test_runs(self):
        for k in tests.keys():
            yield self.check_run, k

Add valgrind tests file.