コード例 #1
0
ファイル: nose_runner.py プロジェクト: chevah/empirical
def main():
    """
    Execute the nose test runner.

    Drop privileges and alter the system argument to remove the
    userid and group id arguments that are only required for the test.
    """
    if len(sys.argv) < 2:
        print (
            u'Run the test suite using drop privileges username as first '
            u'arguments. Use "-" if you do not want elevated mode.')
        sys.exit(1)

    # Delay import after coverage is started.
    from chevah.empirical.nose_memory_usage import MemoryUsage
    from chevah.empirical.nose_test_timer import TestTimer
    from chevah.empirical.nose_run_reporter import RunReporter

    from chevah.empirical import EmpiricalTestCase


    drop_user = sys.argv[1]
    EmpiricalTestCase.initialize(drop_user=drop_user)
    EmpiricalTestCase.dropPrivileges()

    new_argv = ['chevah-test-runner']
    new_argv.extend(sys.argv[2:])
    sys.argv = new_argv
    plugins = [
        TestTimer(),
        RunReporter(),
        MemoryUsage(),
        ]
    try:
        nose_main(addplugins=plugins)
    except SystemExit, error:
        if cov:
            cov.stop()
            cov.save()
        import threading
        print "Max RSS: %s" % EmpiricalTestCase.getPeakMemoryUsage()
        threads = threading.enumerate()
        if len(threads) < 2:
            # No running threads, other than main so we can exit as normal.
            sys.exit(error.code)
        else:
            print "There are still active threads: %s" % threads

            # We do a brute force exit here, since sys.exit will wait for
            # unjoined threads.
            # We have to do some manual work to compensate for skipping sys.exit()
            sys.exitfunc()
            # Don't forget to flush the toilet.
            sys.stdout.flush()
            sys.stderr.flush()
            os._exit(error.code)
コード例 #2
0
ファイル: pavement.py プロジェクト: chevah/empirical
def test_py3():
    """
    Run checks for py3 compatibility.
    """
    from pylint.lint import Run
    from nose.core import main as nose_main
    arguments = ['--py3k', SETUP['folders']['source']]
    linter = Run(arguments, exit=False)
    stats = linter.linter.stats
    errors = (
        stats['info'] + stats['error'] + stats['refactor'] +
        stats['fatal'] + stats['convention'] + stats['warning']
        )
    if errors:
        print 'Pylint failed'
        sys.exit(1)

    print 'Compiling in Py3 ...',
    command = ['python3', '-m', 'compileall', '-q', 'chevah']
    pave.execute(command, output=sys.stdout)
    print 'done'

    sys.argv = sys.argv[:1]
    pave.python_command_normal.extend(['-3'])

    warnings.filterwarnings('always', module='chevah.empirical')
    captured_warnings = []

    def capture_warning(
        message, category, filename,
        lineno=None, file=None, line=None
            ):
        if not filename.startswith('chevah'):
            # Not our code.
            return
        line = (message.message, filename, lineno)
        if line in captured_warnings:
            # Don't include duplicate warnings.
            return
        captured_warnings.append(line)

    warnings.showwarning = capture_warning

    sys.args = ['nose', 'chevah.empirical.tests.normal']
    runner = nose_main(exit=False)
    if not runner.success:
        print 'Test failed'
        sys.exit(1)
    if not captured_warnings:
        sys.exit(0)

    print '\nCaptured warnings\n'
    for warning, filename, line in captured_warnings:
        print '%s:%s %s' % (filename, line, warning)
    sys.exit(1)