Ejemplo n.º 1
0
    def action_shell(instance=("I", DEFAULT_INSTANCE_FOLDER)):
        """Start a new interactive python session."""

        from rezine import setup_rezine
        from code import interact

        rezine_app = setup_rezine(instance)
        namespace = {"rezine_app": rezine_app}

        banner = """Interactive Rezine Shell

  namespace:
"""
        for k, v in namespace.items():
            banner += "    %s: %s\n" % (k, v.__doc__.split("\n")[0].strip())

        banner += "\n  Use dir() to inspect current namespace."
        interact(banner, local=namespace)
Ejemplo n.º 2
0
def test_suite(modnames=[]):
    """Generate the test suite.

    The first argument is a list of modules to be tested. If it is empty (which
    it is by default), all sub-modules of the rezine package are tested.
    If the second argument is True, this function returns two objects: a
    TestSuite instance and a list of the names of the tested modules. Otherwise
    (which is the default) it only returns the former. This is done so that
    this function can be used as setuptools' test_suite.
    """

    # the app object is used for two purposes:
    # 1) plugins are not usable (i.e. not testable) without an initialised app
    # 2) for functions that require an application object as argument, you can
    #    write >>> my_function(app, ...) in the tests
    # The instance directory of this object is located in the tests directory.
    #
    from rezine import is_rezine_setup, setup_rezine, get_rezine

    if not is_rezine_setup():
        # instance files potentially get changed, lets
        # set them up in a temp dir first
        tmpdir = mkdtemp()
        instance_path = join(tmpdir, DEFAULT_INSTANCE_FOLDER)
        copytree(join(dirname(__file__), DEFAULT_INSTANCE_FOLDER),
                 instance_path)
        app = setup_rezine(instance_path)
    else:
        app = get_rezine()

    suite = TestSuite()

    if modnames == []:
        modnames = find_tp_modules()
    test_files = os.listdir(dirname(__file__))
    for modname in modnames:
        if modname in untested:
            continue

        # the fromlist must contain something, otherwise the rezine
        # package is returned, not our module
        try:
            mod = __import__(modname, None, None, [''])
        except ImportError:
            # some plugins can have external dependencies (e.g. creoleparser,
            # pygments) that are not installed on the machine the tests are
            # run on. Therefore, just skip those (with an error message)
            if 'plugins.' in modname:
                sys.stderr.write('could not import plugin %s\n' % modname)
                continue
            else:
                raise

        suites = [DocTestSuite(mod, extraglobs={'app': app})]
        filename = modname[5:] + '.txt'
        if filename in test_files:
            globs = {'app': app}
            globs.update(mod.__dict__)
            suites.append(DocFileSuite(filename, globs=globs))
        for i, subsuite in enumerate(suites):
            # skip modules without any tests
            if subsuite.countTestCases():
                suite.addTest(subsuite)
    return suite
Ejemplo n.º 3
0
def test_suite(modnames=[]):
    """Generate the test suite.

    The first argument is a list of modules to be tested. If it is empty (which
    it is by default), all sub-modules of the rezine package are tested.
    If the second argument is True, this function returns two objects: a
    TestSuite instance and a list of the names of the tested modules. Otherwise
    (which is the default) it only returns the former. This is done so that
    this function can be used as setuptools' test_suite.
    """

    # the app object is used for two purposes:
    # 1) plugins are not usable (i.e. not testable) without an initialised app
    # 2) for functions that require an application object as argument, you can
    #    write >>> my_function(app, ...) in the tests
    # The instance directory of this object is located in the tests directory.
    #
    from rezine import is_rezine_setup, setup_rezine, get_rezine

    if not is_rezine_setup():
        # instance files potentially get changed, lets
        # set them up in a temp dir first
        tmpdir = mkdtemp()
        instance_path = join(tmpdir, DEFAULT_INSTANCE_FOLDER)
        copytree(join(dirname(__file__), DEFAULT_INSTANCE_FOLDER), instance_path)
        app = setup_rezine(instance_path)
    else:
        app = get_rezine()

    suite = TestSuite()

    if modnames == []:
        modnames = find_tp_modules()
    test_files = os.listdir(dirname(__file__))
    for modname in modnames:
        if modname in untested:
            continue

        # the fromlist must contain something, otherwise the rezine
        # package is returned, not our module
        try:
            mod = __import__(modname, None, None, [''])
        except ImportError:
            # some plugins can have external dependencies (e.g. creoleparser,
            # pygments) that are not installed on the machine the tests are
            # run on. Therefore, just skip those (with an error message)
            if 'plugins.' in modname:
                sys.stderr.write('could not import plugin %s\n' % modname)
                continue
            else:
                raise

        suites = [DocTestSuite(mod, extraglobs={'app': app})]
        filename = modname[5:] + '.txt'
        if filename in test_files:
            globs = {'app': app}
            globs.update(mod.__dict__)
            suites.append(DocFileSuite(filename, globs=globs))
        for i, subsuite in enumerate(suites):
            # skip modules without any tests
            if subsuite.countTestCases():
                suite.addTest(subsuite)
    return suite