test/test_functional.py
author David Douard <david.douard@logilab.fr>
Wed, 14 May 2014 22:28:57 +0200
changeset 1520 0abe241164e2
parent 1501 a45f5a997ab2
child 1522 70131ccb08ec
permissions -rw-r--r--
[test] fix tests when executed in an apycot environment ie. when tests are executed from sources towards an installed apycot. The fix consist mainly in "moving" the input_path function from testutils.py (which is part of the installed modules) into unittest_checkers.py so we are sure we look for test data files relatively to the test directory (and not the location of the installation).

import os.path as osp
import subprocess
import shutil

import cubicweb.devtools
import cubes.apycot.testutils as utils

from cubes.apycot.recipes import full_script

HERE = osp.abspath(osp.dirname(__file__))
def setUpModule():
    ppath = osp.join(HERE, 'data', 'project')
    if osp.isdir(osp.join(ppath, '.hg')):
        shutil.rmtree(osp.join(ppath, '.hg'))
    subprocess.check_call(['hg', 'init', '-q', ppath])
    subprocess.check_call(['hg', 'addremove', '-q', '-R', ppath])
    subprocess.check_call(['hg', 'commit', '-q', '-R', ppath, '-m', 'ze rev'])
    subprocess.check_call(['hg', 'phase', '-p', '.', '-q', '-R', ppath])


def tearDownModule():
    shutil.rmtree(osp.join(HERE, 'data', 'project', '.hg'))

class ApycotTC(utils.ApycotBaseTC):

    def test_quick_recipe(self):
        te = self.lgc.start(self.lgce)
        self.commit()
        self.run_plan(te)
        self.assertEqual(dict((checker.name, checker.status) for checker in te.checkers),
                         {'pyunit': 'nodata'})


    def test_full_recipe(self):
        recipe = self.req.execute('Recipe X WHERE X name "apycot.recipe.full"').get_entity(0, 0)
        # reset recipe content
        recipe.set_attributes(script=full_script)
        tc = self.add_test_config(u'full config', env=self.lgce, group=self.pyp,
                                  use_recipe=recipe)
        te = tc.start(self.lgce)
        self.commit()
        self.run_plan(te)
        exp = {u'pycoverage': u'error', u'pyunit': u'nodata'}
        try:
            from pylint import checkers as pycheckers
            from pylint.lint import PyLinter
            from pylint.__pkginfo__ import version as pylint_version
            from pylint.interfaces import IReporter
            from pylint.reporters import BaseReporter
            exp['pylint'] = u'error'
        except:
            pass
        self.assertDictEqual(exp,
                             dict((checker.name, checker.status) for checker in te.checkers),
                             )