blob: b64cc3a9043238b0146c9c183625b2bc8333ea0c [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
Benjamin Petersonee8712c2008-05-20 21:35:26 +000011from test import support
12from test.support import TESTFN
Tarek Ziadé396fad72010-02-23 05:30:31 +000013from os.path import splitdrive
14from distutils.spawn import find_executable, spawn
15from shutil import (_make_tarball, _make_zipfile, make_archive,
16 register_archive_format, unregister_archive_format,
Tarek Ziadé6ac91722010-04-28 17:51:36 +000017 get_archive_formats, Error, unpack_archive,
18 register_unpack_format, RegistryError,
19 unregister_unpack_format, get_unpack_formats)
Tarek Ziadé396fad72010-02-23 05:30:31 +000020import tarfile
21import warnings
22
23from test import support
Ezio Melotti975077a2011-05-19 22:03:22 +030024from test.support import TESTFN, check_warnings, captured_stdout, requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +000025
Tarek Ziadéffa155a2010-04-29 13:34:35 +000026try:
27 import bz2
28 BZ2_SUPPORTED = True
29except ImportError:
30 BZ2_SUPPORTED = False
31
Antoine Pitrou7fff0962009-05-01 21:09:44 +000032TESTFN2 = TESTFN + "2"
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000033
Tarek Ziadé396fad72010-02-23 05:30:31 +000034try:
35 import grp
36 import pwd
37 UID_GID_SUPPORT = True
38except ImportError:
39 UID_GID_SUPPORT = False
40
41try:
Tarek Ziadé396fad72010-02-23 05:30:31 +000042 import zipfile
43 ZIP_SUPPORT = True
44except ImportError:
45 ZIP_SUPPORT = find_executable('zip')
46
Nick Coghlan8ed3cf32011-03-16 14:05:35 -040047def _fake_rename(*args, **kwargs):
48 # Pretend the destination path is on a different filesystem.
49 raise OSError()
50
51def mock_rename(func):
52 @functools.wraps(func)
53 def wrap(*args, **kwargs):
54 try:
55 builtin_rename = os.rename
56 os.rename = _fake_rename
57 return func(*args, **kwargs)
58 finally:
59 os.rename = builtin_rename
60 return wrap
61
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000062class TestShutil(unittest.TestCase):
Tarek Ziadé396fad72010-02-23 05:30:31 +000063
64 def setUp(self):
65 super(TestShutil, self).setUp()
66 self.tempdirs = []
67
68 def tearDown(self):
69 super(TestShutil, self).tearDown()
70 while self.tempdirs:
71 d = self.tempdirs.pop()
72 shutil.rmtree(d, os.name in ('nt', 'cygwin'))
73
74 def write_file(self, path, content='xxx'):
75 """Writes a file in the given path.
76
77
78 path can be a string or a sequence.
79 """
80 if isinstance(path, (list, tuple)):
81 path = os.path.join(*path)
82 f = open(path, 'w')
83 try:
84 f.write(content)
85 finally:
86 f.close()
87
88 def mkdtemp(self):
89 """Create a temporary directory that will be cleaned up.
90
91 Returns the path of the directory.
92 """
93 d = tempfile.mkdtemp()
94 self.tempdirs.append(d)
95 return d
Tarek Ziadé5340db32010-04-19 22:30:51 +000096
Barry Warsaw7fc2cca2003-01-24 17:34:13 +000097 def test_rmtree_errors(self):
98 # filename is guaranteed not to exist
99 filename = tempfile.mktemp()
100 self.assertRaises(OSError, shutil.rmtree, filename)
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000101
Johannes Gijsbersb8b09d02004-12-06 20:50:15 +0000102 # See bug #1071513 for why we don't run this on cygwin
103 # and bug #1076467 for why we don't run this as root.
104 if (hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin'
Johannes Gijsbers6b220b02004-12-12 15:52:57 +0000105 and not (hasattr(os, 'geteuid') and os.geteuid() == 0)):
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000106 def test_on_error(self):
107 self.errorState = 0
108 os.mkdir(TESTFN)
Tim Peters4590c002004-11-01 02:40:52 +0000109 self.childpath = os.path.join(TESTFN, 'a')
Victor Stinnerbf816222011-06-30 23:25:47 +0200110 support.create_empty_file(self.childpath)
Tim Peters4590c002004-11-01 02:40:52 +0000111 old_dir_mode = os.stat(TESTFN).st_mode
112 old_child_mode = os.stat(self.childpath).st_mode
113 # Make unwritable.
114 os.chmod(self.childpath, stat.S_IREAD)
115 os.chmod(TESTFN, stat.S_IREAD)
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000116
117 shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
Johannes Gijsbers8e6f2de2004-11-23 09:27:27 +0000118 # Test whether onerror has actually been called.
Johannes Gijsbersb8b09d02004-12-06 20:50:15 +0000119 self.assertEqual(self.errorState, 2,
120 "Expected call to onerror function did not happen.")
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000121
Tim Peters4590c002004-11-01 02:40:52 +0000122 # Make writable again.
123 os.chmod(TESTFN, old_dir_mode)
124 os.chmod(self.childpath, old_child_mode)
125
126 # Clean up.
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000127 shutil.rmtree(TESTFN)
128
129 def check_args_to_onerror(self, func, arg, exc):
Benjamin Peterson25c95f12009-05-08 20:42:26 +0000130 # test_rmtree_errors deliberately runs rmtree
131 # on a directory that is chmod 400, which will fail.
132 # This function is run when shutil.rmtree fails.
133 # 99.9% of the time it initially fails to remove
134 # a file in the directory, so the first time through
135 # func is os.remove.
136 # However, some Linux machines running ZFS on
137 # FUSE experienced a failure earlier in the process
138 # at os.listdir. The first failure may legally
139 # be either.
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000140 if self.errorState == 0:
Benjamin Peterson25c95f12009-05-08 20:42:26 +0000141 if func is os.remove:
142 self.assertEqual(arg, self.childpath)
143 else:
144 self.assertIs(func, os.listdir,
145 "func must be either os.remove or os.listdir")
146 self.assertEqual(arg, TESTFN)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000147 self.assertTrue(issubclass(exc[0], OSError))
Johannes Gijsbersef5ffc42004-10-31 12:05:31 +0000148 self.errorState = 1
149 else:
150 self.assertEqual(func, os.rmdir)
151 self.assertEqual(arg, TESTFN)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000152 self.assertTrue(issubclass(exc[0], OSError))
Johannes Gijsbers8e6f2de2004-11-23 09:27:27 +0000153 self.errorState = 2
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000154
Johannes Gijsbersd60e92a2004-09-11 21:26:21 +0000155 def test_rmtree_dont_delete_file(self):
156 # When called on a file instead of a directory, don't delete it.
157 handle, path = tempfile.mkstemp()
Victor Stinnerbf816222011-06-30 23:25:47 +0200158 os.close(handle)
Johannes Gijsbersd60e92a2004-09-11 21:26:21 +0000159 self.assertRaises(OSError, shutil.rmtree, path)
160 os.remove(path)
161
Tarek Ziadé5340db32010-04-19 22:30:51 +0000162 def _write_data(self, path, data):
163 f = open(path, "w")
164 f.write(data)
165 f.close()
166
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000167 def test_copytree_simple(self):
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000168
169 def read_data(path):
170 f = open(path)
171 data = f.read()
172 f.close()
173 return data
174
175 src_dir = tempfile.mkdtemp()
176 dst_dir = os.path.join(tempfile.mkdtemp(), 'destination')
Tarek Ziadé5340db32010-04-19 22:30:51 +0000177 self._write_data(os.path.join(src_dir, 'test.txt'), '123')
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000178 os.mkdir(os.path.join(src_dir, 'test_dir'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000179 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000180
181 try:
182 shutil.copytree(src_dir, dst_dir)
183 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test.txt')))
184 self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'test_dir')))
185 self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'test_dir',
186 'test.txt')))
187 actual = read_data(os.path.join(dst_dir, 'test.txt'))
188 self.assertEqual(actual, '123')
189 actual = read_data(os.path.join(dst_dir, 'test_dir', 'test.txt'))
190 self.assertEqual(actual, '456')
191 finally:
192 for path in (
193 os.path.join(src_dir, 'test.txt'),
194 os.path.join(dst_dir, 'test.txt'),
195 os.path.join(src_dir, 'test_dir', 'test.txt'),
196 os.path.join(dst_dir, 'test_dir', 'test.txt'),
197 ):
198 if os.path.exists(path):
199 os.remove(path)
Christian Heimese052dd82007-11-20 03:20:04 +0000200 for path in (src_dir,
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000201 os.path.dirname(dst_dir)
Christian Heimese052dd82007-11-20 03:20:04 +0000202 ):
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000203 if os.path.exists(path):
Christian Heimes94140152007-11-20 01:45:17 +0000204 shutil.rmtree(path)
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000205
Georg Brandl2ee470f2008-07-16 12:55:28 +0000206 def test_copytree_with_exclude(self):
207
Georg Brandl2ee470f2008-07-16 12:55:28 +0000208 def read_data(path):
209 f = open(path)
210 data = f.read()
211 f.close()
212 return data
213
214 # creating data
215 join = os.path.join
216 exists = os.path.exists
217 src_dir = tempfile.mkdtemp()
Georg Brandl2ee470f2008-07-16 12:55:28 +0000218 try:
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000219 dst_dir = join(tempfile.mkdtemp(), 'destination')
Tarek Ziadé5340db32010-04-19 22:30:51 +0000220 self._write_data(join(src_dir, 'test.txt'), '123')
221 self._write_data(join(src_dir, 'test.tmp'), '123')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000222 os.mkdir(join(src_dir, 'test_dir'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000223 self._write_data(join(src_dir, 'test_dir', 'test.txt'), '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000224 os.mkdir(join(src_dir, 'test_dir2'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000225 self._write_data(join(src_dir, 'test_dir2', 'test.txt'), '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000226 os.mkdir(join(src_dir, 'test_dir2', 'subdir'))
227 os.mkdir(join(src_dir, 'test_dir2', 'subdir2'))
Tarek Ziadé5340db32010-04-19 22:30:51 +0000228 self._write_data(join(src_dir, 'test_dir2', 'subdir', 'test.txt'),
229 '456')
230 self._write_data(join(src_dir, 'test_dir2', 'subdir2', 'test.py'),
231 '456')
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000232
233
234 # testing glob-like patterns
235 try:
236 patterns = shutil.ignore_patterns('*.tmp', 'test_dir2')
237 shutil.copytree(src_dir, dst_dir, ignore=patterns)
238 # checking the result: some elements should not be copied
239 self.assertTrue(exists(join(dst_dir, 'test.txt')))
240 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
241 self.assertTrue(not exists(join(dst_dir, 'test_dir2')))
242 finally:
243 if os.path.exists(dst_dir):
244 shutil.rmtree(dst_dir)
245 try:
246 patterns = shutil.ignore_patterns('*.tmp', 'subdir*')
247 shutil.copytree(src_dir, dst_dir, ignore=patterns)
248 # checking the result: some elements should not be copied
249 self.assertTrue(not exists(join(dst_dir, 'test.tmp')))
250 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2')))
251 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
252 finally:
253 if os.path.exists(dst_dir):
254 shutil.rmtree(dst_dir)
255
256 # testing callable-style
257 try:
258 def _filter(src, names):
259 res = []
260 for name in names:
261 path = os.path.join(src, name)
262
263 if (os.path.isdir(path) and
264 path.split()[-1] == 'subdir'):
265 res.append(name)
266 elif os.path.splitext(path)[-1] in ('.py'):
267 res.append(name)
268 return res
269
270 shutil.copytree(src_dir, dst_dir, ignore=_filter)
271
272 # checking the result: some elements should not be copied
273 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir2',
274 'test.py')))
275 self.assertTrue(not exists(join(dst_dir, 'test_dir2', 'subdir')))
276
277 finally:
278 if os.path.exists(dst_dir):
279 shutil.rmtree(dst_dir)
Georg Brandl2ee470f2008-07-16 12:55:28 +0000280 finally:
Antoine Pitrou97c81ef2009-11-04 00:57:15 +0000281 shutil.rmtree(src_dir)
282 shutil.rmtree(os.path.dirname(dst_dir))
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000283
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000284 @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000285 def test_dont_copy_file_onto_link_to_itself(self):
Georg Brandl724d0892010-12-05 07:51:39 +0000286 # Temporarily disable test on Windows.
287 if os.name == 'nt':
288 return
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000289 # bug 851123.
290 os.mkdir(TESTFN)
291 src = os.path.join(TESTFN, 'cheese')
292 dst = os.path.join(TESTFN, 'shop')
293 try:
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000294 with open(src, 'w') as f:
295 f.write('cheddar')
296 os.link(src, dst)
297 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
298 with open(src, 'r') as f:
299 self.assertEqual(f.read(), 'cheddar')
300 os.remove(dst)
301 finally:
302 shutil.rmtree(TESTFN, ignore_errors=True)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000303
Brian Curtin3b4499c2010-12-28 14:31:47 +0000304 @support.skip_unless_symlink
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000305 def test_dont_copy_file_onto_symlink_to_itself(self):
306 # bug 851123.
307 os.mkdir(TESTFN)
308 src = os.path.join(TESTFN, 'cheese')
309 dst = os.path.join(TESTFN, 'shop')
310 try:
311 with open(src, 'w') as f:
312 f.write('cheddar')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000313 # Using `src` here would mean we end up with a symlink pointing
314 # to TESTFN/TESTFN/cheese, while it should point at
315 # TESTFN/cheese.
316 os.symlink('cheese', dst)
317 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000318 with open(src, 'r') as f:
319 self.assertEqual(f.read(), 'cheddar')
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000320 os.remove(dst)
321 finally:
Hirokazu Yamamoto26681452010-12-05 02:04:16 +0000322 shutil.rmtree(TESTFN, ignore_errors=True)
Johannes Gijsbers68128712004-08-14 13:57:08 +0000323
Brian Curtin3b4499c2010-12-28 14:31:47 +0000324 @support.skip_unless_symlink
Brian Curtind40e6f72010-07-08 21:39:08 +0000325 def test_rmtree_on_symlink(self):
326 # bug 1669.
327 os.mkdir(TESTFN)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000328 try:
Brian Curtind40e6f72010-07-08 21:39:08 +0000329 src = os.path.join(TESTFN, 'cheese')
330 dst = os.path.join(TESTFN, 'shop')
331 os.mkdir(src)
332 os.symlink(src, dst)
333 self.assertRaises(OSError, shutil.rmtree, dst)
Tarek Ziadé51a6f722010-04-23 13:03:09 +0000334 finally:
Brian Curtind40e6f72010-07-08 21:39:08 +0000335 shutil.rmtree(TESTFN, ignore_errors=True)
336
337 if hasattr(os, "mkfifo"):
338 # Issue #3002: copyfile and copytree block indefinitely on named pipes
339 def test_copyfile_named_pipe(self):
340 os.mkfifo(TESTFN)
341 try:
342 self.assertRaises(shutil.SpecialFileError,
343 shutil.copyfile, TESTFN, TESTFN2)
344 self.assertRaises(shutil.SpecialFileError,
345 shutil.copyfile, __file__, TESTFN)
346 finally:
347 os.remove(TESTFN)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000348
Brian Curtin3b4499c2010-12-28 14:31:47 +0000349 @support.skip_unless_symlink
Brian Curtin52173d42010-12-02 18:29:18 +0000350 def test_copytree_named_pipe(self):
351 os.mkdir(TESTFN)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000352 try:
Brian Curtin52173d42010-12-02 18:29:18 +0000353 subdir = os.path.join(TESTFN, "subdir")
354 os.mkdir(subdir)
355 pipe = os.path.join(subdir, "mypipe")
356 os.mkfifo(pipe)
357 try:
358 shutil.copytree(TESTFN, TESTFN2)
359 except shutil.Error as e:
360 errors = e.args[0]
361 self.assertEqual(len(errors), 1)
362 src, dst, error_msg = errors[0]
363 self.assertEqual("`%s` is a named pipe" % pipe, error_msg)
364 else:
365 self.fail("shutil.Error should have been raised")
366 finally:
367 shutil.rmtree(TESTFN, ignore_errors=True)
368 shutil.rmtree(TESTFN2, ignore_errors=True)
Antoine Pitrou7fff0962009-05-01 21:09:44 +0000369
Tarek Ziadé5340db32010-04-19 22:30:51 +0000370 def test_copytree_special_func(self):
371
372 src_dir = self.mkdtemp()
373 dst_dir = os.path.join(self.mkdtemp(), 'destination')
374 self._write_data(os.path.join(src_dir, 'test.txt'), '123')
375 os.mkdir(os.path.join(src_dir, 'test_dir'))
376 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
377
378 copied = []
379 def _copy(src, dst):
380 copied.append((src, dst))
381
382 shutil.copytree(src_dir, dst_dir, copy_function=_copy)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000383 self.assertEqual(len(copied), 2)
Tarek Ziadé5340db32010-04-19 22:30:51 +0000384
Brian Curtin3b4499c2010-12-28 14:31:47 +0000385 @support.skip_unless_symlink
Tarek Ziadéfb437512010-04-20 08:57:33 +0000386 def test_copytree_dangling_symlinks(self):
387
388 # a dangling symlink raises an error at the end
389 src_dir = self.mkdtemp()
390 dst_dir = os.path.join(self.mkdtemp(), 'destination')
391 os.symlink('IDONTEXIST', os.path.join(src_dir, 'test.txt'))
392 os.mkdir(os.path.join(src_dir, 'test_dir'))
393 self._write_data(os.path.join(src_dir, 'test_dir', 'test.txt'), '456')
394 self.assertRaises(Error, shutil.copytree, src_dir, dst_dir)
395
396 # a dangling symlink is ignored with the proper flag
397 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
398 shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True)
399 self.assertNotIn('test.txt', os.listdir(dst_dir))
400
401 # a dangling symlink is copied if symlinks=True
402 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
403 shutil.copytree(src_dir, dst_dir, symlinks=True)
404 self.assertIn('test.txt', os.listdir(dst_dir))
405
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400406 def _copy_file(self, method):
407 fname = 'test.txt'
408 tmpdir = self.mkdtemp()
409 self.write_file([tmpdir, fname])
410 file1 = os.path.join(tmpdir, fname)
411 tmpdir2 = self.mkdtemp()
412 method(file1, tmpdir2)
413 file2 = os.path.join(tmpdir2, fname)
414 return (file1, file2)
415
416 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
417 def test_copy(self):
418 # Ensure that the copied file exists and has the same mode bits.
419 file1, file2 = self._copy_file(shutil.copy)
420 self.assertTrue(os.path.exists(file2))
421 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)
422
423 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
Senthil Kumaran0c2dba52011-07-03 18:21:38 -0700424 @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime')
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400425 def test_copy2(self):
426 # Ensure that the copied file exists and has the same mode and
427 # modification time bits.
428 file1, file2 = self._copy_file(shutil.copy2)
429 self.assertTrue(os.path.exists(file2))
430 file1_stat = os.stat(file1)
431 file2_stat = os.stat(file2)
432 self.assertEqual(file1_stat.st_mode, file2_stat.st_mode)
433 for attr in 'st_atime', 'st_mtime':
434 # The modification times may be truncated in the new file.
435 self.assertLessEqual(getattr(file1_stat, attr),
436 getattr(file2_stat, attr) + 1)
437 if hasattr(os, 'chflags') and hasattr(file1_stat, 'st_flags'):
438 self.assertEqual(getattr(file1_stat, 'st_flags'),
439 getattr(file2_stat, 'st_flags'))
440
Ezio Melotti975077a2011-05-19 22:03:22 +0300441 @requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +0000442 def test_make_tarball(self):
443 # creating something to tar
444 tmpdir = self.mkdtemp()
445 self.write_file([tmpdir, 'file1'], 'xxx')
446 self.write_file([tmpdir, 'file2'], 'xxx')
447 os.mkdir(os.path.join(tmpdir, 'sub'))
448 self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
449
450 tmpdir2 = self.mkdtemp()
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400451 # force shutil to create the directory
452 os.rmdir(tmpdir2)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000453 unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
454 "source and target should be on same drive")
455
456 base_name = os.path.join(tmpdir2, 'archive')
457
458 # working with relative paths to avoid tar warnings
459 old_dir = os.getcwd()
460 os.chdir(tmpdir)
461 try:
462 _make_tarball(splitdrive(base_name)[1], '.')
463 finally:
464 os.chdir(old_dir)
465
466 # check if the compressed tarball was created
467 tarball = base_name + '.tar.gz'
468 self.assertTrue(os.path.exists(tarball))
469
470 # trying an uncompressed one
471 base_name = os.path.join(tmpdir2, 'archive')
472 old_dir = os.getcwd()
473 os.chdir(tmpdir)
474 try:
475 _make_tarball(splitdrive(base_name)[1], '.', compress=None)
476 finally:
477 os.chdir(old_dir)
478 tarball = base_name + '.tar'
479 self.assertTrue(os.path.exists(tarball))
480
481 def _tarinfo(self, path):
482 tar = tarfile.open(path)
483 try:
484 names = tar.getnames()
485 names.sort()
486 return tuple(names)
487 finally:
488 tar.close()
489
490 def _create_files(self):
491 # creating something to tar
492 tmpdir = self.mkdtemp()
493 dist = os.path.join(tmpdir, 'dist')
494 os.mkdir(dist)
495 self.write_file([dist, 'file1'], 'xxx')
496 self.write_file([dist, 'file2'], 'xxx')
497 os.mkdir(os.path.join(dist, 'sub'))
498 self.write_file([dist, 'sub', 'file3'], 'xxx')
499 os.mkdir(os.path.join(dist, 'sub2'))
500 tmpdir2 = self.mkdtemp()
501 base_name = os.path.join(tmpdir2, 'archive')
502 return tmpdir, tmpdir2, base_name
503
Ezio Melotti975077a2011-05-19 22:03:22 +0300504 @requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +0000505 @unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
506 'Need the tar command to run')
507 def test_tarfile_vs_tar(self):
508 tmpdir, tmpdir2, base_name = self._create_files()
509 old_dir = os.getcwd()
510 os.chdir(tmpdir)
511 try:
512 _make_tarball(base_name, 'dist')
513 finally:
514 os.chdir(old_dir)
515
516 # check if the compressed tarball was created
517 tarball = base_name + '.tar.gz'
518 self.assertTrue(os.path.exists(tarball))
519
520 # now create another tarball using `tar`
521 tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
522 tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
523 gzip_cmd = ['gzip', '-f9', 'archive2.tar']
524 old_dir = os.getcwd()
525 os.chdir(tmpdir)
526 try:
527 with captured_stdout() as s:
528 spawn(tar_cmd)
529 spawn(gzip_cmd)
530 finally:
531 os.chdir(old_dir)
532
533 self.assertTrue(os.path.exists(tarball2))
534 # let's compare both tarballs
Ezio Melottib3aedd42010-11-20 19:04:17 +0000535 self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
Tarek Ziadé396fad72010-02-23 05:30:31 +0000536
537 # trying an uncompressed one
538 base_name = os.path.join(tmpdir2, 'archive')
539 old_dir = os.getcwd()
540 os.chdir(tmpdir)
541 try:
542 _make_tarball(base_name, 'dist', compress=None)
543 finally:
544 os.chdir(old_dir)
545 tarball = base_name + '.tar'
546 self.assertTrue(os.path.exists(tarball))
547
548 # now for a dry_run
549 base_name = os.path.join(tmpdir2, 'archive')
550 old_dir = os.getcwd()
551 os.chdir(tmpdir)
552 try:
553 _make_tarball(base_name, 'dist', compress=None, dry_run=True)
554 finally:
555 os.chdir(old_dir)
556 tarball = base_name + '.tar'
557 self.assertTrue(os.path.exists(tarball))
558
Ezio Melotti975077a2011-05-19 22:03:22 +0300559 @requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +0000560 @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
561 def test_make_zipfile(self):
562 # creating something to tar
563 tmpdir = self.mkdtemp()
564 self.write_file([tmpdir, 'file1'], 'xxx')
565 self.write_file([tmpdir, 'file2'], 'xxx')
566
567 tmpdir2 = self.mkdtemp()
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400568 # force shutil to create the directory
569 os.rmdir(tmpdir2)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000570 base_name = os.path.join(tmpdir2, 'archive')
571 _make_zipfile(base_name, tmpdir)
572
573 # check if the compressed tarball was created
574 tarball = base_name + '.zip'
Éric Araujo1c505492010-11-06 02:12:51 +0000575 self.assertTrue(os.path.exists(tarball))
Tarek Ziadé396fad72010-02-23 05:30:31 +0000576
577
578 def test_make_archive(self):
579 tmpdir = self.mkdtemp()
580 base_name = os.path.join(tmpdir, 'archive')
581 self.assertRaises(ValueError, make_archive, base_name, 'xxx')
582
Ezio Melotti975077a2011-05-19 22:03:22 +0300583 @requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +0000584 def test_make_archive_owner_group(self):
585 # testing make_archive with owner and group, with various combinations
586 # this works even if there's not gid/uid support
587 if UID_GID_SUPPORT:
588 group = grp.getgrgid(0)[0]
589 owner = pwd.getpwuid(0)[0]
590 else:
591 group = owner = 'root'
592
593 base_dir, root_dir, base_name = self._create_files()
594 base_name = os.path.join(self.mkdtemp() , 'archive')
595 res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
596 group=group)
597 self.assertTrue(os.path.exists(res))
598
599 res = make_archive(base_name, 'zip', root_dir, base_dir)
600 self.assertTrue(os.path.exists(res))
601
602 res = make_archive(base_name, 'tar', root_dir, base_dir,
603 owner=owner, group=group)
604 self.assertTrue(os.path.exists(res))
605
606 res = make_archive(base_name, 'tar', root_dir, base_dir,
607 owner='kjhkjhkjg', group='oihohoh')
608 self.assertTrue(os.path.exists(res))
609
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000610
Ezio Melotti975077a2011-05-19 22:03:22 +0300611 @requires_zlib
Tarek Ziadé396fad72010-02-23 05:30:31 +0000612 @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
613 def test_tarfile_root_owner(self):
614 tmpdir, tmpdir2, base_name = self._create_files()
615 old_dir = os.getcwd()
616 os.chdir(tmpdir)
617 group = grp.getgrgid(0)[0]
618 owner = pwd.getpwuid(0)[0]
619 try:
620 archive_name = _make_tarball(base_name, 'dist', compress=None,
621 owner=owner, group=group)
622 finally:
623 os.chdir(old_dir)
624
625 # check if the compressed tarball was created
626 self.assertTrue(os.path.exists(archive_name))
627
628 # now checks the rights
629 archive = tarfile.open(archive_name)
630 try:
631 for member in archive.getmembers():
Ezio Melottib3aedd42010-11-20 19:04:17 +0000632 self.assertEqual(member.uid, 0)
633 self.assertEqual(member.gid, 0)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000634 finally:
635 archive.close()
636
637 def test_make_archive_cwd(self):
638 current_dir = os.getcwd()
639 def _breaks(*args, **kw):
640 raise RuntimeError()
641
642 register_archive_format('xxx', _breaks, [], 'xxx file')
643 try:
644 try:
645 make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
646 except Exception:
647 pass
Ezio Melottib3aedd42010-11-20 19:04:17 +0000648 self.assertEqual(os.getcwd(), current_dir)
Tarek Ziadé396fad72010-02-23 05:30:31 +0000649 finally:
650 unregister_archive_format('xxx')
651
652 def test_register_archive_format(self):
653
654 self.assertRaises(TypeError, register_archive_format, 'xxx', 1)
655 self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
656 1)
657 self.assertRaises(TypeError, register_archive_format, 'xxx', lambda: x,
658 [(1, 2), (1, 2, 3)])
659
660 register_archive_format('xxx', lambda: x, [(1, 2)], 'xxx file')
661 formats = [name for name, params in get_archive_formats()]
662 self.assertIn('xxx', formats)
663
664 unregister_archive_format('xxx')
665 formats = [name for name, params in get_archive_formats()]
666 self.assertNotIn('xxx', formats)
667
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000668 def _compare_dirs(self, dir1, dir2):
669 # check that dir1 and dir2 are equivalent,
670 # return the diff
671 diff = []
672 for root, dirs, files in os.walk(dir1):
673 for file_ in files:
674 path = os.path.join(root, file_)
675 target_path = os.path.join(dir2, os.path.split(path)[-1])
676 if not os.path.exists(target_path):
677 diff.append(file_)
678 return diff
679
Ezio Melotti975077a2011-05-19 22:03:22 +0300680 @requires_zlib
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000681 def test_unpack_archive(self):
Tarek Ziadéffa155a2010-04-29 13:34:35 +0000682 formats = ['tar', 'gztar', 'zip']
683 if BZ2_SUPPORTED:
684 formats.append('bztar')
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000685
Tarek Ziadéffa155a2010-04-29 13:34:35 +0000686 for format in formats:
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000687 tmpdir = self.mkdtemp()
688 base_dir, root_dir, base_name = self._create_files()
689 tmpdir2 = self.mkdtemp()
690 filename = make_archive(base_name, format, root_dir, base_dir)
691
692 # let's try to unpack it now
693 unpack_archive(filename, tmpdir2)
694 diff = self._compare_dirs(tmpdir, tmpdir2)
Ezio Melottib3aedd42010-11-20 19:04:17 +0000695 self.assertEqual(diff, [])
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000696
Nick Coghlanabf202d2011-03-16 13:52:20 -0400697 # and again, this time with the format specified
698 tmpdir3 = self.mkdtemp()
699 unpack_archive(filename, tmpdir3, format=format)
700 diff = self._compare_dirs(tmpdir, tmpdir3)
701 self.assertEqual(diff, [])
702 self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
703 self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
704
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000705 def test_unpack_registery(self):
706
707 formats = get_unpack_formats()
708
709 def _boo(filename, extract_dir, extra):
Ezio Melottib3aedd42010-11-20 19:04:17 +0000710 self.assertEqual(extra, 1)
711 self.assertEqual(filename, 'stuff.boo')
712 self.assertEqual(extract_dir, 'xx')
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000713
714 register_unpack_format('Boo', ['.boo', '.b2'], _boo, [('extra', 1)])
715 unpack_archive('stuff.boo', 'xx')
716
717 # trying to register a .boo unpacker again
718 self.assertRaises(RegistryError, register_unpack_format, 'Boo2',
719 ['.boo'], _boo)
720
721 # should work now
722 unregister_unpack_format('Boo')
723 register_unpack_format('Boo2', ['.boo'], _boo)
724 self.assertIn(('Boo2', ['.boo'], ''), get_unpack_formats())
725 self.assertNotIn(('Boo', ['.boo'], ''), get_unpack_formats())
726
727 # let's leave a clean state
728 unregister_unpack_format('Boo2')
Ezio Melottib3aedd42010-11-20 19:04:17 +0000729 self.assertEqual(get_unpack_formats(), formats)
Tarek Ziadé6ac91722010-04-28 17:51:36 +0000730
Giampaolo Rodola'210e7ca2011-07-01 13:55:36 +0200731 @unittest.skipUnless(hasattr(shutil, 'disk_usage'),
732 "disk_usage not available on this platform")
733 def test_disk_usage(self):
734 usage = shutil.disk_usage(os.getcwd())
Éric Araujo2ee61882011-07-02 16:45:45 +0200735 self.assertGreater(usage.total, 0)
736 self.assertGreater(usage.used, 0)
737 self.assertGreaterEqual(usage.free, 0)
738 self.assertGreaterEqual(usage.total, usage.used)
739 self.assertGreater(usage.total, usage.free)
Giampaolo Rodola'210e7ca2011-07-01 13:55:36 +0200740
Christian Heimes9bd667a2008-01-20 15:14:11 +0000741
Christian Heimesada8c3b2008-03-18 18:26:33 +0000742class TestMove(unittest.TestCase):
743
744 def setUp(self):
745 filename = "foo"
746 self.src_dir = tempfile.mkdtemp()
747 self.dst_dir = tempfile.mkdtemp()
748 self.src_file = os.path.join(self.src_dir, filename)
749 self.dst_file = os.path.join(self.dst_dir, filename)
Christian Heimesada8c3b2008-03-18 18:26:33 +0000750 with open(self.src_file, "wb") as f:
751 f.write(b"spam")
752
753 def tearDown(self):
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400754 for d in (self.src_dir, self.dst_dir):
Christian Heimesada8c3b2008-03-18 18:26:33 +0000755 try:
756 if d:
757 shutil.rmtree(d)
758 except:
759 pass
760
761 def _check_move_file(self, src, dst, real_dst):
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000762 with open(src, "rb") as f:
763 contents = f.read()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000764 shutil.move(src, dst)
Antoine Pitrou92f60ed2010-10-14 22:11:44 +0000765 with open(real_dst, "rb") as f:
766 self.assertEqual(contents, f.read())
Christian Heimesada8c3b2008-03-18 18:26:33 +0000767 self.assertFalse(os.path.exists(src))
768
769 def _check_move_dir(self, src, dst, real_dst):
770 contents = sorted(os.listdir(src))
771 shutil.move(src, dst)
772 self.assertEqual(contents, sorted(os.listdir(real_dst)))
773 self.assertFalse(os.path.exists(src))
774
775 def test_move_file(self):
776 # Move a file to another location on the same filesystem.
777 self._check_move_file(self.src_file, self.dst_file, self.dst_file)
778
779 def test_move_file_to_dir(self):
780 # Move a file inside an existing dir on the same filesystem.
781 self._check_move_file(self.src_file, self.dst_dir, self.dst_file)
782
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400783 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000784 def test_move_file_other_fs(self):
785 # Move a file to an existing dir on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400786 self.test_move_file()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000787
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400788 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000789 def test_move_file_to_dir_other_fs(self):
790 # Move a file to another location on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400791 self.test_move_file_to_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000792
793 def test_move_dir(self):
794 # Move a dir to another location on the same filesystem.
795 dst_dir = tempfile.mktemp()
796 try:
797 self._check_move_dir(self.src_dir, dst_dir, dst_dir)
798 finally:
799 try:
800 shutil.rmtree(dst_dir)
801 except:
802 pass
803
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400804 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000805 def test_move_dir_other_fs(self):
806 # Move a dir to another location on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400807 self.test_move_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000808
809 def test_move_dir_to_dir(self):
810 # Move a dir inside an existing dir on the same filesystem.
811 self._check_move_dir(self.src_dir, self.dst_dir,
812 os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
813
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400814 @mock_rename
Christian Heimesada8c3b2008-03-18 18:26:33 +0000815 def test_move_dir_to_dir_other_fs(self):
816 # Move a dir inside an existing dir on another filesystem.
Nick Coghlan8ed3cf32011-03-16 14:05:35 -0400817 self.test_move_dir_to_dir()
Christian Heimesada8c3b2008-03-18 18:26:33 +0000818
819 def test_existing_file_inside_dest_dir(self):
820 # A file with the same name inside the destination dir already exists.
821 with open(self.dst_file, "wb"):
822 pass
823 self.assertRaises(shutil.Error, shutil.move, self.src_file, self.dst_dir)
824
825 def test_dont_move_dir_in_itself(self):
826 # Moving a dir inside itself raises an Error.
827 dst = os.path.join(self.src_dir, "bar")
828 self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst)
829
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000830 def test_destinsrc_false_negative(self):
831 os.mkdir(TESTFN)
832 try:
833 for src, dst in [('srcdir', 'srcdir/dest')]:
834 src = os.path.join(TESTFN, src)
835 dst = os.path.join(TESTFN, dst)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000836 self.assertTrue(shutil._destinsrc(src, dst),
Benjamin Peterson247a9b82009-02-20 04:09:19 +0000837 msg='_destinsrc() wrongly concluded that '
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000838 'dst (%s) is not in src (%s)' % (dst, src))
839 finally:
840 shutil.rmtree(TESTFN, ignore_errors=True)
Christian Heimesada8c3b2008-03-18 18:26:33 +0000841
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000842 def test_destinsrc_false_positive(self):
843 os.mkdir(TESTFN)
844 try:
845 for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]:
846 src = os.path.join(TESTFN, src)
847 dst = os.path.join(TESTFN, dst)
Benjamin Petersonc9c0f202009-06-30 23:06:06 +0000848 self.assertFalse(shutil._destinsrc(src, dst),
Benjamin Peterson247a9b82009-02-20 04:09:19 +0000849 msg='_destinsrc() wrongly concluded that '
Antoine Pitrou0dcc3cd2009-01-29 20:26:59 +0000850 'dst (%s) is in src (%s)' % (dst, src))
851 finally:
852 shutil.rmtree(TESTFN, ignore_errors=True)
Christian Heimes9bd667a2008-01-20 15:14:11 +0000853
Tarek Ziadé5340db32010-04-19 22:30:51 +0000854
Tarek Ziadéae4d5c62010-05-05 22:27:31 +0000855class TestCopyFile(unittest.TestCase):
856
857 _delete = False
858
859 class Faux(object):
860 _entered = False
861 _exited_with = None
862 _raised = False
863 def __init__(self, raise_in_exit=False, suppress_at_exit=True):
864 self._raise_in_exit = raise_in_exit
865 self._suppress_at_exit = suppress_at_exit
866 def read(self, *args):
867 return ''
868 def __enter__(self):
869 self._entered = True
870 def __exit__(self, exc_type, exc_val, exc_tb):
871 self._exited_with = exc_type, exc_val, exc_tb
872 if self._raise_in_exit:
873 self._raised = True
874 raise IOError("Cannot close")
875 return self._suppress_at_exit
876
877 def tearDown(self):
878 if self._delete:
879 del shutil.open
880
881 def _set_shutil_open(self, func):
882 shutil.open = func
883 self._delete = True
884
885 def test_w_source_open_fails(self):
886 def _open(filename, mode='r'):
887 if filename == 'srcfile':
888 raise IOError('Cannot open "srcfile"')
889 assert 0 # shouldn't reach here.
890
891 self._set_shutil_open(_open)
892
893 self.assertRaises(IOError, shutil.copyfile, 'srcfile', 'destfile')
894
895 def test_w_dest_open_fails(self):
896
897 srcfile = self.Faux()
898
899 def _open(filename, mode='r'):
900 if filename == 'srcfile':
901 return srcfile
902 if filename == 'destfile':
903 raise IOError('Cannot open "destfile"')
904 assert 0 # shouldn't reach here.
905
906 self._set_shutil_open(_open)
907
908 shutil.copyfile('srcfile', 'destfile')
909 self.assertTrue(srcfile._entered)
910 self.assertTrue(srcfile._exited_with[0] is IOError)
911 self.assertEqual(srcfile._exited_with[1].args,
912 ('Cannot open "destfile"',))
913
914 def test_w_dest_close_fails(self):
915
916 srcfile = self.Faux()
917 destfile = self.Faux(True)
918
919 def _open(filename, mode='r'):
920 if filename == 'srcfile':
921 return srcfile
922 if filename == 'destfile':
923 return destfile
924 assert 0 # shouldn't reach here.
925
926 self._set_shutil_open(_open)
927
928 shutil.copyfile('srcfile', 'destfile')
929 self.assertTrue(srcfile._entered)
930 self.assertTrue(destfile._entered)
931 self.assertTrue(destfile._raised)
932 self.assertTrue(srcfile._exited_with[0] is IOError)
933 self.assertEqual(srcfile._exited_with[1].args,
934 ('Cannot close',))
935
936 def test_w_source_close_fails(self):
937
938 srcfile = self.Faux(True)
939 destfile = self.Faux()
940
941 def _open(filename, mode='r'):
942 if filename == 'srcfile':
943 return srcfile
944 if filename == 'destfile':
945 return destfile
946 assert 0 # shouldn't reach here.
947
948 self._set_shutil_open(_open)
949
950 self.assertRaises(IOError,
951 shutil.copyfile, 'srcfile', 'destfile')
952 self.assertTrue(srcfile._entered)
953 self.assertTrue(destfile._entered)
954 self.assertFalse(destfile._raised)
955 self.assertTrue(srcfile._exited_with[0] is None)
956 self.assertTrue(srcfile._raised)
957
Ronald Oussorenf51738b2011-05-06 10:23:04 +0200958 def test_move_dir_caseinsensitive(self):
959 # Renames a folder to the same name
960 # but a different case.
961
962 self.src_dir = tempfile.mkdtemp()
963 dst_dir = os.path.join(
964 os.path.dirname(self.src_dir),
965 os.path.basename(self.src_dir).upper())
966 self.assertNotEqual(self.src_dir, dst_dir)
967
968 try:
969 shutil.move(self.src_dir, dst_dir)
970 self.assertTrue(os.path.isdir(dst_dir))
971 finally:
972 if os.path.exists(dst_dir):
973 os.rmdir(dst_dir)
974
975
Tarek Ziadéae4d5c62010-05-05 22:27:31 +0000976
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000977def test_main():
Tarek Ziadéae4d5c62010-05-05 22:27:31 +0000978 support.run_unittest(TestShutil, TestMove, TestCopyFile)
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000979
Barry Warsaw7fc2cca2003-01-24 17:34:13 +0000980if __name__ == '__main__':
Walter Dörwald21d3a322003-05-01 17:45:56 +0000981 test_main()