Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a956f1

Browse files
committed
Add simple test for fcntl.flock()
1 parent ac98a4e commit 0a956f1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_fcntl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ def test_fcntl_64_bit(self):
115115
finally:
116116
os.close(fd)
117117

118+
def test_flock(self):
119+
self.f = open(TESTFN, 'wb')
120+
fileno = self.f.fileno()
121+
fcntl.flock(fileno, fcntl.LOCK_SH)
122+
fcntl.flock(fileno, fcntl.LOCK_UN)
123+
fcntl.flock(self.f, fcntl.LOCK_SH | fcntl.LOCK_NB)
124+
fcntl.flock(self.f, fcntl.LOCK_UN)
125+
fcntl.flock(fileno, fcntl.LOCK_EX)
126+
fcntl.flock(fileno, fcntl.LOCK_UN)
127+
128+
self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH)
129+
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)
130+
self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
131+
fcntl.LOCK_SH)
132+
118133

119134
def test_main():
120135
run_unittest(TestFcntl)

0 commit comments

Comments
 (0)