def testStop(self): """ Test that stop really stops the copying process. """ try: with tempfile.NamedTemporaryFile() as src: os.unlink(src.name) os.mkfifo(src.name) with tempfile.NamedTemporaryFile() as dst: misc.ddWatchCopy(src.name, dst.name, lambda: True, 100) except utils.ActionStopped: self.log.info("Looks like it stopped!") else: self.fail("Copying didn't stop!")
def testCopy(self): """ Test that regular copying works. """ # Prepare source data = "Everything starts somewhere, " + \ "though many physicists disagree." + \ "But people have always been dimly aware of the " + \ "problem with the start of things." + \ "They wonder how the snowplough driver gets to work, or " + \ "how the makers of dictionaries look up the spelling of words." # (C) Terry Pratchet - Small Gods # Makes sure we round up to a complete block size data *= 512 with temporaryPath(perms=0o666, data=data) as srcPath: with temporaryPath(perms=0o666) as dstPath: # Copy rc, out, err = misc.ddWatchCopy(srcPath, dstPath, None, len(data)) # Get copied data with open(dstPath) as f: readData = f.read() # Comapre self.assertEquals(readData, data)
def testNonAlignedAppend(self): data = "ABCD" * 256 # 1Kb add_data = "E" repetitions = misc.MEGA / len(data) path = self._createDataFile(data, repetitions) try: with open(path, "a") as f: # Appending additional data f.write(add_data) self.assertEquals(os.stat(path).st_size, misc.MEGA + len(add_data)) # Using os.stat(path).st_size is part of the test, please do not # remove or change. rc, out, err = misc.ddWatchCopy( "/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) self.assertEquals(rc, 0) self.assertEquals(os.stat(path).st_size, misc.MEGA * 2 + len(add_data)) with open(path, "r") as f: for i in range(repetitions): self.assertEquals(f.read(len(data)), data) # Checking the additional data self.assertEquals(f.read(len(add_data)), add_data) finally: os.unlink(path)
def testNonAlignedCopy(self, sudo=False): """ Test that copying a file with odd length works. """ data = '- "What\'re quantum mechanics?"' + \ '- "I don\'t know. People who repair quantums, I suppose."' # (C) Terry Pratchet - Small Gods # Make sure the length is appropriate if (len(data) % 512) == 0: data += "!" with temporaryPath(perms=0o666, data=data) as srcPath: with temporaryPath(perms=0o666) as dstPath: # Copy rc, out, err = misc.ddWatchCopy(srcPath, dstPath, None, len(data)) # Get copied data with open(dstPath) as dp: readData = dp.read() # Compare self.assertEquals(readData, data)
def testCopy(self): """ Test that regular copying works. """ # Prepare source data = "Everything starts somewhere, " + \ "though many physicists disagree." + \ "But people have always been dimly aware of the " + \ "problem with the start of things." + \ "They wonder how the snowplough driver gets to work, or " + \ "how the makers of dictionaries look up the spelling of words." # (C) Terry Pratchet - Small Gods # Makes sure we round up to a complete block size data *= 512 with temporaryPath(perms=0o666, data=data) as srcPath: with temporaryPath(perms=0o666) as dstPath: # Copy rc, out, err = misc.ddWatchCopy(srcPath, dstPath, None, len(data)) # Get copied data readData = open(dstPath).read() # Comapre self.assertEquals(readData, data)
def testNonAlignedAppend(self): data = "ABCD" * 256 # 1Kb add_data = "E" repetitions = misc.MEGA / len(data) path = self._createDataFile(data, repetitions) try: with open(path, "a") as f: # Appending additional data f.write(add_data) self.assertEquals(os.stat(path).st_size, misc.MEGA + len(add_data)) # Using os.stat(path).st_size is part of the test, please do not # remove or change. rc, out, err = misc.ddWatchCopy( "/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) self.assertEquals(rc, 0) self.assertEquals(os.stat(path).st_size, misc.MEGA * 2 + len(add_data)) with open(path, "r") as f: for i in xrange(repetitions): self.assertEquals(f.read(len(data)), data) # Checking the additional data self.assertEquals(f.read(len(add_data)), add_data) finally: os.unlink(path)
def testAlignedAppend(self): data = "ABCD" * 256 # 1Kb repetitions = misc.MEGA / len(data) path = self._createDataFile(data, repetitions) try: # Using os.stat(path).st_size is part of the test, please do not # remove or change. rc, out, err = misc.ddWatchCopy( "/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) self.assertEquals(rc, 0) self.assertEquals(os.stat(path).st_size, misc.MEGA * 2) with open(path, "r") as f: for i in xrange(repetitions): self.assertEquals(f.read(len(data)), data) finally: os.unlink(path)
def testAlignedAppend(self): data = "ABCD" * 256 # 1Kb repetitions = misc.MEGA / len(data) path = self._createDataFile(data, repetitions) try: # Using os.stat(path).st_size is part of the test, please do not # remove or change. rc, out, err = misc.ddWatchCopy("/dev/zero", path, None, misc.MEGA, os.stat(path).st_size) self.assertEquals(rc, 0) self.assertEquals(os.stat(path).st_size, misc.MEGA * 2) with open(path, "r") as f: for i in range(repetitions): self.assertEquals(f.read(len(data)), data) finally: os.unlink(path)
def ddWatchCopy(srcPath, dstPath, callback, dataLen): rc, out, err = misc.ddWatchCopy(srcPath, dstPath, callback, dataLen) return rc, out, err