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