def test_syncfile(self): """ Tests that a file can be sync'd """ synchronizer = sync.RsyncSynchronizer() src_file = self.test_files[0]["path"] dst_file = os.path.join(self.test_dst_dir, self.test_files[0]["name"]) self.assertTrue(synchronizer.sync(src_file, dst_file)) self.assertTrue(filecmp.cmp(src_file, dst_file))
def test_syncfiletomissingdir(self): """ Tests that a file can be sync'd to a directory that's missing """ synchronizer = sync.RsyncSynchronizer() new_dir = os.path.join("missing_dir", ".") src_file = self.test_files[0]["path"] dst_dir = os.path.join(self.test_dst_dir, new_dir) # Sync the file to the missing directory (should fail) self.assertFalse(synchronizer.sync(src_file, dst_dir))
def test_syncwithoptions(self): """ Tests that options provided to the synchronizer are effective """ options = "--dry-run" synchronizer = sync.RsyncSynchronizer(options) src_file = self.test_files[0]["path"] dst_file = os.path.join(self.test_dst_dir, self.test_files[0]["name"]) # Do the sync (it should succeed) self.assertTrue(synchronizer.sync(src_file, dst_file)) # Make sure the dst file does not exist self.assertFalse(os.path.exists(dst_file))
def test_syncdir(self): """ Tests that a directory can be sync'd """ synchronizer = sync.RsyncSynchronizer() src_dir = self.test_src_dir dst_dir = self.test_dst_dir # Sync the directories self.assertTrue(synchronizer.sync(src_dir, dst_dir)) # Compare the files in the directories dst_dir = os.path.join(self.test_dst_dir, self.test_src) files = map(lambda i: i["name"], self.test_files) match, mismatch, err = filecmp.cmpfiles(src_dir, dst_dir, files) for f in files: self.assertIn(f, match) self.assertTrue(not mismatch) self.assertTrue(not err)
def test_manyfilesyncs(self): """ Tests that a single synchronizer can do many syncs """ synchronizer = sync.RsyncSynchronizer() src_dir = self.test_src_dir dst_dir = self.test_dst_dir # Sync each test file for f in self.test_files: dst_file = os.path.join(dst_dir, f["name"]) self.assertTrue(synchronizer.sync(f["path"], dst_file)) # Compare the files in the directories files = map(lambda i: i["name"], self.test_files) match, mismatch, err = filecmp.cmpfiles(src_dir, dst_dir, files) for f in files: self.assertIn(f, match) self.assertTrue(not mismatch) self.assertTrue(not err) pass