[issue12196] add pipe2() to the os module
Charles-François Natali
report at bugs.python.org
Mon May 30 19:23:48 CEST 2011
Charles-François Natali <neologix at free.fr> added the comment:
> support.linux_version() may be changed for requires_linux_version(2, 6, 27),
>
> but linux_version() is always used in tests to check the Linux version.
> requires_linux_version() would only raise a SkipTest if the OS is Linux and
> if
> the kernel is lesser than the specified version.
>
See the patch attached.
> By the way, I like the new os.pipe2() function! You may want to document it
> in
> the "What's new in Python 3.3" doc (just mention the new function, the
> document will be rephrased later).
>
Sure, where is this document?
----------
Added file: http://bugs.python.org/file22197/support_linux_version.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12196>
_______________________________________
-------------- next part --------------
diff -r f73d80d0ba44 Lib/test/support.py
--- a/Lib/test/support.py Mon May 30 11:15:05 2011 -0500
+++ b/Lib/test/support.py Mon May 30 19:21:14 2011 +0200
@@ -291,13 +291,17 @@
msg = "Use of the `%s' resource not enabled" % resource
raise ResourceDenied(msg)
-def linux_version():
- try:
- # platform.release() is something like '2.6.33.7-desktop-2mnb'
- version_string = platform.release().split('-')[0]
- return tuple(map(int, version_string.split('.')))
- except ValueError:
- return 0, 0, 0
+def requires_linux_version(*min_version):
+ if sys.platform.startswith('linux'):
+ try:
+ # platform.release() is something like '2.6.33.7-desktop-2mnb'
+ version_string = platform.release().split('-')[0]
+ version = tuple(map(int, version_string.split('.')))
+ if version < min_version:
+ raise unittest.SkipTest("Linux kernel %s or higher required" %
+ ".".join(map(str, min_version)))
+ except ValueError:
+ pass
HOST = 'localhost'
diff -r f73d80d0ba44 Lib/test/test_posix.py
--- a/Lib/test/test_posix.py Mon May 30 11:15:05 2011 -0500
+++ b/Lib/test/test_posix.py Mon May 30 19:21:14 2011 +0200
@@ -310,10 +310,7 @@
@unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
def test_oscloexec(self):
- version = support.linux_version()
- if sys.platform == 'linux2' and version < (2, 6, 23):
- self.skipTest("Linux kernel 2.6.23 or higher required, "
- "not %s.%s.%s" % version)
+ support.requires_linux_version(2, 6, 23)
fd = os.open(support.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
self.addCleanup(os.close, fd)
self.assertTrue(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC)
@@ -480,10 +477,7 @@
@unittest.skipUnless(hasattr(os, 'pipe2'), "test needs os.pipe2()")
def test_pipe2(self):
- version = support.linux_version()
- if sys.platform == 'linux2' and version < (2, 6, 27):
- self.skipTest("Linux kernel 2.6.27 or higher required, "
- "not %s.%s.%s" % version)
+ support.requires_linux_version(2, 6, 27)
self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
self.assertRaises(TypeError, os.pipe2, 0, 0)
diff -r f73d80d0ba44 Lib/test/test_socket.py
--- a/Lib/test/test_socket.py Mon May 30 11:15:05 2011 -0500
+++ b/Lib/test/test_socket.py Mon May 30 19:21:14 2011 +0200
@@ -1024,10 +1024,7 @@
if hasattr(socket, "SOCK_NONBLOCK"):
def testInitNonBlocking(self):
- v = support.linux_version()
- if v < (2, 6, 28):
- self.skipTest("Linux kernel 2.6.28 or higher required, not %s"
- % ".".join(map(str, v)))
+ support.requires_linux_version(2, 6, 28)
# reinit server socket
self.serv.close()
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM |
@@ -2002,10 +1999,7 @@
@unittest.skipUnless(fcntl, "module fcntl not available")
class CloexecConstantTest(unittest.TestCase):
def test_SOCK_CLOEXEC(self):
- v = support.linux_version()
- if v < (2, 6, 28):
- self.skipTest("Linux kernel 2.6.28 or higher required, not %s"
- % ".".join(map(str, v)))
+ support.requires_linux_version(2, 6, 28)
with socket.socket(socket.AF_INET,
socket.SOCK_STREAM | socket.SOCK_CLOEXEC) as s:
self.assertTrue(s.type & socket.SOCK_CLOEXEC)
@@ -2024,10 +2018,7 @@
self.assertEqual(s.gettimeout(), None)
def test_SOCK_NONBLOCK(self):
- v = support.linux_version()
- if v < (2, 6, 28):
- self.skipTest("Linux kernel 2.6.28 or higher required, not %s"
- % ".".join(map(str, v)))
+ support.requires_linux_version(2, 6, 28)
# a lot of it seems silly and redundant, but I wanted to test that
# changing back and forth worked ok
with socket.socket(socket.AF_INET,
More information about the Python-bugs-list
mailing list