Ejemplo n.º 1
0
def profile_command(
        reports="ProfileReporter",
        n=1, # How many times to run dexy for profiling.
        **kw # Accepts additional keyword arguments for the 'dexy' command
    ):
    """
    Runs dexy using cProfile to do time-based profiling. Uses ProfileReport
    (the only report enabled by default) to present profiling information.
    Other reports can be specified, report time is not included in profiling.
    Running ProfileReport each time ensures that profiling data is stored in
    sqlite database for comparison (a 'dexy reset' will delete this database).
    """
    dexy_fn = args.function_for(dexy.commands, "dexy")
    defaults = args.determine_kwargs(dexy_fn)
    defaults.update(kw)
    defaults['profile'] = True

    locals_for_run_dexy = {'args' : defaults}

    logs_dir = kw.has_key("logsdir") and kw['logsdir'] or Constants.DEFAULT_LDIR
    prof_file = os.path.join(logs_dir, "dexy.prof")

    report_kwargs = {}
    if kw.has_key('artifactclass'):
        report_kwargs['artifactclass'] = kw['artifactclass']

    for i in xrange(n):
        print "===== run %s of %s =====" % (i+1, n)
        cProfile.runctx("run_dexy(args)", globals(), copy.deepcopy(locals_for_run_dexy), prof_file)
        reports_command(reports=reports, **report_kwargs)
def test_kwdocs():
    fn = args.function_for(commands, "documented")
    kwdocs = args.determine_kwdocs(fn)
    assert kwdocs['port'] == "The TCP port on which to connect"
    assert kwdocs['host'] == "The host to run as"
    assert kwdocs['chroot'] == "TODO what should happen here.."
    assert kwdocs['chdir'] is None
    assert kwdocs['kwargs'] == "Other unspecified args to be passed to another command."
def test_help_on_command():
    fn = args.function_for(commands, "documented")
    help_text = args.help_text('modargs', commands, on="documented")
    assert "Help for 'modargs documented'" in help_text
    assert "This is a very important command" in help_text
    assert "port - The TCP port on which to connect" in help_text
    assert "e.g. 'modargs documented --port 8825'" in help_text
    assert "Keyword Arguments" in help_text
Ejemplo n.º 4
0
def test_help_on_command():
    fn = args.function_for(commands, "documented")
    help_text = args.help_text('modargs', commands, on="documented")
    assert "Help for 'modargs documented'" in help_text
    assert "This is a very important command" in help_text
    assert "port - The TCP port on which to connect" in help_text
    assert "e.g. 'modargs documented --port 8825'" in help_text
    assert "Keyword Arguments" in help_text
Ejemplo n.º 5
0
def test_kwdocs():
    fn = args.function_for(commands, "documented")
    kwdocs = args.determine_kwdocs(fn)
    assert kwdocs['port'] == "The TCP port on which to connect"
    assert kwdocs['host'] == "The host to run as"
    assert kwdocs['chroot'] == "TODO what should happen here.."
    assert kwdocs['chdir'] is None
    assert kwdocs[
        'kwargs'] == "Other unspecified args to be passed to another command."
Ejemplo n.º 6
0
def test_run():
    with tempdir():
        fn = modargs.function_for(dexy.commands, "dexy")
        args = modargs.determine_kwargs(fn)
        args['globals'] = []
        os.mkdir(args['logsdir'])
        c = Controller(args)
        c.config = SIMPLE_PY_CONFIG
        c.process_config()
        assert c.members.has_key("simple.py|py")
        assert isinstance(c.members["simple.py|py"], Document)
Ejemplo n.º 7
0
Archivo: utils.py Proyecto: mrflip/dexy
def controller_args(additional_args = {}):
    fn = modargs.function_for(dexy.commands, "dexy")
    args = modargs.determine_kwargs(fn)
    args.update(additional_args)

    if not os.path.exists(args['logsdir']):
        os.mkdir(args['logsdir'])
    if not os.path.exists(args['artifactsdir']):
        os.mkdir(args['artifactsdir'])

    return args
Ejemplo n.º 8
0
def controller_args(additional_args={}):
    fn = modargs.function_for(dexy.commands, "dexy")
    args = modargs.determine_kwargs(fn)
    args.update(additional_args)

    if not os.path.exists(args['logsdir']):
        os.mkdir(args['logsdir'])
    if not os.path.exists(args['artifactsdir']):
        os.mkdir(args['artifactsdir'])

    return args
Ejemplo n.º 9
0
def test_circular_dependencies():
    with tempdir():
        fn = modargs.function_for(dexy.commands, "dexy")
        args = modargs.determine_kwargs(fn)
        args['globals'] = []
        os.mkdir(args['logsdir'])
        args['danger'] = True
        c = Controller(args)
        c.config = CIRCULAR_CONFIG
        with divert_stdout() as stdout:
            try:
                c.process_config()
                assert False
            except CycleError:
                assert True
            stdout_text = stdout.getvalue()
        assert "abc depends on ghi" in stdout_text
        assert "def depends on abc" in stdout_text
        assert "ghi depends on def" in stdout_text
Ejemplo n.º 10
0
def profile_command(
        reports="ProfileReporter",
        **kw # Accepts additional keyword arguments for the 'dexy' command
    ):
    """
    Runs dexy using cProfile to do time-based profiling. Uses ProfileReport
    (the only report enabled by default) to present profiling information.
    Other reports can be specified, report time is not included in profiling.
    Running ProfileReport each time ensures that profiling data is stored in
    sqlite database for comparison (a 'dexy reset' will delete this database).
    """
    dexy_fn = args.function_for(dexy.commands, "dexy")
    defaults = args.determine_kwargs(dexy_fn)
    defaults.update(kw)
    defaults['profile'] = True

    ls = {'args' : defaults}
    cProfile.runctx("run_dexy(args)", globals(), ls, "logs/dexy.prof")
    reports_command(reports=reports)
Ejemplo n.º 11
0
def test_docs_with_no_filters():
    with tempdir():
        fn = modargs.function_for(dexy.commands, "dexy")
        args = modargs.determine_kwargs(fn)
        args['globals'] = []
        os.mkdir(args['logsdir'])
        c = Controller(args)
        c.config = NO_FILTERS_CONFIG
        c.process_config()
        assert c.members.has_key("hello.txt")
        assert isinstance(c.members["hello.txt"], Document)
        assert sorted(c.batch_info().keys()) == [
                "args",
                "config",
                "docs",
                "elapsed",
                "finish_time",
                "id",
                "start_time",
                "timing"
                ]
Ejemplo n.º 12
0
def run_dexy_without_tempdir(config_dict, additional_args={}):
    if not hasattr(Document, "filter_list"):
        Document.filter_list = dexy.introspect.filters()

    fn = modargs.function_for(dexy.commands, "dexy")
    args = modargs.determine_kwargs(fn)
    args.update(additional_args)

    if not os.path.exists(args["logsdir"]):
        os.mkdir(args["logsdir"])
    if not os.path.exists(args["artifactsdir"]):
        os.mkdir(args["artifactsdir"])

    c = Controller(args)
    c.config = config_dict
    c.process_config()

    [doc.setup() for doc in c.docs]

    for doc in c.docs:
        yield (doc)

    c.persist()
def test_mixed_type_args():
    fn = args.function_for(commands, "mixed_type")
    kwargs = args.determine_kwargs(fn)
    assert kwargs['kwfoo'] == 5
    assert kwargs['kwbaz'] == 'ok'
Ejemplo n.º 14
0
def test_mixed_type_args():
    fn = args.function_for(commands, "mixed_type")
    kwargs = args.determine_kwargs(fn)
    assert kwargs['kwfoo'] == 5
    assert kwargs['kwbaz'] == 'ok'