1 """Test program for the fcntl C module.
3 OS/2+EMX doesn't support the file locking operations.
11 from test
.test_support
import verbose
, TESTFN
, unlink
, run_unittest
13 # TODO - Write tests for flock() and lockf().
16 if sys
.platform
.startswith('atheos'):
21 except AttributeError:
26 if sys
.platform
in ('netbsd1', 'netbsd2', 'netbsd3',
27 'Darwin1.2', 'darwin',
28 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
29 'freebsd6', 'freebsd7', 'freebsd8',
30 'bsdos2', 'bsdos3', 'bsdos4',
31 'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
32 if struct
.calcsize('l') == 8:
38 lockdata
= struct
.pack(off_t
+ off_t
+ pid_t
+ 'hh', 0, 0, 0,
40 elif sys
.platform
in ['aix3', 'aix4', 'hp-uxB', 'unixware7']:
41 lockdata
= struct
.pack('hhlllii', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0, 0)
42 elif sys
.platform
in ['os2emx']:
45 lockdata
= struct
.pack('hh'+start_len
+'hh', fcntl
.F_WRLCK
, 0, 0, 0, 0, 0)
48 print 'struct.pack: ', repr(lockdata
)
51 lockdata
= get_lockdata()
54 class TestFcntl(unittest
.TestCase
):
64 def test_fcntl_fileno(self
):
65 # the example from the library docs
66 self
.f
= open(TESTFN
, 'w')
67 rv
= fcntl
.fcntl(self
.f
.fileno(), fcntl
.F_SETFL
, os
.O_NONBLOCK
)
69 print 'Status from fcntl with O_NONBLOCK: ', rv
70 if sys
.platform
not in ['os2emx']:
71 rv
= fcntl
.fcntl(self
.f
.fileno(), fcntl
.F_SETLKW
, lockdata
)
73 print 'String from fcntl with F_SETLKW: ', repr(rv
)
76 def test_fcntl_file_descriptor(self
):
77 # again, but pass the file rather than numeric descriptor
78 self
.f
= open(TESTFN
, 'w')
79 rv
= fcntl
.fcntl(self
.f
, fcntl
.F_SETFL
, os
.O_NONBLOCK
)
80 if sys
.platform
not in ['os2emx']:
81 rv
= fcntl
.fcntl(self
.f
, fcntl
.F_SETLKW
, lockdata
)
86 run_unittest(TestFcntl
)
88 if __name__
== '__main__':