-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
bpo-36746: Create test for fcntl.lockf() #12999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ | |
fcntl = import_module('fcntl') | ||
|
||
|
||
# TODO - Write tests for flock() and lockf(). | ||
|
||
def get_lockdata(): | ||
try: | ||
os.O_LARGEFILE | ||
|
@@ -138,6 +136,39 @@ def test_flock(self): | |
self.assertRaises(ValueError, fcntl.flock, -1, fcntl.LOCK_SH) | ||
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH) | ||
|
||
def test_lockf(self): | ||
|
||
self.f = open(TESTFN, 'wb+') | ||
|
||
self.assertRaises(TypeError, fcntl.lockf, self.f, "foo") | ||
self.assertRaises(TypeError, fcntl.lockf, self.f, fcntl.LOCK_UN, "foo") | ||
self.assertRaises(ValueError, fcntl.lockf, self.f, -256) | ||
self.assertRaises(ValueError, fcntl.lockf, self.f, 256) | ||
|
||
fcntl.lockf(self.f, fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
rval = 2 | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
fcntl.lockf(open(self.f.name, self.f.mode), fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line causes a
|
||
except IOError as e: | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if e.errno not in (errno.EACCES, errno.EAGAIN): | ||
raise | ||
rval = 0 | ||
else: | ||
rval = 1 | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
finally: | ||
os._exit(rval) | ||
|
||
assert pid > 0 | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
(pid, status) = os.waitpid(pid, 0) | ||
self.assertEqual(os.WIFEXITED(status), True) | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fcntl.lockf(self.f, fcntl.LOCK_UN) | ||
|
||
self.f.close() | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this is redundant since |
||
|
||
@cpython_only | ||
def test_flock_overflow(self): | ||
import _testcapi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A test for `fcntl.lockf()` is now implemented. | ||
nanjekyejoannah marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.