Ejemplo n.º 1
0
def test_runner_instance_callable_dry():

    cmd_ = ['echo', 'Testing', '__call__', 'with', 'string']
    for cmd in [cmd_, ' '.join(cmd_)]:
        dry = DryRunProtocol()
        runner = Runner(protocol=dry)
        ret = runner(cmd)
        # (stdout, stderr) is returned.  But in dry -- ("DRY","DRY")
        eq_(ret, ("DRY", "DRY"))
        assert_equal(
            cmd_, dry[0]['command'],
            "Dry run of Runner.__call__ didn't record command: %s.\n"
            "Buffer: %s" % (cmd, dry))

    ret = runner(os.path.join, 'foo', 'bar')
    eq_(ret, None)

    assert_in(
        'join', dry[1]['command'][0],
        "Dry run of Runner.__call__ didn't record function join()."
        "Buffer: %s" % dry)
    assert_equal(
        "args=('foo', 'bar')", dry[1]['command'][1],
        "Dry run of Runner.__call__ didn't record function join()."
        "Buffer: %s" % dry)
Ejemplo n.º 2
0
def test_runner_dry(tempfile):

    dry = DryRunProtocol()
    runner = Runner(protocol=dry)

    # test dry command call
    cmd = 'echo Testing äöü東 dry run > %s' % tempfile
    with swallow_logs(new_level=5) as cml:
        ret = runner.run(cmd)
        cml.assert_logged("{DryRunProtocol} Running: %s" % cmd, regex=False)
    assert_equal(("DRY", "DRY"), ret,
                 "Output of dry run (%s): %s" % (cmd, ret))
    assert_equal(split_cmdline(cmd), dry[0]['command'])
    assert_false(os.path.exists(tempfile))

    # test dry python function call
    output = runner.call(os.path.join, 'foo', 'bar')
    assert_is(None, output, "Dry call of: os.path.join, 'foo', 'bar' "
                            "returned: %s" % output)
    assert_in('join', dry[1]['command'][0])
    assert_equal("args=('foo', 'bar')", dry[1]['command'][1])
Ejemplo n.º 3
0
def get_runner(*args, **kwargs):
    if cfg.obtain('datalad.crawl.dryrun', default=False):
        kwargs = kwargs.copy()
        kwargs['protocol'] = DryRunProtocol()
    return Runner(*args, **kwargs)
Ejemplo n.º 4
0
        wipe_drives(drives)
    else:
        raise ValueError(action)


def parse_args(args=None):
    parser = argparse.ArgumentParser(
        description="A little benchmarker of file systems")
    parser.add_argument('action',
                        choices=["benchmark", "wipe"],
                        default="benchmark",
                        help='Action to perform')
    parser.add_argument('-n',
                        '--dry-run',
                        action='store_true',
                        help='Perform dry run')
    parser.add_argument(
        '--assume-created',
        action='store_true',
        help='Assume that FS was created and mounted (e.g. manually outside)')

    # Parse command line options
    return parser.parse_args(args)


if __name__ == "__main__":
    args = parse_args()
    if args.dry_run:
        dryrun.protocol = DryRunProtocol()
    main(args.action, assume_created=args.assume_created)