def test_basic(self): """copy_file: copy files into destdir, leaving existing contents""" files = self.makefiles("src/file1", "src/subdir/file2") self.makefiles("dest/file3") copy_files(files, self.destdir) result = set(os.listdir(self.destdir)) self.assertEqual(result, set(["file1", "file2", "file3"]))
def test_basic(self): """copy_file: copy files into destdir, leaving existing contents""" files = self.makefiles("src/file1", "src/subdir/file2") self.makefiles("dest/file3") copy_files(files, self.destdir, self.srcdir) result = set(listfiles(self.destdir)) self.assertEqual(result, set(["file1", "subdir/file2", "file3"]))
def test_copy_kernel(self): """copy_file: strip leading module directories""" files = self.makefiles("src/lib/modules/3.2.1-900.fc47.x86_64/kernel/subdir/module.ko", "src/lib/modules/3.2.1-900.fc47.x86_64/kernel/other.ko.xz") copy_files(files, self.destdir, self.srcdir+"/lib/modules") result = set(listfiles(self.destdir)) self.assertEqual(result, set(["subdir/module.ko", "other.ko.xz"]))
def test_samefile(self): """copy_file: skip files already in destdir""" (dest,) = self.makefiles("dest/file1") with open(dest, 'w') as outf: outf.write("destfile") copy_files([dest], self.destdir) self.assertEqual(os.listdir(self.destdir), ["file1"]) self.assertEqual(open(dest).read(), "destfile")
def test_samefile(self): """copy_file: skip files already in destdir""" (dest, ) = self.makefiles("dest/file1") with open(dest, 'w') as outf: outf.write("destfile") copy_files([dest], self.destdir, "src") self.assertEqual(list(listfiles(self.destdir)), ["file1"]) self.assertEqual(open(dest).read(), "destfile")
def test_overwrite(self): """copy_file: overwrite files in destdir if they have the same name""" src, dest = self.makefiles("src/file1", "dest/file1") with open(src, 'w') as outf: outf.write("srcfile") with open(dest, 'w') as outf: outf.write("destfile") copy_files([src], self.destdir) self.assertEqual(os.listdir(self.destdir), ["file1"]) self.assertEqual(open(dest).read(), "srcfile")
def test_overwrite(self): """copy_file: overwrite files in destdir if they have the same name""" src, dest = self.makefiles("src/file1", "dest/file1") with open(src, 'w') as outf: outf.write("srcfile") with open(dest, 'w') as outf: outf.write("destfile") copy_files([src], self.destdir, self.srcdir) self.assertEqual(list(listfiles(self.destdir)), ["file1"]) self.assertEqual(open(dest).read(), "srcfile")
def test_copy_to_parent(self): """copy_file: skip files in subdirs of destdir""" files = self.makefiles("dest/subdir/file1") copy_files(files, self.destdir) self.assertEqual(list(iter_files(self.destdir)), files)
def test_copy_to_parent(self): """copy_file: skip files in subdirs of destdir""" files = self.makefiles("dest/subdir/file1") copy_files(files, self.destdir, "src") self.assertEqual(list(iter_files(self.destdir)), files)