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

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

Issue 26826: Expose new copy_file_range() syscal in os module and use it to improve shutils.copy()
Patch Set: Created 3 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
OLDNEW
1 # As a test suite for the os module, this is woefully inadequate, but this 1 # As a test suite for the os module, this is woefully inadequate, but this
2 # does add tests for a few functions which have been determined to be more 2 # does add tests for a few functions which have been determined to be more
3 # portable than they had been thought to be. 3 # portable than they had been thought to be.
4 4
5 import asynchat 5 import asynchat
6 import asyncore 6 import asyncore
7 import codecs 7 import codecs
8 import contextlib 8 import contextlib
9 import decimal 9 import decimal
10 import errno 10 import errno
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 # and unmaintained) linuxthreads threading library. There's an issue 74 # and unmaintained) linuxthreads threading library. There's an issue
75 # when combining linuxthreads with a failed execv call: see 75 # when combining linuxthreads with a failed execv call: see
76 # http://bugs.python.org/issue4970. 76 # http://bugs.python.org/issue4970.
77 if hasattr(sys, 'thread_info') and sys.thread_info.version: 77 if hasattr(sys, 'thread_info') and sys.thread_info.version:
78 USING_LINUXTHREADS = sys.thread_info.version.startswith("linuxthreads") 78 USING_LINUXTHREADS = sys.thread_info.version.startswith("linuxthreads")
79 else: 79 else:
80 USING_LINUXTHREADS = False 80 USING_LINUXTHREADS = False
81 81
82 # Issue #14110: Some tests fail on FreeBSD if the user is in the wheel group. 82 # Issue #14110: Some tests fail on FreeBSD if the user is in the wheel group.
83 HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0 83 HAVE_WHEEL_GROUP = sys.platform.startswith('freebsd') and os.getgid() == 0
84
85 84
86 @contextlib.contextmanager 85 @contextlib.contextmanager
87 def ignore_deprecation_warnings(msg_regex, quiet=False): 86 def ignore_deprecation_warnings(msg_regex, quiet=False):
88 with support.check_warnings((msg_regex, DeprecationWarning), quiet=quiet): 87 with support.check_warnings((msg_regex, DeprecationWarning), quiet=quiet):
89 yield 88 yield
90 89
91 90
92 @contextlib.contextmanager 91 @contextlib.contextmanager
93 def bytes_filename_warn(expected): 92 def bytes_filename_warn(expected):
94 msg = 'The Windows bytes API has been deprecated' 93 msg = 'The Windows bytes API has been deprecated'
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 dir_fd=None) 235 dir_fd=None)
237 os.close(f) 236 os.close(f)
238 237
239 def test_symlink_keywords(self): 238 def test_symlink_keywords(self):
240 symlink = support.get_attribute(os, "symlink") 239 symlink = support.get_attribute(os, "symlink")
241 try: 240 try:
242 symlink(src='target', dst=support.TESTFN, 241 symlink(src='target', dst=support.TESTFN,
243 target_is_directory=False, dir_fd=None) 242 target_is_directory=False, dir_fd=None)
244 except (NotImplementedError, OSError): 243 except (NotImplementedError, OSError):
245 pass # No OS support or unprivileged user 244 pass # No OS support or unprivileged user
245
246 @unittest.skipUnless(hasattr(os, 'copy_file_range'), 'test needs os.copy_fil e_range()')
247 def test_copy_file_range_ok(self):
248 TESTFN2 = support.TESTFN + ".3"
249
250 create_file(support.TESTFN, b'0123456789')
251 self.addCleanup(support.unlink, support.TESTFN)
252
253 in_file = open (support.TESTFN, 'rb')
254 self.addCleanup(in_file.close)
255 in_fd = in_file.fileno()
256
257 out_file = open (TESTFN2, 'w+b')
258 self.addCleanup(support.unlink, TESTFN2)
259 self.addCleanup(out_file.close)
260 out_fd = out_file.fileno()
261
262 i = os.copy_file_range (in_fd, out_fd, 5);
Martin Panter 2016/06/09 10:53:01 Probably should skip if it raises ENOSYS too. E.g.
263 self.assertEqual (i, 5);
Martin Panter 2016/06/09 10:53:01 The man page says it can return less than the requ
264
265 in_file = open (TESTFN2, 'rb')
266 self.assertEqual (in_file.read(), b'01234')
246 267
247 268
248 # Test attributes on return values from os.*stat* family. 269 # Test attributes on return values from os.*stat* family.
249 class StatAttributeTests(unittest.TestCase): 270 class StatAttributeTests(unittest.TestCase):
250 def setUp(self): 271 def setUp(self):
251 self.fname = support.TESTFN 272 self.fname = support.TESTFN
252 self.addCleanup(support.unlink, self.fname) 273 self.addCleanup(support.unlink, self.fname)
253 create_file(self.fname, b"ABC") 274 create_file(self.fname, b"ABC")
254 275
255 @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()') 276 @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()')
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 def test_inheritable(self): 1573 def test_inheritable(self):
1553 self.check(os.get_inheritable) 1574 self.check(os.get_inheritable)
1554 self.check(os.set_inheritable, True) 1575 self.check(os.set_inheritable, True)
1555 1576
1556 @unittest.skipUnless(hasattr(os, 'get_blocking'), 1577 @unittest.skipUnless(hasattr(os, 'get_blocking'),
1557 'needs os.get_blocking() and os.set_blocking()') 1578 'needs os.get_blocking() and os.set_blocking()')
1558 def test_blocking(self): 1579 def test_blocking(self):
1559 self.check(os.get_blocking) 1580 self.check(os.get_blocking)
1560 self.check(os.set_blocking, True) 1581 self.check(os.set_blocking, True)
1561 1582
1583 @unittest.skipUnless(hasattr(os, 'copy_file_range'), 'test needs os.copy_fil e_range()')
1584 def test_copy_file_range_in(self):
1585 self.check(os.copy_file_range, 0, 0)
1562 1586
1563 class LinkTests(unittest.TestCase): 1587 class LinkTests(unittest.TestCase):
1564 def setUp(self): 1588 def setUp(self):
1565 self.file1 = support.TESTFN 1589 self.file1 = support.TESTFN
1566 self.file2 = os.path.join(support.TESTFN + "2") 1590 self.file2 = os.path.join(support.TESTFN + "2")
1567 1591
1568 def tearDown(self): 1592 def tearDown(self):
1569 for file in (self.file1, self.file2): 1593 for file in (self.file1, self.file2):
1570 if os.path.exists(file): 1594 if os.path.exists(file):
1571 os.unlink(file) 1595 os.unlink(file)
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 for o in int, type, os, vapor(): 3166 for o in int, type, os, vapor():
3143 self.assertRaises(TypeError, os.fspath, o) 3167 self.assertRaises(TypeError, os.fspath, o)
3144 3168
3145 def test_argument_required(self): 3169 def test_argument_required(self):
3146 with self.assertRaises(TypeError): 3170 with self.assertRaises(TypeError):
3147 os.fspath() 3171 os.fspath()
3148 3172
3149 3173
3150 if __name__ == "__main__": 3174 if __name__ == "__main__":
3151 unittest.main() 3175 unittest.main()
OLDNEW
« Doc/library/os.rst ('K') | « Doc/library/os.rst ('k') | Modules/posixmodule.c » ('j') | no next file with comments »

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