def test_deflated_file(self): """ Check that DeflatedFile.copy yields the proper content in the destination file in all situations that trigger different code paths (see TestFile.test_file) """ src = self.tmppath("src.jar") dest = self.tmppath("dest") contents = {} with JarWriter(src) as jar: for content in samples: name = "".join( random.choice( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ) for i in range(8) ) jar.add(name, content, compress=True) contents[name] = content for j in JarReader(src): f = DeflatedFile(j) f.copy(dest) self.assertEqual(contents[j.filename], open(dest, "rb").read())
def test_deflated_file(self): """ Check that DeflatedFile.copy yields the proper content in the destination file in all situations that trigger different code paths (see TestFile.test_file) """ src = self.tmppath("src.jar") dest = self.tmppath("dest") contents = {} with JarWriter(src) as jar: for content in samples: name = "".join(random.choice(string.letters) for i in xrange(8)) jar.add(name, content, compress=True) contents[name] = content for j in JarReader(src): f = DeflatedFile(j) f.copy(dest) self.assertEqual(contents[j.filename], open(dest, "rb").read())
def test_deflated_file(self): ''' Check that DeflatedFile.copy yields the proper content in the destination file in all situations that trigger different code paths (see TestFile.test_file) ''' src = self.tmppath('src.jar') dest = self.tmppath('dest') contents = {} with JarWriter(src) as jar: for content in samples: name = ''.join( random.choice(string.letters) for i in xrange(8)) jar.add(name, content, compress=True) contents[name] = content for j in JarReader(src): f = DeflatedFile(j) f.copy(dest) self.assertEqual(contents[j.filename], open(dest, 'rb').read())
def test_deflated_file_no_write(self): """ Test various conditions where DeflatedFile.copy is expected not to write in the destination file. """ src = self.tmppath("src.jar") dest = self.tmppath("dest") with JarWriter(src) as jar: jar.add("test", b"test") jar.add("test2", b"test") jar.add("fooo", b"fooo") jar = JarReader(src) # Initial copy f = DeflatedFile(jar["test"]) f.copy(dest) # Ensure subsequent copies won't trigger writes f.copy(DestNoWrite(dest)) self.assertEqual(b"test", open(dest, "rb").read()) # When using a different file with the same content, no copy should # occur f = DeflatedFile(jar["test2"]) f.copy(DestNoWrite(dest)) self.assertEqual(b"test", open(dest, "rb").read()) # Double check that under conditions where a copy occurs, we would get # an exception. f = DeflatedFile(jar["fooo"]) self.assertRaises(RuntimeError, f.copy, DestNoWrite(dest))
def test_deflated_file_no_write(self): ''' Test various conditions where DeflatedFile.copy is expected not to write in the destination file. ''' src = self.tmppath('src.jar') dest = self.tmppath('dest') with JarWriter(src) as jar: jar.add('test', 'test') jar.add('test2', 'test') jar.add('fooo', 'fooo') jar = JarReader(src) # Initial copy f = DeflatedFile(jar['test']) f.copy(dest) # Ensure subsequent copies won't trigger writes f.copy(DestNoWrite(dest)) self.assertEqual('test', open(dest, 'rb').read()) # When using a different file with the same content, no copy should # occur f = DeflatedFile(jar['test2']) f.copy(DestNoWrite(dest)) self.assertEqual('test', open(dest, 'rb').read()) # Double check that under conditions where a copy occurs, we would get # an exception. f = DeflatedFile(jar['fooo']) self.assertRaises(RuntimeError, f.copy, DestNoWrite(dest))
def test_deflated_file_no_write(self): ''' Test various conditions where DeflatedFile.copy is expected not to write in the destination file. ''' src = self.tmppath('src.jar') dest = self.tmppath('dest') with JarWriter(src) as jar: jar.add('test', 'test') jar.add('test2', 'test') jar.add('fooo', 'fooo') jar = JarReader(src) # Initial copy f = DeflatedFile(jar['test']) f.copy(dest) # Ensure subsequent copies won't trigger writes f.copy(DestNoWrite(dest)) self.assertEqual('test', open(dest, 'rb').read()) # When using a different file with the same content, no copy should # occur f = DeflatedFile(jar['test2']) f.copy(DestNoWrite(dest)) self.assertEqual('test', open(dest, 'rb').read()) # Double check that under conditions where a copy occurs, we would get # an exception. f = DeflatedFile(jar['fooo']) self.assertRaises(RuntimeError, f.copy, DestNoWrite(dest))
def test_deflated_file_no_write(self): """ Test various conditions where DeflatedFile.copy is expected not to write in the destination file. """ src = self.tmppath("src.jar") dest = self.tmppath("dest") with JarWriter(src) as jar: jar.add("test", "test") jar.add("test2", "test") jar.add("fooo", "fooo") jar = JarReader(src) # Initial copy f = DeflatedFile(jar["test"]) f.copy(dest) # Ensure subsequent copies won't trigger writes f.copy(DestNoWrite(dest)) self.assertEqual("test", open(dest, "rb").read()) # When using a different file with the same content, no copy should # occur f = DeflatedFile(jar["test2"]) f.copy(DestNoWrite(dest)) self.assertEqual("test", open(dest, "rb").read()) # Double check that under conditions where a copy occurs, we would get # an exception. f = DeflatedFile(jar["fooo"]) self.assertRaises(RuntimeError, f.copy, DestNoWrite(dest))