def runverify(self, in_dir, out_dir=None, munge_output=None, munge_input=None, src_optlist=None, dst_optlist=None, vfy_optlist=None): ''' Run hsync, optionally change something, then run the verifier. ''' (in_tmp, out_tmp) = self.rundiff(in_dir, out_dir, delete=False, src_optlist=src_optlist, dst_optlist=dst_optlist) if munge_input is not None: munge_input(in_tmp) if munge_output is not None: munge_output(out_tmp) vfyopt = ['--verify-only', '-D', out_tmp, '-u', in_tmp, '-d'] if vfy_optlist is not None: vfyopt.extend(vfy_optlist) ret = hsync.main(vfyopt) shutil.rmtree(in_tmp) shutil.rmtree(out_tmp) return ret
def test_no_args_source_side(self): '''Fail with arguments for -S mode''' with self.assertRaises(UnexpectedArgumentsError): hsync.main(['-S', '/nonexistent', 'blah'])
def test_00runnable(self): '''Program is runnable directly from Python import''' with self.assertRaises(SystemExit): hsync.main(['-h'])
def rundiff(self, in_dir, out_dir=None, delete=True, src_optlist=None, dst_optlist=None, web=False, diff_optlist=None, run_diff=True, srvr_repeat=1, clnt_repeat=1): ''' Set up copies of an existing tree (or existing trees), run hsync and report on any differences. Differences are detected using 'diff -Purd'. This has a few problems, notably it's not that portable, and that broken symlinks will cause it to fail. If delete is True, remove the temporary output directories. Otherwise, return (in_tmp, out_tmp), probably for further comparison. src_optlist and dst_optlist are optional lists of additional options to pass to the -S and -D commands respectively. ''' in_tmp = self.in_tmp out_tmp = self.out_tmp self._just_remove(in_tmp) self._just_remove(out_tmp) in_dir = os.path.join(self.topdir, in_dir) if os.path.isdir(in_dir): shutil.copytree(in_dir, in_tmp, symlinks=True) else: # Allows for deliberate tripping of the file-where-dir-expected # error. shutil.copyfile(in_dir, in_tmp) subprocess.check_call(['find', in_tmp, '-name', '.gitignore', '-exec', 'rm', '{}', ';']) if out_dir is not None: shutil.copytree(os.path.join(self.topdir, out_dir), out_tmp, symlinks=True) subprocess.check_call(['find', out_tmp, '-name', '.gitignore', '-exec', 'rm', '{}', ';']) else: os.mkdir(out_tmp) srcopt = ['-S', in_tmp] if src_optlist is not None: srcopt.extend(src_optlist) for n in range(1, srvr_repeat + 1): self.assertTrue(hsync.main(srcopt)) for n in range(1, clnt_repeat + 1): in_url = in_tmp if web: in_url = 'http://127.0.0.1:%d/test/in_tmp' % (self.wport) log.debug("Fetch URL: %s", in_url) # time.sleep(20) # XXX dstopt = ['--no-write-hashfile', '-D', out_tmp, '-u', in_url, '-d'] if dst_optlist is not None: dstopt.extend(dst_optlist) self.assertTrue(hsync.main(dstopt)) # os.unlink(hashfile) if run_diff: diffopt = ['diff', '-Purd', '-x', 'HSYNC.SIG*', in_tmp, out_tmp] if diff_optlist is not None: diffopt.extend(diff_optlist) ret = subprocess.call(diffopt) # if ret != 0: # subprocess.call("bash", shell=True) self.assertEqual(ret, 0, "diff -Purd should return 0 " "('no differences')") if delete: self._just_remove(in_tmp) self._just_remove(out_tmp) else: return (in_tmp, out_tmp)