diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 20:32:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 20:32:47 (GMT) |
commit | 1db9e7bb19909ed56821b1580cbb024faccac041 (patch) | |
tree | 20043197ec08844340c9ac039fe26c630bd4189d /Lib/test/test_os.py | |
parent | 6aa4269ed25f7fdddd99fe1d7b09b8406ecb05ea (diff) | |
download | cpython-1db9e7bb19909ed56821b1580cbb024faccac041.zip cpython-1db9e7bb19909ed56821b1580cbb024faccac041.tar.gz cpython-1db9e7bb19909ed56821b1580cbb024faccac041.tar.bz2 |
Issue #22054: Add os.get_blocking() and os.set_blocking() functions to get and
set the blocking mode of a file descriptor (False if the O_NONBLOCK flag is
set, True otherwise). These functions are not available on Windows.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r-- | Lib/test/test_os.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index e669df8..020d0fa 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1376,6 +1376,16 @@ class TestInvalidFD(unittest.TestCase): def test_writev(self): self.check(os.writev, [b'abc']) + def test_inheritable(self): + self.check(os.get_inheritable) + self.check(os.set_inheritable, True) + + @unittest.skipUnless(hasattr(os, 'get_blocking'), + 'needs os.get_blocking() and os.set_blocking()') + def test_blocking(self): + self.check(os.get_blocking) + self.check(os.set_blocking, True) + class LinkTests(unittest.TestCase): def setUp(self): @@ -2591,6 +2601,21 @@ class FDInheritanceTests(unittest.TestCase): self.assertEqual(os.get_inheritable(slave_fd), False) +@unittest.skipUnless(hasattr(os, 'get_blocking'), + 'needs os.get_blocking() and os.set_blocking()') +class BlockingTests(unittest.TestCase): + def test_blocking(self): + fd = os.open(__file__, os.O_RDONLY) + self.addCleanup(os.close, fd) + self.assertEqual(os.get_blocking(fd), True) + + os.set_blocking(fd, False) + self.assertEqual(os.get_blocking(fd), False) + + os.set_blocking(fd, True) + self.assertEqual(os.get_blocking(fd), True) + + @support.reap_threads def test_main(): support.run_unittest( @@ -2626,6 +2651,7 @@ def test_main(): CPUCountTests, FDInheritanceTests, Win32JunctionTests, + BlockingTests, ) if __name__ == "__main__": |