def cmd_test(metasync, args, opts): "quick test (e.g., metasync test {%s})" # invoke pdb when failed in testing util.install_pdb() tmpdir = tempfile.mkdtemp() root = os.path.join(tmpdir, "repo") util.mkdirs(root) metasync = MetaSync(root) # opts for sub test routines opts.root = root opts.tmpdir = tmpdir opts.encrypt_key = "testkey" if opts.encrypt else "" dbg.info("root: %s" % root) dbg.info("args: %s" % args) dbg.info("opts: ") for (k, v) in vars(opts).iteritems(): dbg.info(" %-12s = %s" % (k, v)) alltests = dict(test.get_all_tests()) if any(case not in alltests for case in args): dbg.err("no such a test case: %s" % args) alltests["help"](metasync, opts) exit(1)
def cmd_test(metasync, args, opts): "quick test (e.g., metasync test {%s})" # invoke pdb when failed in testing util.install_pdb() tmpdir = tempfile.mkdtemp() root = os.path.join(tmpdir, "repo") util.mkdirs(root) metasync = MetaSync(root) # opts for sub test routines opts.root = root opts.tmpdir = tmpdir opts.encrypt_key = "testkey" if opts.encrypt else "" dbg.info("root: %s" % root) dbg.info("args: %s" % args) dbg.info("opts: ") for (k, v) in vars(opts).iteritems(): dbg.info(" %-12s = %s" % (k, v)) alltests = dict(test.get_all_tests()) if any(case not in alltests for case in args): dbg.err("no such a test case: %s" % args) alltests["help"](metasync, opts) exit(1) # print help if no test case is provided if len(args) == 0: args = ["help"] for case in args: dbg.info("#R<testing %s#> (%s)" % (case, alltests[case].__doc__)) alltests[case](metasync, opts) # poorman's tree def tree(path): for root, dirs, files in os.walk(path): base = os.path.basename(root) idnt = ' ' * (root.replace(path, '').count(os.sep)) print('%s%s/' % (idnt, base)) for f in files: pn = os.path.join(root, f) print(' %s%s [%s]' % (idnt, f, os.stat(pn).st_size)) # dump some content of blobs if opts.dump and "objects" == base: print(util.hexdump(util.read_file(pn, 32*2))) print # dump root if not opts.notree: tree(tmpdir) # cleanup tmpdir if not opts.keep: shutil.rmtree(tmpdir)
# dump some content of blobs if opts.dump and "objects" == base: print(util.hexdump(util.read_file(pn, 32 * 2))) print # dump root if not opts.notree: tree(tmpdir) # cleanup tmpdir if not opts.keep: shutil.rmtree(tmpdir) # update cmd_test sub args cmd_test.__doc__ %= "|".join(n for (n, _) in test.get_all_tests()) def get_all_cmds(): for k, f in globals().items(): if k.startswith("cmd_"): yield (k[4:], f) def get_cmd(cmd): func = "cmd_%s" % cmd return globals().get(func, None) def invoke_cmd(cmd, metasync, args): func = get_cmd(cmd)
# dump some content of blobs if opts.dump and "objects" == base: print(util.hexdump(util.read_file(pn, 32*2))) print # dump root if not opts.notree: tree(tmpdir) # cleanup tmpdir if not opts.keep: shutil.rmtree(tmpdir) # update cmd_test sub args cmd_test.__doc__ %= "|".join(n for (n,_) in test.get_all_tests()) def get_all_cmds(): for k, f in globals().items(): if k.startswith("cmd_"): yield (k[4:], f) def get_cmd(cmd): func = "cmd_%s" % cmd return globals().get(func, None) def invoke_cmd(cmd, metasync, args): func = get_cmd(cmd) return func(metasync, args.args, args)