MCPcopy Index your code
hub / github.com/python/cpython / _do_copyish

Method _do_copyish

Lib/test/test_unicode_file.py:57–84  ·  view source on GitHub ↗
(self, filename1, filename2)

Source from the content-addressed store, hash-verified

55
56 # Tests that copy, move, etc one file to another.
57 def _do_copyish(self, filename1, filename2):
58 # Should be able to rename the file using either name.
59 self.assertTrue(os.path.isfile(filename1)) # must exist.
60 os.rename(filename1, filename2 + ".new")
61 self.assertFalse(os.path.isfile(filename2))
62 self.assertTrue(os.path.isfile(filename1 + '.new'))
63 os.rename(filename1 + ".new", filename2)
64 self.assertFalse(os.path.isfile(filename1 + '.new'))
65 self.assertTrue(os.path.isfile(filename2))
66
67 shutil.copy(filename1, filename2 + ".new")
68 os.unlink(filename1 + ".new") # remove using equiv name.
69 # And a couple of moves, one using each name.
70 shutil.move(filename1, filename2 + ".new")
71 self.assertFalse(os.path.exists(filename2))
72 self.assertTrue(os.path.exists(filename1 + '.new'))
73 shutil.move(filename1 + ".new", filename2)
74 self.assertFalse(os.path.exists(filename2 + '.new'))
75 self.assertTrue(os.path.exists(filename1))
76 # Note - due to the implementation of shutil.move,
77 # it tries a rename first. This only fails on Windows when on
78 # different file systems - and this test can't ensure that.
79 # So we test the shutil.copy2 function, which is the thing most
80 # likely to fail.
81 shutil.copy2(filename1, filename2 + ".new")
82 self.assertTrue(os.path.isfile(filename1 + '.new'))
83 os.unlink(filename1 + ".new")
84 self.assertFalse(os.path.exists(filename2 + '.new'))
85
86 def _do_directory(self, make_name, chdir_name):
87 if os.path.isdir(make_name):

Callers 1

_do_singleMethod · 0.95

Calls 8

assertTrueMethod · 0.80
assertFalseMethod · 0.80
isfileMethod · 0.45
renameMethod · 0.45
copyMethod · 0.45
unlinkMethod · 0.45
moveMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected