]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add tests for posix O_SHLOCK & O_EXLOCK. Missed checking this in with
authorSkip Montanaro <skip@pobox.com>
Fri, 17 Jun 2005 01:14:49 +0000 (01:14 +0000)
committerSkip Montanaro <skip@pobox.com>
Fri, 17 Jun 2005 01:14:49 +0000 (01:14 +0000)
posixmodule.c 2.335.  Really should be considered part of patch #1103951.

Lib/test/test_posix.py

index 24e5b1ced62339a2369ce9969b84dbcafb53877b..1ccc62bdf27dcbccbf2428cade8b8fe70880faa8 100644 (file)
@@ -94,6 +94,37 @@ class PosixTester(unittest.TestCase):
             self.fdopen_helper('r')
             self.fdopen_helper('r', 100)
 
+    def test_osexlock(self):
+        if hasattr(posix, "O_EXLOCK"):
+            fd = os.open(test_support.TESTFN,
+                         os.O_WRONLY|os.O_EXLOCK|os.O_CREAT)
+            self.assertRaises(OSError, os.open, test_support.TESTFN,
+                              os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
+            os.close(fd)
+
+            if hasattr(posix, "O_SHLOCK"):
+                fd = os.open(test_support.TESTFN,
+                             os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
+                self.assertRaises(OSError, os.open, test_support.TESTFN,
+                                  os.O_WRONLY|os.O_EXLOCK|os.O_NONBLOCK)
+                os.close(fd)
+
+    def test_osshlock(self):
+        if hasattr(posix, "O_SHLOCK"):
+            fd1 = os.open(test_support.TESTFN,
+                         os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
+            fd2 = os.open(test_support.TESTFN,
+                          os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
+            os.close(fd2)
+            os.close(fd1)
+
+            if hasattr(posix, "O_EXLOCK"):
+                fd = os.open(test_support.TESTFN,
+                             os.O_WRONLY|os.O_SHLOCK|os.O_CREAT)
+                self.assertRaises(OSError, os.open, test_support.TESTFN,
+                                  os.O_RDONLY|os.O_EXLOCK|os.O_NONBLOCK)
+                os.close(fd)
+
     def test_fstat(self):
         if hasattr(posix, 'fstat'):
             fp = open(test_support.TESTFN)