|
6 | 6 | import os |
7 | 7 | import struct |
8 | 8 | import sys |
| 9 | +import _testcapi |
9 | 10 | import unittest |
10 | 11 | from test.test_support import (verbose, TESTFN, unlink, run_unittest, |
11 | 12 | import_module) |
@@ -81,6 +82,26 @@ def test_fcntl_file_descriptor(self): |
81 | 82 | rv = fcntl.fcntl(self.f, fcntl.F_SETLKW, lockdata) |
82 | 83 | self.f.close() |
83 | 84 |
|
| 85 | + def test_fcntl_bad_file(self): |
| 86 | + class F: |
| 87 | + def __init__(self, fn): |
| 88 | + self.fn = fn |
| 89 | + def fileno(self): |
| 90 | + return self.fn |
| 91 | + self.assertRaises(ValueError, fcntl.fcntl, -1, fcntl.F_SETFL, os.O_NONBLOCK) |
| 92 | + self.assertRaises(ValueError, fcntl.fcntl, F(-1), fcntl.F_SETFL, os.O_NONBLOCK) |
| 93 | + self.assertRaises(TypeError, fcntl.fcntl, 'spam', fcntl.F_SETFL, os.O_NONBLOCK) |
| 94 | + self.assertRaises(TypeError, fcntl.fcntl, F('spam'), fcntl.F_SETFL, os.O_NONBLOCK) |
| 95 | + # Issue 15989 |
| 96 | + self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MAX + 1, |
| 97 | + fcntl.F_SETFL, os.O_NONBLOCK) |
| 98 | + self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MAX + 1), |
| 99 | + fcntl.F_SETFL, os.O_NONBLOCK) |
| 100 | + self.assertRaises(ValueError, fcntl.fcntl, _testcapi.INT_MIN - 1, |
| 101 | + fcntl.F_SETFL, os.O_NONBLOCK) |
| 102 | + self.assertRaises(ValueError, fcntl.fcntl, F(_testcapi.INT_MIN - 1), |
| 103 | + fcntl.F_SETFL, os.O_NONBLOCK) |
| 104 | + |
84 | 105 | def test_fcntl_64_bit(self): |
85 | 106 | # Issue #1309352: fcntl shouldn't fail when the third arg fits in a |
86 | 107 | # C 'long' but not in a C 'int'. |
|
0 commit comments