]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add simple test for fcntl.flock()
authorChristian Heimes <christian@cheimes.de>
Thu, 5 Dec 2013 15:13:03 +0000 (16:13 +0100)
committerChristian Heimes <christian@cheimes.de>
Thu, 5 Dec 2013 15:13:03 +0000 (16:13 +0100)
Lib/test/test_fcntl.py

index c816d970d750f70c4097f018a8825c55e9851c0a..837fc16569a7cc53d49108fa82ef8994ab83a2d1 100644 (file)
@@ -115,6 +115,21 @@ class TestFcntl(unittest.TestCase):
         finally:
             os.close(fd)
 
+    def test_flock(self):
+        self.f = open(TESTFN, 'wb')
+        fileno = self.f.fileno()
+        fcntl.flock(fileno, fcntl.LOCK_SH)
+        fcntl.flock(fileno, fcntl.LOCK_UN)
+        fcntl.flock(self.f, fcntl.LOCK_SH | fcntl.LOCK_NB)
+        fcntl.flock(self.f, fcntl.LOCK_UN)
+        fcntl.flock(fileno, fcntl.LOCK_EX)
+        fcntl.flock(fileno, fcntl.LOCK_UN)
+
+        self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH)
+        self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)
+        self.assertRaises(OverflowError, fcntl.flock, _testcapi.INT_MAX+1,
+                          fcntl.LOCK_SH)
+
 
 def test_main():
     run_unittest(TestFcntl)