blob: 1a016b90ddf113341f3c89caa1def89d1860e140 [file] [log] [blame]
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00001# Copyright (C) 2003 Python Software Foundation
2
3import unittest
4import shutil
5import tempfile
Johannes Gijsbers8e6f2de2004-11-23 09:27:27 +00006import sys
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +00007import stat
Brett Cannon1c3fa182004-06-19 21:11:35 +00008import os
9import os.path
Nick Coghlan8ed3cf32011-03-16 14:05:35 -040010import functools
Ned Deily5fddf862012-05-10 17:21:23 -070011import errno
Benjamin Petersonee8712c2008-05-20 21:35:26 +000012from test import support
13from test.support import TESTFN
Tarek Ziadé396fad72010-02-23 05:30:31 +000014from os.path import splitdrive
15from distutils.spawn import find_executable, spawn
16from shutil import (_make_tarball, _make_zipfile, make_archive,
17 register_archive_format, unregister_archive_format,
Tarek Ziadé6ac91722010-04-28 17:51:36 +000018 get_archive_formats, Error, unpack_archive,
19 register_unpack_format, RegistryError,
20 unregister_unpack_format, get_unpack_formats)
Tarek Ziadé396fad72010-02-23 05:30:31 +000021import tarfile
22import warnings
23
24from test import support
25from test.support import TESTFN, check_warnings, captured_stdout
26
Tarek Ziadéffa155a2010-04-29 13:34:35 +000027try:
28 import bz2
29 BZ2_SUPPORTED = True
30except ImportError:
31 BZ2_SUPPORTED = False
32
Antoine Pitrou7fff0962009-05-01 21:09:44 +000033TESTFN2 = TESTFN + "2"
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000034
Tarek Ziadé396fad72010-02-23 05:30:31 +000035try:
36 import grp
37 import pwd
38 UID_GID_SUPPORT = True
39except ImportError:
40 UID_GID_SUPPORT = False
41
42try:
43 import zlib
44except ImportError:
45 zlib = None
46
47try:
48 import zipfile
49 ZIP_SUPPORT = True
50except ImportError:
51 ZIP_SUPPORT = find_executable('zip')
52
Nick Coghlan8ed3cf32011-03-16 14:05:35 -040053def _fake_rename(*args, **kwargs):
54 # Pretend the destination path is on a different filesystem.
55 raise OSError()
56
57def mock_rename(func):
58 @functools.wraps(func)
59 def wrap(*args, **kwargs):
60 try:
61 builtin_rename = os.rename
62 os.rename = _fake_rename
63 return func(*args, **kwargs)
64 finally:
65 os.rename = builtin_rename
66 return wrap
67
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000068class TestShutil(unittest.TestCase):
Tarek Ziadé396fad72010-02-23 05:30:31 +000069
70 def setUp(self):
71 super(TestShutil, self).setUp()
72 self.tempdirs = []
73
74 def tearDown(self):
75 super(TestShutil, self).tearDown()
76 while self.tempdirs:
77 d = self.tempdirs.pop()
78 shutil.rmtree(d, os.name in ('nt', 'cygwin'))
79
80 def write_file(self, path, content='xxx'):
81 """Writes a file in the given path.
82
83
84 path can be a string or a sequence.
85 """
86 if isinstance(path, (list, tuple)):
87 path = os.path.join(*path)
88 f = open(path, 'w')
89 try:
90 f.write(content)
91 finally:
92 f.close()
93
94 def mkdtemp(self):
95 """Create a temporary directory that will be cleaned up.
96
97 Returns the path of the directory.
98 """
99 d = tempfile.mkdtemp()
100 self.tempdirs.append(d)
101 return d
Tarek Ziadé5340db32010-04-19 22:30:51 +0000102
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000103 def test_rmtree_errors(self):
104 # filename is guaranteed not to exist
105 filename = tempfile.mktemp()
106 self.assertRaises(OSError, shutil.rmtree, filename)
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000107
Johannes Gijsbersb8b09d02004-12-06 20:50:15 +0000108 # See bug #1071513 for why we don't run this on cygwin
109 # and bug #1076467 for why we don't run this as root.
110 if (hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin'
Johannes Gijsbers6b220b02004-12-12 15:52:57 +0000111 and not (hasattr(os, 'geteuid') and os.geteuid() == 0)):
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000112 def test_on_error(self):
113 self.errorState = 0
114 os.mkdir(TESTFN)
Tim Peters4590c002004-11-01 02:40:52 +0000115 self.childpath = os.path.join(TESTFN, 'a')
116 f = open(self.childpath, 'w')
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000117 f.close()
Tim Peters4590c002004-11-01 02:40:52 +0000118 old_dir_mode = os.stat(TESTFN).st_mode
119 old_child_mode = os.stat(self.childpath).st_mode
120 # Make unwritable.
121 os.chmod(self.childpath, stat.S_IREAD)
122 os.chmod(TESTFN, stat.S_IREAD)
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000123
124 shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
Johannes Gijsbers8e6f2de2004-11-23 09:27:27 +0000125 # Test whether onerror has actually been called.
Johannes Gijsbersb8b09d02004-12-06 20:50:15 +0000126 self.assertEqual(self.errorState, 2,
127 "Expected call to onerror function did not happen.")
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000128
Tim Peters4590c002004-11-01 02:40:52 +0000129 # Make writable again.
130 os.chmod(TESTFN, old_dir_mode)
131 os.chmod(self.childpath, old_child_mode)
132
133 # Clean up.
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000134 shutil.rmtree(TESTFN)
135
136 def check_args_to_onerror(self, func, arg, exc):
Benjamin Peterson25c95f12009-05-08 20:42:26 +0000137 # test_rmtree_errors deliberately runs rmtree
138 # on a directory that is chmod 400, which will fail.
139 # This function is run when shutil.rmtree fails.
140 # 99.9% of the time it initially fails to remove
141 # a file in the directory, so the first time through
142 # func is os.remove.
143 # However, some Linux machines running ZFS on
144 # FUSE experienced a failure earlier in the process
145 # at os.listdir. The first failure may legally
146 # be either.
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000147 if self.errorState == 0:
Benjamin Peterson25c95f12009-05-08 20:42:26 +0000148 if func is os.remove:
149 self.assertEqual(arg, self.childpath)
150 else:
151 self.assertIs(func, os.listdir,
152 "func must be either os.remove or os.listdir")
153 self.assertEqual(arg, TESTFN)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000154 self.assertTrue(issubclass(exc[0], OSError))
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000155 self.errorState = 1
156 else:
157 self.assertEqual(func, os.rmdir)
158 self.assertEqual(arg, TESTFN)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000159 self.assertTrue(issubclass(exc[0], OSError))
Johannes Gijsbers8e6f2de2004-11-23 09:27:27 +0000160 self.errorState = 2
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000161
Johannes Gijsbersd60e92a2004-09-11 21:26:21 +0000162 def test_rmtree_dont_delete_file(self):
163 # When called on a file instead of a directory, don't delete it.
164 handle, path = tempfile.mkstemp()
165 os.fdopen(handle).close()
166 self.assertRaises(OSError, shutil.rmtree, path)
167 os.remove(path)
168
Tarek Ziadé5340db32010-04-19 22:30:51 +0000169 def _write_data(self, path, data):
170 f = open(path, "w")
171 f.write(data)
172 f.close()
173
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000174 def test_copytree_simple(self):
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000175
176 def read_data(path):
177 f = open(path)
178 data = f.read()
179 f.close()
180 return data
181
182 src_dir = tempfile.mkdtemp()
183 dst_dir = os.path.join(tempfile.mkdtemp(), 'destination')
Tarek Ziadé5340db32010-04-19 22:30:51 +0000184 self._write_data(os.path.join(src_dir, 'test.txt'), '123')
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000185 os.mkdir(os.path.join(src_dir, 'test_dir'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000186 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000187
188 try:
189 shutil.copytree(src_dir, dst_dir)
190 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
191 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
192 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir',
193 'test.txt')))
194 actual = read_data(os.path.join(dst_dir, 'test.txt'))
195 self.assertEqual(actual, '123')
196 actual = read_data(os.path.join(dst_dir, 'test_dir', 'test.txt'))
197 self.assertEqual(actual, '456')
198 finally:
199 for path in (
200 os.path.join(src_dir, 'test.txt'),
201 os.path.join(dst_dir, 'test.txt'),
202 os.path.join(src_dir, 'test_dir', 'test.txt'),
203 os.path.join(dst_dir, 'test_dir', 'test.txt'),
204 ):
205 if os.path.exists(path):
206 os.remove(path)
Christian Heimese052dd82007-11-20 03:20:04 +0000207 for path in (src_dir,
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000208 os.path.dirname(dst_dir)
Christian Heimese052dd82007-11-20 03:20:04 +0000209 ):
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000210 if os.path.exists(path):
Christian Heimes94140152007-11-20 01:45:17 +0000211 shutil.rmtree(path)
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000212
Georg Brandl2ee470f2008-07-16 12:55:28 +0000213 def test_copytree_with_exclude(self):
214
Georg Brandl2ee470f2008-07-16 12:55:28 +0000215 def read_data(path):
216 f = open(path)
217 data = f.read()
218 f.close()
219 return data
220
221 # creating data
222 join = os.path.join
223 exists = os.path.exists
224 src_dir = tempfile.mkdtemp()
Georg Brandl2ee470f2008-07-16 12:55:28 +0000225 try:
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000226 dst_dir = join(tempfile.mkdtemp(), 'destination')
Tarek Ziadé5340db32010-04-19 22:30:51 +0000227 self._write_data(join(src_dir, 'test.txt'), '123')
228 self._write_data(join(src_dir, 'test.tmp'), '123')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000229 os.mkdir(join(src_dir, 'test_dir'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000230 self._write_data(join(src_dir, 'test_dir', 'test.txt'), '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000231 os.mkdir(join(src_dir, 'test_dir2'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000232 self._write_data(join(src_dir, 'test_dir2', 'test.txt'), '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000233 os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
234 os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000235 self._write_data(join(src_dir, 'test_dir2', 'subdir', 'test.txt'),
236 '456')
237 self._write_data(join(src_dir, 'test_dir2', 'subdir2', 'test.py'),
238 '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000239
240
241 # testing glob-like patterns
242 try:
243 patterns = shutil.ignore_patterns('*.tmp', 'test_dir2')
244 shutil.copytree(src_dir, dst_dir, ignore=patterns)
245 # checking the result: some elements should not be copied
246 self.assertTrue(exists(join(dst_dir, 'test.txt')))
247 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
248 self.assertTrue(not exists(join(dst_dir, 'test_dir2')))
249 finally:
250 if os.path.exists(dst_dir):
251 shutil.rmtree(dst_dir)
252 try:
253 patterns = shutil.ignore_patterns('*.tmp', 'subdir*')
254 shutil.copytree(src_dir, dst_dir, ignore=patterns)
255 # checking the result: some elements should not be copied
256 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
257 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
258 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
259 finally:
260 if os.path.exists(dst_dir):
261 shutil.rmtree(dst_dir)
262
263 # testing callable-style
264 try:
265 def _filter(src, names):
266 res = []
267 for name in names:
268 path = os.path.join(src, name)
269
270 if (os.path.isdir(path) and
271 path.split()[-1] == 'subdir'):
272 res.append(name)
273 elif os.path.splitext(path)[-1] in ('.py'):
274 res.append(name)
275 return res
276
277 shutil.copytree(src_dir, dst_dir, ignore=_filter)
278
279 # checking the result: some elements should not be copied
280 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2',
281 'test.py')))
282 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
283
284 finally:
285 if os.path.exists(dst_dir):
286 shutil.rmtree(dst_dir)
Georg Brandl2ee470f2008-07-16 12:55:28 +0000287 finally:
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000288 shutil.rmtree(src_dir)
289 shutil.rmtree(os.path.dirname(dst_dir))
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000290
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000291 @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000292 def test_dont_copy_file_onto_link_to_itself(self):
Georg Brandl724d0892010-12-05 07:51:39 +0000293 # Temporarily disable test on Windows.
294 if os.name == 'nt':
295 return
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000296 # bug 851123.
297 os.mkdir(TESTFN)
298 src = os.path.join(TESTFN, 'cheese')
299 dst = os.path.join(TESTFN, 'shop')
300 try:
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000301 with open(src, 'w') as f:
302 f.write('cheddar')
303 os.link(src, dst)
304 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
305 with open(src, 'r') as f:
306 self.assertEqual(f.read(), 'cheddar')
307 os.remove(dst)
308 finally:
309 shutil.rmtree(TESTFN, ignore_errors=True)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000310
Ned Deily5fddf862012-05-10 17:21:23 -0700311 @unittest.skipUnless(hasattr(os, 'chflags') and
312 hasattr(errno, 'EOPNOTSUPP') and
313 hasattr(errno, 'ENOTSUP'),
314 "requires os.chflags, EOPNOTSUPP & ENOTSUP")
315 def test_copystat_handles_harmless_chflags_errors(self):
316 tmpdir = self.mkdtemp()
317 file1 = os.path.join(tmpdir, 'file1')
318 file2 = os.path.join(tmpdir, 'file2')
319 self.write_file(file1, 'xxx')
320 self.write_file(file2, 'xxx')
321
322 def make_chflags_raiser(err):
323 ex = OSError()
324
325 def _chflags_raiser(path, flags):
326 ex.errno = err
327 raise ex
328 return _chflags_raiser
329 old_chflags = os.chflags
330 try:
331 for err in errno.EOPNOTSUPP, errno.ENOTSUP:
332 os.chflags = make_chflags_raiser(err)
333 shutil.copystat(file1, file2)
334 # assert others errors break it
335 os.chflags = make_chflags_raiser(errno.EOPNOTSUPP + errno.ENOTSUP)
336 self.assertRaises(OSError, shutil.copystat, file1, file2)
337 finally:
338 os.chflags = old_chflags
339
Brian Curtin3b4499c2010-12-28 14:31:47 +0000340 @support.skip_unless_symlink
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000341 def test_dont_copy_file_onto_symlink_to_itself(self):
342 # bug 851123.
343 os.mkdir(TESTFN)
344 src = os.path.join(TESTFN, 'cheese')
345 dst = os.path.join(TESTFN, 'shop')
346 try:
347 with open(src, 'w') as f:
348 f.write('cheddar')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000349 # Using `src` here would mean we end up with a symlink pointing
350 # to TESTFN/TESTFN/cheese, while it should point at
351 # TESTFN/cheese.
352 os.symlink('cheese', dst)
353 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000354 with open(src, 'r') as f:
355 self.assertEqual(f.read(), 'cheddar')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000356 os.remove(dst)
357 finally:
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000358 shutil.rmtree(TESTFN, ignore_errors=True)
Johannes Gijsbers68128712004-08-14 13:57:08 +0000359
Brian Curtin3b4499c2010-12-28 14:31:47 +0000360 @support.skip_unless_symlink
Brian Curtind40e6f72010-07-08 21:39:08 +0000361 def test_rmtree_on_symlink(self):
362 # bug 1669.
363 os.mkdir(TESTFN)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000364 try:
Brian Curtind40e6f72010-07-08 21:39:08 +0000365 src = os.path.join(TESTFN, 'cheese')
366 dst = os.path.join(TESTFN, 'shop')
367 os.mkdir(src)
368 os.symlink(src, dst)
369 self.assertRaises(OSError, shutil.rmtree, dst)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000370 finally:
Brian Curtind40e6f72010-07-08 21:39:08 +0000371 shutil.rmtree(TESTFN, ignore_errors=True)
372
373 if hasattr(os, "mkfifo"):
374 # Issue #3002: copyfile and copytree block indefinitely on named pipes
375 def test_copyfile_named_pipe(self):
376 os.mkfifo(TESTFN)
377 try:
378 self.assertRaises(shutil.SpecialFileError,
379 shutil.copyfile, TESTFN, TESTFN2)
380 self.assertRaises(shutil.SpecialFileError,
381 shutil.copyfile, __file__, TESTFN)
382 finally:
383 os.remove(TESTFN)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000384
Brian Curtin3b4499c2010-12-28 14:31:47 +0000385 @support.skip_unless_symlink
Brian Curtin52173d42010-12-02 18:29:18 +0000386 def test_copytree_named_pipe(self):
387 os.mkdir(TESTFN)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000388 try:
Brian Curtin52173d42010-12-02 18:29:18 +0000389 subdir = os.path.join(TESTFN, "subdir")
390 os.mkdir(subdir)
391 pipe = os.path.join(subdir, "mypipe")
392 os.mkfifo(pipe)
393 try:
394 shutil.copytree(TESTFN, TESTFN2)
395 except shutil.Error as e:
396 errors = e.args[0]
397 self.assertEqual(len(errors), 1)
398 src, dst, error_msg = errors[0]
399 self.assertEqual("`%s` is a named pipe" % pipe, error_msg)
400 else:
401 self.fail("shutil.Error should have been raised")
402 finally:
403 shutil.rmtree(TESTFN, ignore_errors=True)
404 shutil.rmtree(TESTFN2, ignore_errors=True)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000405
Tarek Ziadé5340db32010-04-19 22:30:51 +0000406 def test_copytree_special_func(self):
407
408 src_dir = self.mkdtemp()
409 dst_dir = os.path.join(self.mkdtemp(), 'destination')
410 self._write_data(os.path.join(src_dir, 'test.txt'), '123')
411 os.mkdir(os.path.join(src_dir, 'test_dir'))
412 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
413
414 copied = []
415 def _copy(src, dst):
416 copied.append((src, dst))
417
418 shutil.copytree(src_dir, dst_dir, copy_function=_copy)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000419 self.assertEqual(len(copied), 2)
Tarek Ziadé5340db32010-04-19 22:30:51 +0000420
Brian Curtin3b4499c2010-12-28 14:31:47 +0000421 @support.skip_unless_symlink
Tarek Ziadéfb437512010-04-20 08:57:33 +0000422 def test_copytree_dangling_symlinks(self):
423
424 # a dangling symlink raises an error at the end
425 src_dir = self.mkdtemp()
426 dst_dir = os.path.join(self.mkdtemp(), 'destination')
427 os.symlink('IDONTEXIST', os.path.join(src_dir, 'test.txt'))
428 os.mkdir(os.path.join(src_dir, 'test_dir'))
429 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
430 self.assertRaises(Error, shutil.copytree, src_dir, dst_dir)
431
432 # a dangling symlink is ignored with the proper flag
433 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
434 shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True)
435 self.assertNotIn('test.txt', os.listdir(dst_dir))
436
437 # a dangling symlink is copied if symlinks=True
438 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
439 shutil.copytree(src_dir, dst_dir, symlinks=True)
440 self.assertIn('test.txt', os.listdir(dst_dir))
441
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400442 def _copy_file(self, method):
443 fname = 'test.txt'
444 tmpdir = self.mkdtemp()
445 self.write_file([tmpdir, fname])
446 file1 = os.path.join(tmpdir, fname)
447 tmpdir2 = self.mkdtemp()
448 method(file1, tmpdir2)
449 file2 = os.path.join(tmpdir2, fname)
450 return (file1, file2)
451
452 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
453 def test_copy(self):
454 # Ensure that the copied file exists and has the same mode bits.
455 file1, file2 = self._copy_file(shutil.copy)
456 self.assertTrue(os.path.exists(file2))
457 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)
458
459 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
Senthil Kumaran0c2dba52011-07-03 18:21:38 -0700460 @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime')
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400461 def test_copy2(self):
462 # Ensure that the copied file exists and has the same mode and
463 # modification time bits.
464 file1, file2 = self._copy_file(shutil.copy2)
465 self.assertTrue(os.path.exists(file2))
466 file1_stat = os.stat(file1)
467 file2_stat = os.stat(file2)
468 self.assertEqual(file1_stat.st_mode, file2_stat.st_mode)
469 for attr in 'st_atime', 'st_mtime':
470 # The modification times may be truncated in the new file.
471 self.assertLessEqual(getattr(file1_stat, attr),
472 getattr(file2_stat, attr) + 1)
473 if hasattr(os, 'chflags') and hasattr(file1_stat, 'st_flags'):
474 self.assertEqual(getattr(file1_stat, 'st_flags'),
475 getattr(file2_stat, 'st_flags'))
476
Tarek Ziadé396fad72010-02-23 05:30:31 +0000477 @unittest.skipUnless(zlib, "requires zlib")
478 def test_make_tarball(self):
479 # creating something to tar
480 tmpdir = self.mkdtemp()
481 self.write_file([tmpdir, 'file1'], 'xxx')
482 self.write_file([tmpdir, 'file2'], 'xxx')
483 os.mkdir(os.path.join(tmpdir, 'sub'))
484 self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
485
486 tmpdir2 = self.mkdtemp()
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400487 # force shutil to create the directory
488 os.rmdir(tmpdir2)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000489 unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
490 "source and target should be on same drive")
491
492 base_name = os.path.join(tmpdir2, 'archive')
493
494 # working with relative paths to avoid tar warnings
495 old_dir = os.getcwd()
496 os.chdir(tmpdir)
497 try:
498 _make_tarball(splitdrive(base_name)[1], '.')
499 finally:
500 os.chdir(old_dir)
501
502 # check if the compressed tarball was created
503 tarball = base_name + '.tar.gz'
504 self.assertTrue(os.path.exists(tarball))
505
506 # trying an uncompressed one
507 base_name = os.path.join(tmpdir2, 'archive')
508 old_dir = os.getcwd()
509 os.chdir(tmpdir)
510 try:
511 _make_tarball(splitdrive(base_name)[1], '.', compress=None)
512 finally:
513 os.chdir(old_dir)
514 tarball = base_name + '.tar'
515 self.assertTrue(os.path.exists(tarball))
516
517 def _tarinfo(self, path):
518 tar = tarfile.open(path)
519 try:
520 names = tar.getnames()
521 names.sort()
522 return tuple(names)
523 finally:
524 tar.close()
525
526 def _create_files(self):
527 # creating something to tar
528 tmpdir = self.mkdtemp()
529 dist = os.path.join(tmpdir, 'dist')
530 os.mkdir(dist)
531 self.write_file([dist, 'file1'], 'xxx')
532 self.write_file([dist, 'file2'], 'xxx')
533 os.mkdir(os.path.join(dist, 'sub'))
534 self.write_file([dist, 'sub', 'file3'], 'xxx')
535 os.mkdir(os.path.join(dist, 'sub2'))
536 tmpdir2 = self.mkdtemp()
537 base_name = os.path.join(tmpdir2, 'archive')
538 return tmpdir, tmpdir2, base_name
539
540 @unittest.skipUnless(zlib, "Requires zlib")
541 @unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
542 'Need the tar command to run')
543 def test_tarfile_vs_tar(self):
544 tmpdir, tmpdir2, base_name = self._create_files()
545 old_dir = os.getcwd()
546 os.chdir(tmpdir)
547 try:
548 _make_tarball(base_name, 'dist')
549 finally:
550 os.chdir(old_dir)
551
552 # check if the compressed tarball was created
553 tarball = base_name + '.tar.gz'
554 self.assertTrue(os.path.exists(tarball))
555
556 # now create another tarball using `tar`
557 tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
558 tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
559 gzip_cmd = ['gzip', '-f9', 'archive2.tar']
560 old_dir = os.getcwd()
561 os.chdir(tmpdir)
562 try:
563 with captured_stdout() as s:
564 spawn(tar_cmd)
565 spawn(gzip_cmd)
566 finally:
567 os.chdir(old_dir)
568
569 self.assertTrue(os.path.exists(tarball2))
570 # let's compare both tarballs
Ezio Melottib3aedd42010-11-20 19:04:17 +0000571 self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
Tarek Ziadé396fad72010-02-23 05:30:31 +0000572
573 # trying an uncompressed one
574 base_name = os.path.join(tmpdir2, 'archive')
575 old_dir = os.getcwd()
576 os.chdir(tmpdir)
577 try:
578 _make_tarball(base_name, 'dist', compress=None)
579 finally:
580 os.chdir(old_dir)
581 tarball = base_name + '.tar'
582 self.assertTrue(os.path.exists(tarball))
583
584 # now for a dry_run
585 base_name = os.path.join(tmpdir2, 'archive')
586 old_dir = os.getcwd()
587 os.chdir(tmpdir)
588 try:
589 _make_tarball(base_name, 'dist', compress=None, dry_run=True)
590 finally:
591 os.chdir(old_dir)
592 tarball = base_name + '.tar'
593 self.assertTrue(os.path.exists(tarball))
594
Tarek Ziadé396fad72010-02-23 05:30:31 +0000595 @unittest.skipUnless(zlib, "Requires zlib")
596 @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
597 def test_make_zipfile(self):
598 # creating something to tar
599 tmpdir = self.mkdtemp()
600 self.write_file([tmpdir, 'file1'], 'xxx')
601 self.write_file([tmpdir, 'file2'], 'xxx')
602
603 tmpdir2 = self.mkdtemp()
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400604 # force shutil to create the directory
605 os.rmdir(tmpdir2)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000606 base_name = os.path.join(tmpdir2, 'archive')
607 _make_zipfile(base_name, tmpdir)
608
609 # check if the compressed tarball was created
610 tarball = base_name + '.zip'
Éric Araujo1c505492010-11-06 02:12:51 +0000611 self.assertTrue(os.path.exists(tarball))
Tarek Ziadé396fad72010-02-23 05:30:31 +0000612
613
614 def test_make_archive(self):
615 tmpdir = self.mkdtemp()
616 base_name = os.path.join(tmpdir, 'archive')
617 self.assertRaises(ValueError, make_archive, base_name, 'xxx')
618
619 @unittest.skipUnless(zlib, "Requires zlib")
620 def test_make_archive_owner_group(self):
621 # testing make_archive with owner and group, with various combinations
622 # this works even if there's not gid/uid support
623 if UID_GID_SUPPORT:
624 group = grp.getgrgid(0)[0]
625 owner = pwd.getpwuid(0)[0]
626 else:
627 group = owner = 'root'
628
629 base_dir, root_dir, base_name = self._create_files()
630 base_name = os.path.join(self.mkdtemp() , 'archive')
631 res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
632 group=group)
633 self.assertTrue(os.path.exists(res))
634
635 res = make_archive(base_name, 'zip', root_dir, base_dir)
636 self.assertTrue(os.path.exists(res))
637
638 res = make_archive(base_name, 'tar', root_dir, base_dir,
639 owner=owner, group=group)
640 self.assertTrue(os.path.exists(res))
641
642 res = make_archive(base_name, 'tar', root_dir, base_dir,
643 owner='kjhkjhkjg', group='oihohoh')
644 self.assertTrue(os.path.exists(res))
645
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000646
Tarek Ziadé396fad72010-02-23 05:30:31 +0000647 @unittest.skipUnless(zlib, "Requires zlib")
648 @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
649 def test_tarfile_root_owner(self):
650 tmpdir, tmpdir2, base_name = self._create_files()
651 old_dir = os.getcwd()
652 os.chdir(tmpdir)
653 group = grp.getgrgid(0)[0]
654 owner = pwd.getpwuid(0)[0]
655 try:
656 archive_name = _make_tarball(base_name, 'dist', compress=None,
657 owner=owner, group=group)
658 finally:
659 os.chdir(old_dir)
660
661 # check if the compressed tarball was created
662 self.assertTrue(os.path.exists(archive_name))
663
664 # now checks the rights
665 archive = tarfile.open(archive_name)
666 try:
667 for member in archive.getmembers():
Ezio Melottib3aedd42010-11-20 19:04:17 +0000668 self.assertEqual(member.uid, 0)
669 self.assertEqual(member.gid, 0)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000670 finally:
671 archive.close()
672
673 def test_make_archive_cwd(self):
674 current_dir = os.getcwd()
675 def _breaks(*args, **kw):
676 raise RuntimeError()
677
678 register_archive_format('xxx', _breaks, [], 'xxx file')
679 try:
680 try:
681 make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
682 except Exception:
683 pass
Ezio Melottib3aedd42010-11-20 19:04:17 +0000684 self.assertEqual(os.getcwd(), current_dir)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000685 finally:
686 unregister_archive_format('xxx')
687
688 def test_register_archive_format(self):
689
690 self.assertRaises(TypeError, register_archive_format, 'xxx', 1)
691 self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
692 1)
693 self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
694 [(1, 2), (1, 2, 3)])
695
696 register_archive_format('xxx', lambda: x, [(1, 2)], 'xxx file')
697 formats = [name for name, params in get_archive_formats()]
698 self.assertIn('xxx', formats)
699
700 unregister_archive_format('xxx')
701 formats = [name for name, params in get_archive_formats()]
702 self.assertNotIn('xxx', formats)
703
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000704 def _compare_dirs(self, dir1, dir2):
705 # check that dir1 and dir2 are equivalent,
706 # return the diff
707 diff = []
708 for root, dirs, files in os.walk(dir1):
709 for file_ in files:
710 path = os.path.join(root, file_)
711 target_path = os.path.join(dir2, os.path.split(path)[-1])
712 if not os.path.exists(target_path):
713 diff.append(file_)
714 return diff
715
716 @unittest.skipUnless(zlib, "Requires zlib")
717 def test_unpack_archive(self):
Tarek Ziadéffa155a2010-04-29 13:34:35 +0000718 formats = ['tar', 'gztar', 'zip']
719 if BZ2_SUPPORTED:
720 formats.append('bztar')
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000721
Tarek Ziadéffa155a2010-04-29 13:34:35 +0000722 for format in formats:
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000723 tmpdir = self.mkdtemp()
724 base_dir, root_dir, base_name = self._create_files()
725 tmpdir2 = self.mkdtemp()
726 filename = make_archive(base_name, format, root_dir, base_dir)
727
728 # let's try to unpack it now
729 unpack_archive(filename, tmpdir2)
730 diff = self._compare_dirs(tmpdir, tmpdir2)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000731 self.assertEqual(diff, [])
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000732
Nick Coghlanabf202d2011-03-16 13:52:20 -0400733 # and again, this time with the format specified
734 tmpdir3 = self.mkdtemp()
735 unpack_archive(filename, tmpdir3, format=format)
736 diff = self._compare_dirs(tmpdir, tmpdir3)
737 self.assertEqual(diff, [])
738 self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
739 self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
740
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000741 def test_unpack_registery(self):
742
743 formats = get_unpack_formats()
744
745 def _boo(filename, extract_dir, extra):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000746 self.assertEqual(extra, 1)
747 self.assertEqual(filename, 'stuff.boo')
748 self.assertEqual(extract_dir, 'xx')
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000749
750 register_unpack_format('Boo', ['.boo', '.b2'], _boo, [('extra', 1)])
751 unpack_archive('stuff.boo', 'xx')
752
753 # trying to register a .boo unpacker again
754 self.assertRaises(RegistryError, register_unpack_format, 'Boo2',
755 ['.boo'], _boo)
756
757 # should work now
758 unregister_unpack_format('Boo')
759 register_unpack_format('Boo2', ['.boo'], _boo)
760 self.assertIn(('Boo2', ['.boo'], ''), get_unpack_formats())
761 self.assertNotIn(('Boo', ['.boo'], ''), get_unpack_formats())
762
763 # let's leave a clean state
764 unregister_unpack_format('Boo2')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000765 self.assertEqual(get_unpack_formats(), formats)
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000766
Christian Heimes9bd667a2008-01-20 15:14:11 +0000767
Christian Heimesada8c3b2008-03-18 18:26:33 +0000768class TestMove(unittest.TestCase):
769
770 def setUp(self):
771 filename = "foo"
772 self.src_dir = tempfile.mkdtemp()
773 self.dst_dir = tempfile.mkdtemp()
774 self.src_file = os.path.join(self.src_dir, filename)
775 self.dst_file = os.path.join(self.dst_dir, filename)
Christian Heimesada8c3b2008-03-18 18:26:33 +0000776 with open(self.src_file, "wb") as f:
777 f.write(b"spam")
778
779 def tearDown(self):
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400780 for d in (self.src_dir, self.dst_dir):
Christian Heimesada8c3b2008-03-18 18:26:33 +0000781 try:
782 if d:
783 shutil.rmtree(d)
784 except:
785 pass
786
787 def _check_move_file(self, src, dst, real_dst):
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000788 with open(src, "rb") as f:
789 contents = f.read()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000790 shutil.move(src, dst)
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000791 with open(real_dst, "rb") as f:
792 self.assertEqual(contents, f.read())
Christian Heimesada8c3b2008-03-18 18:26:33 +0000793 self.assertFalse(os.path.exists(src))
794
795 def _check_move_dir(self, src, dst, real_dst):
796 contents = sorted(os.listdir(src))
797 shutil.move(src, dst)
798 self.assertEqual(contents, sorted(os.listdir(real_dst)))
799 self.assertFalse(os.path.exists(src))
800
801 def test_move_file(self):
802 # Move a file to another location on the same filesystem.
803 self._check_move_file(self.src_file, self.dst_file, self.dst_file)
804
805 def test_move_file_to_dir(self):
806 # Move a file inside an existing dir on the same filesystem.
807 self._check_move_file(self.src_file, self.dst_dir, self.dst_file)
808
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400809 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000810 def test_move_file_other_fs(self):
811 # Move a file to an existing dir on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400812 self.test_move_file()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000813
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400814 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000815 def test_move_file_to_dir_other_fs(self):
816 # Move a file to another location on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400817 self.test_move_file_to_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000818
819 def test_move_dir(self):
820 # Move a dir to another location on the same filesystem.
821 dst_dir = tempfile.mktemp()
822 try:
823 self._check_move_dir(self.src_dir, dst_dir, dst_dir)
824 finally:
825 try:
826 shutil.rmtree(dst_dir)
827 except:
828 pass
829
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400830 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000831 def test_move_dir_other_fs(self):
832 # Move a dir to another location on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400833 self.test_move_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000834
835 def test_move_dir_to_dir(self):
836 # Move a dir inside an existing dir on the same filesystem.
837 self._check_move_dir(self.src_dir, self.dst_dir,
838 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
839
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400840 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000841 def test_move_dir_to_dir_other_fs(self):
842 # Move a dir inside an existing dir on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400843 self.test_move_dir_to_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000844
845 def test_existing_file_inside_dest_dir(self):
846 # A file with the same name inside the destination dir already exists.
847 with open(self.dst_file, "wb"):
848 pass
849 self.assertRaises(shutil.Error, shutil.move, self.src_file, self.dst_dir)
850
851 def test_dont_move_dir_in_itself(self):
852 # Moving a dir inside itself raises an Error.
853 dst = os.path.join(self.src_dir, "bar")
854 self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst)
855
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000856 def test_destinsrc_false_negative(self):
857 os.mkdir(TESTFN)
858 try:
859 for src, dst in [('srcdir', 'srcdir/dest')]:
860 src = os.path.join(TESTFN, src)
861 dst = os.path.join(TESTFN, dst)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000862 self.assertTrue(shutil._destinsrc(src, dst),
Benjamin Peterson247a9b82009-02-20 04:09:19 +0000863 msg='_destinsrc() wrongly concluded that '
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000864 'dst (%s) is not in src (%s)' % (dst, src))
865 finally:
866 shutil.rmtree(TESTFN, ignore_errors=True)
Christian Heimesada8c3b2008-03-18 18:26:33 +0000867
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000868 def test_destinsrc_false_positive(self):
869 os.mkdir(TESTFN)
870 try:
871 for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]:
872 src = os.path.join(TESTFN, src)
873 dst = os.path.join(TESTFN, dst)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000874 self.assertFalse(shutil._destinsrc(src, dst),
Benjamin Peterson247a9b82009-02-20 04:09:19 +0000875 msg='_destinsrc() wrongly concluded that '
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000876 'dst (%s) is in src (%s)' % (dst, src))
877 finally:
878 shutil.rmtree(TESTFN, ignore_errors=True)
Christian Heimes9bd667a2008-01-20 15:14:11 +0000879
Tarek Ziadé5340db32010-04-19 22:30:51 +0000880
Tarek Ziadéae4d5c62010-05-05 22:27:31 +0000881class TestCopyFile(unittest.TestCase):
882
883 _delete = False
884
885 class Faux(object):
886 _entered = False
887 _exited_with = None
888 _raised = False
889 def __init__(self, raise_in_exit=False, suppress_at_exit=True):
890 self._raise_in_exit = raise_in_exit
891 self._suppress_at_exit = suppress_at_exit
892 def read(self, *args):
893 return ''
894 def __enter__(self):
895 self._entered = True
896 def __exit__(self, exc_type, exc_val, exc_tb):
897 self._exited_with = exc_type, exc_val, exc_tb
898 if self._raise_in_exit:
899 self._raised = True
900 raise IOError("Cannot close")
901 return self._suppress_at_exit
902
903 def tearDown(self):
904 if self._delete:
905 del shutil.open
906
907 def _set_shutil_open(self, func):
908 shutil.open = func
909 self._delete = True
910
911 def test_w_source_open_fails(self):
912 def _open(filename, mode='r'):
913 if filename == 'srcfile':
914 raise IOError('Cannot open "srcfile"')
915 assert 0 # shouldn't reach here.
916
917 self._set_shutil_open(_open)
918
919 self.assertRaises(IOError, shutil.copyfile, 'srcfile', 'destfile')
920
921 def test_w_dest_open_fails(self):
922
923 srcfile = self.Faux()
924
925 def _open(filename, mode='r'):
926 if filename == 'srcfile':
927 return srcfile
928 if filename == 'destfile':
929 raise IOError('Cannot open "destfile"')
930 assert 0 # shouldn't reach here.
931
932 self._set_shutil_open(_open)
933
934 shutil.copyfile('srcfile', 'destfile')
935 self.assertTrue(srcfile._entered)
936 self.assertTrue(srcfile._exited_with[0] is IOError)
937 self.assertEqual(srcfile._exited_with[1].args,
938 ('Cannot open "destfile"',))
939
940 def test_w_dest_close_fails(self):
941
942 srcfile = self.Faux()
943 destfile = self.Faux(True)
944
945 def _open(filename, mode='r'):
946 if filename == 'srcfile':
947 return srcfile
948 if filename == 'destfile':
949 return destfile
950 assert 0 # shouldn't reach here.
951
952 self._set_shutil_open(_open)
953
954 shutil.copyfile('srcfile', 'destfile')
955 self.assertTrue(srcfile._entered)
956 self.assertTrue(destfile._entered)
957 self.assertTrue(destfile._raised)
958 self.assertTrue(srcfile._exited_with[0] is IOError)
959 self.assertEqual(srcfile._exited_with[1].args,
960 ('Cannot close',))
961
962 def test_w_source_close_fails(self):
963
964 srcfile = self.Faux(True)
965 destfile = self.Faux()
966
967 def _open(filename, mode='r'):
968 if filename == 'srcfile':
969 return srcfile
970 if filename == 'destfile':
971 return destfile
972 assert 0 # shouldn't reach here.
973
974 self._set_shutil_open(_open)
975
976 self.assertRaises(IOError,
977 shutil.copyfile, 'srcfile', 'destfile')
978 self.assertTrue(srcfile._entered)
979 self.assertTrue(destfile._entered)
980 self.assertFalse(destfile._raised)
981 self.assertTrue(srcfile._exited_with[0] is None)
982 self.assertTrue(srcfile._raised)
983
Ronald Oussorenf51738b2011-05-06 10:23:04 +0200984 def test_move_dir_caseinsensitive(self):
985 # Renames a folder to the same name
986 # but a different case.
987
988 self.src_dir = tempfile.mkdtemp()
989 dst_dir = os.path.join(
990 os.path.dirname(self.src_dir),
991 os.path.basename(self.src_dir).upper())
992 self.assertNotEqual(self.src_dir, dst_dir)
993
994 try:
995 shutil.move(self.src_dir, dst_dir)
996 self.assertTrue(os.path.isdir(dst_dir))
997 finally:
998 if os.path.exists(dst_dir):
999 os.rmdir(dst_dir)
1000
1001
Tarek Ziadéae4d5c62010-05-05 22:27:31 +00001002
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00001003def test_main():
Tarek Ziadéae4d5c62010-05-05 22:27:31 +00001004 support.run_unittest(TestShutil, TestMove, TestCopyFile)
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00001005
Barry Warsaw7fc2cca2003-01-24 17:34:13 +00001006if __name__ == '__main__':
Walter Dörwald21d3a322003-05-01 17:45:56 +00001007 test_main()