Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/test/test_shutil.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_runpy.py ('k') | Lib/test/test_signal.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2003 Python Software Foundation 1 # Copyright (C) 2003 Python Software Foundation
2 2
3 import unittest 3 import unittest
4 import shutil 4 import shutil
5 import tempfile 5 import tempfile
6 import sys 6 import sys
7 import stat 7 import stat
8 import os 8 import os
9 import os.path 9 import os.path
10 import functools 10 import functools
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 self.assertRaises(OSError, shutil.rmtree, filename) 100 self.assertRaises(OSError, shutil.rmtree, filename)
101 101
102 # See bug #1071513 for why we don't run this on cygwin 102 # 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. 103 # and bug #1076467 for why we don't run this as root.
104 if (hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin' 104 if (hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin'
105 and not (hasattr(os, 'geteuid') and os.geteuid() == 0)): 105 and not (hasattr(os, 'geteuid') and os.geteuid() == 0)):
106 def test_on_error(self): 106 def test_on_error(self):
107 self.errorState = 0 107 self.errorState = 0
108 os.mkdir(TESTFN) 108 os.mkdir(TESTFN)
109 self.childpath = os.path.join(TESTFN, 'a') 109 self.childpath = os.path.join(TESTFN, 'a')
110 support.create_empty_file(self.childpath) 110 f = open(self.childpath, 'w')
111 f.close()
111 old_dir_mode = os.stat(TESTFN).st_mode 112 old_dir_mode = os.stat(TESTFN).st_mode
112 old_child_mode = os.stat(self.childpath).st_mode 113 old_child_mode = os.stat(self.childpath).st_mode
113 # Make unwritable. 114 # Make unwritable.
114 os.chmod(self.childpath, stat.S_IREAD) 115 os.chmod(self.childpath, stat.S_IREAD)
115 os.chmod(TESTFN, stat.S_IREAD) 116 os.chmod(TESTFN, stat.S_IREAD)
116 117
117 shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror) 118 shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
118 # Test whether onerror has actually been called. 119 # Test whether onerror has actually been called.
119 self.assertEqual(self.errorState, 2, 120 self.assertEqual(self.errorState, 2,
120 "Expected call to onerror function did not happen." ) 121 "Expected call to onerror function did not happen." )
(...skipping 27 matching lines...) Expand all
148 self.errorState = 1 149 self.errorState = 1
149 else: 150 else:
150 self.assertEqual(func, os.rmdir) 151 self.assertEqual(func, os.rmdir)
151 self.assertEqual(arg, TESTFN) 152 self.assertEqual(arg, TESTFN)
152 self.assertTrue(issubclass(exc[0], OSError)) 153 self.assertTrue(issubclass(exc[0], OSError))
153 self.errorState = 2 154 self.errorState = 2
154 155
155 def test_rmtree_dont_delete_file(self): 156 def test_rmtree_dont_delete_file(self):
156 # When called on a file instead of a directory, don't delete it. 157 # When called on a file instead of a directory, don't delete it.
157 handle, path = tempfile.mkstemp() 158 handle, path = tempfile.mkstemp()
158 os.close(handle) 159 os.fdopen(handle).close()
159 self.assertRaises(OSError, shutil.rmtree, path) 160 self.assertRaises(OSError, shutil.rmtree, path)
160 os.remove(path) 161 os.remove(path)
161 162
162 def _write_data(self, path, data): 163 def _write_data(self, path, data):
163 f = open(path, "w") 164 f = open(path, "w")
164 f.write(data) 165 f.write(data)
165 f.close() 166 f.close()
166 167
167 def test_copytree_simple(self): 168 def test_copytree_simple(self):
168 169
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return (file1, file2) 415 return (file1, file2)
415 416
416 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod') 417 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
417 def test_copy(self): 418 def test_copy(self):
418 # Ensure that the copied file exists and has the same mode bits. 419 # Ensure that the copied file exists and has the same mode bits.
419 file1, file2 = self._copy_file(shutil.copy) 420 file1, file2 = self._copy_file(shutil.copy)
420 self.assertTrue(os.path.exists(file2)) 421 self.assertTrue(os.path.exists(file2))
421 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode) 422 self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode)
422 423
423 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod') 424 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod')
424 @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime') 425 @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.utime')
425 def test_copy2(self): 426 def test_copy2(self):
426 # Ensure that the copied file exists and has the same mode and 427 # Ensure that the copied file exists and has the same mode and
427 # modification time bits. 428 # modification time bits.
428 file1, file2 = self._copy_file(shutil.copy2) 429 file1, file2 = self._copy_file(shutil.copy2)
429 self.assertTrue(os.path.exists(file2)) 430 self.assertTrue(os.path.exists(file2))
430 file1_stat = os.stat(file1) 431 file1_stat = os.stat(file1)
431 file2_stat = os.stat(file2) 432 file2_stat = os.stat(file2)
432 self.assertEqual(file1_stat.st_mode, file2_stat.st_mode) 433 self.assertEqual(file1_stat.st_mode, file2_stat.st_mode)
433 for attr in 'st_atime', 'st_mtime': 434 for attr in 'st_atime', 'st_mtime':
434 # The modification times may be truncated in the new file. 435 # The modification times may be truncated in the new file.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 721
721 # should work now 722 # should work now
722 unregister_unpack_format('Boo') 723 unregister_unpack_format('Boo')
723 register_unpack_format('Boo2', ['.boo'], _boo) 724 register_unpack_format('Boo2', ['.boo'], _boo)
724 self.assertIn(('Boo2', ['.boo'], ''), get_unpack_formats()) 725 self.assertIn(('Boo2', ['.boo'], ''), get_unpack_formats())
725 self.assertNotIn(('Boo', ['.boo'], ''), get_unpack_formats()) 726 self.assertNotIn(('Boo', ['.boo'], ''), get_unpack_formats())
726 727
727 # let's leave a clean state 728 # let's leave a clean state
728 unregister_unpack_format('Boo2') 729 unregister_unpack_format('Boo2')
729 self.assertEqual(get_unpack_formats(), formats) 730 self.assertEqual(get_unpack_formats(), formats)
730
731 @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())
735 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)
740 731
741 732
742 class TestMove(unittest.TestCase): 733 class TestMove(unittest.TestCase):
743 734
744 def setUp(self): 735 def setUp(self):
745 filename = "foo" 736 filename = "foo"
746 self.src_dir = tempfile.mkdtemp() 737 self.src_dir = tempfile.mkdtemp()
747 self.dst_dir = tempfile.mkdtemp() 738 self.dst_dir = tempfile.mkdtemp()
748 self.src_file = os.path.join(self.src_dir, filename) 739 self.src_file = os.path.join(self.src_dir, filename)
749 self.dst_file = os.path.join(self.dst_dir, filename) 740 self.dst_file = os.path.join(self.dst_dir, filename)
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 if os.path.exists(dst_dir): 963 if os.path.exists(dst_dir):
973 os.rmdir(dst_dir) 964 os.rmdir(dst_dir)
974 965
975 966
976 967
977 def test_main(): 968 def test_main():
978 support.run_unittest(TestShutil, TestMove, TestCopyFile) 969 support.run_unittest(TestShutil, TestMove, TestCopyFile)
979 970
980 if __name__ == '__main__': 971 if __name__ == '__main__':
981 test_main() 972 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_runpy.py ('k') | Lib/test/test_signal.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+