Ejemplo n.º 1
0
def main(test_specs, should_write_xml, max_size, appengine_sdk_dir=None):
    appengine_tool_setup.fix_sys_path(appengine_sdk_dir)

    # This import needs to happen after fix_sys_path is run.
    from testutil import testsize
    testsize.set_max_size(max_size)

    num_errors = 0

    for test_spec in test_specs:
        loader = unittest.loader.TestLoader()
        if not os.path.exists(test_spec):
            suite = loader.loadTestsFromName(test_spec)
        elif test_spec.endswith('.py'):
            suite = loader.loadTestsFromName(file_path_to_module(test_spec))
        else:
            suite = loader.discover(test_spec,
                                    pattern=TEST_FILE_RE,
                                    top_level_dir=os.getcwd())

        if should_write_xml:
            runner = xmlrunner.XMLTestRunner(verbose=True,
                                             output='test-reports')
        else:
            runner = unittest.TextTestRunner(verbosity=2)

        result = runner.run(suite)
        if not result.wasSuccessful():
            num_errors += 1

    return num_errors
Ejemplo n.º 2
0
def main(test_specs, html_basefilename, max_size, appengine_sdk_dir=None, filename=None):
    appengine_tool_setup.fix_sys_path(appengine_sdk_dir)

    # This import needs to happen after fix_sys_path is run.
    from testutil import testsize
    testsize.set_max_size(max_size)

    num_errors = 0

    for test_spec in test_specs:
        loader = unittest.loader.TestLoader()
        if not os.path.exists(test_spec):
            suite = loader.loadTestsFromName(test_spec)
        elif test_spec.endswith('.py'):
            suite = loader.loadTestsFromName(file_path_to_module(test_spec))
        else:
            suite = loader.discover(test_spec,
                                    pattern=TEST_FILE_RE,
                                    top_level_dir=os.getcwd())

        if html_basefilename:
            import HTMLTestRunner
            fp = file('test_reports/%s.html' % html_basefilename, 'wb')
            runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
                                                   title='KhanLatest unit test',
                                                   description='Refers to file commit %s.' % html_basefilename)
            runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">'
            result = runner.run(suite)
            fp = file('test_reports/%s.json' % html_basefilename, "wb")
            json.dump({"wasSuccessful": result.wasSuccessful()}, fp)
            fp.close()
        else:
            runner = unittest.TextTestRunner(verbosity=2)
            result = runner.run(suite)

        if not result.wasSuccessful():
            num_errors += 1

    return num_errors
Ejemplo n.º 3
0
                      help='path to the sqlite datastore. '
                           'Uses %(default)s by default.')

    args = parser.parse_args()

    # SERVER_SOFTWARE is used by dev_appserver to set various things
    # It's also used in transaction_util.ensure_in_transaction to determine
    # whether we're interfacing with the remote API.
    #
    # Without this, anything using ensure_in_transaction won't work properly
    #
    # This has to be done before fix_sys_path, because fix_sys_path sets its
    # own SERVER_SOFTWARE if one isn't already defined.
    os.environ['SERVER_SOFTWARE'] = 'Development (devshell remote-api)/1.0'

    appengine_tool_setup.fix_sys_path(args.sdk)

    # These have to be imported after fix_sys_path is called
    from google.appengine.ext.remote_api import remote_api_stub
    from testutil import handler_test_utils

    handler_test_utils.start_dev_appserver(
        db=args.datastore_path,
        persist_db_changes=True)

    remote_api_stub.ConfigureRemoteApi(
        None,
        '/_ah/remote_api',
        auth_func=(lambda: ('test', 'test')),   # username/password
        servername=handler_test_utils.appserver_url[len('http://'):])
Ejemplo n.º 4
0
those named *_lint.py, and runs all functions named lint_*() inside
those files.  Each lint_*() function is passed a list of files to
lint, which by default is all files under the current directory.
"""

import argparse
import importlib
import os
import subprocess
import sys
import time
import types

# This is needed so the import_module() below can succeed.
import appengine_tool_setup
appengine_tool_setup.fix_sys_path()

from shared import ka_root
from shared.testutil import lintutil

# We can't do a normal import here because 'khan-linter-src' has
# dashes in it.  We could fix that, but we don't want people
# importing khan-linter-src in general; we're a special case.
sys.path.insert(0, ka_root.join('third_party', 'khan-linter-src'))
import runlint as khan_linter

LINT_FILE_SUFFIX = '_lint.py'


def _get_lint_py_files(use_vcs, verbose=False):
    """All *_lint.py files in the current repo."""