author Julien Cristau <julien.cristau@logilab.fr>
Wed, 09 Jul 2014 11:36:06 +0200
changeset 1547 9012705e9076
parent 1520 0abe241164e2
child 1607 51ba8d09c612
permissions -rw-r--r--
[narval/debcheck] use a glob instead of a recursive os.walk to find *.changes We know where those files are, there's no need to do a recursive search. This also avoids issues with os.walk with non-ascii file names. ***

unit tests for python test checkers

import os, sys
from os.path import join

from logilab.common.testlib import unittest_main, TestCase, mock_object

import cubicweb.devtools
from cubes.apycot.testutils import MockCheckWriter

from checkers.apycot import python

from unittest_checkers import input_path

def _test_cmd(self, cmd, status, success=0, failures=0, errors=0, skipped=0):

    for name, got, expected in (
            ('failures', cmd.parser.failures, failures),
            ('errors', cmd.parser.errors, errors),
            ('skipped', cmd.parser.skipped, skipped),
            ('success', cmd.parser.success, success),
        self.assertEqual(got, expected, '%i %s but %i expected'
                          % (got, name, expected))
    self.assertIs(cmd.status, status)

class PyUnitTestCheckerTC(TestCase):
    input_dir = input_path('testcase_pkg/tests/')

    def setUp(self):
        self.checker = python.PyUnitTestChecker(MockCheckWriter())
        self.checker._path = input_path('')
        self.checker.cwd = self.input_dir

    def input_path(self, path):
        return join(self.input_dir, path)

    def test_run_test_result_empty(self):
        cmd = self.checker.run_test(self.input_path('unittest_empty.py'))
        _test_cmd(self, cmd, NODATA, success=0)

    def test_run_test_result_no_main(self):
        cmd = self.checker.run_test(self.input_path('unittest_no_main.py'))
        _test_cmd(self, cmd, NODATA, success=0)

    def test_run_test_result_success(self):
        cmd = self.checker.run_test(self.input_path('unittest_success.py'))
        _test_cmd(self, cmd, SUCCESS, success=1)

    def test_run_test_result_failure(self):
        cmd = self.checker.run_test(self.input_path('unittest_failure.py'))
        _test_cmd(self, cmd, FAILURE, failures=1)

    def test_run_test_result_error(self):
        cmd = self.checker.run_test(self.input_path('unittest_errors.py'))
        _test_cmd(self, cmd, FAILURE, errors=1)

    def test_run_test_result_skipped(self):
        cmd = self.checker.run_test(self.input_path('unittest_skip.py'))
        _test_cmd(self, cmd, PARTIAL, skipped=1)

    def test_run_test_result_mixed(self):
        cmd = self.checker.run_test(self.input_path('unittest_mixed.py'))
        _test_cmd(self, cmd, FAILURE, 2, 15, 1, 2)

    def test_run_test_result_mixed_std(self):
        cmd = self.checker.run_test(self.input_path('unittest_mixed_std.py'))
        _test_cmd(self, cmd, FAILURE, 2, 15, 1, 0)

class PyTestCheckerTC(TestCase):
    input_dir = input_path('testcase_pkg/tests/')

    def setUp(self):
        self.checker = python.PyTestChecker(MockCheckWriter())
        self.checker.cwd = input_path('testcase_pkg')

    def _test_cmd(self, *args):

        cmd_args = ['-c', 'from logilab.common.pytest '
                  'import run; run()',]
        return self.checker.run_test(cmd_args, sys.executable)

    def test_global(self):
        cmd = self._test_cmd()
        #XXX should be NODATA but not handle at the moment
        _test_cmd(self, cmd, FAILURE, 6, 31, 3, 3)

if __name__ == '__main__':