Skip to content

Commit cada500

Browse files
committed
Fixed several bugs with the testing suite.
1 parent d42529f commit cada500

7 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎portalocker/__about__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
__author__ = 'Rick van Hattem'
33
__email__ = '[email protected]'
44
__version__ = '2.10.1'
5-
__description__ = """Wraps the portalocker recipe for easy usage"""
5+
__description__ = '''Wraps the portalocker recipe for easy usage'''
66
__url__ = 'https://github.com/WoLpH/portalocker'

‎portalocker/__main__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def _read_file(
6060
paren = False
6161
from_ = None
6262
for line in path.open():
63+
if '__future__' in line:
64+
continue
65+
6366
if paren:
6467
if ')' in line:
6568
line = line.split(')', 1)[1]
@@ -101,6 +104,9 @@ def combine(args: argparse.Namespace):
101104
output_file = args.output_file
102105
pathlib.Path(output_file.name).parent.mkdir(parents=True, exist_ok=True)
103106

107+
# We're handling this separately because it has to be the first import.
108+
output_file.write('from __future__ import annotations\n')
109+
104110
output_file.write(
105111
_TEXT_TEMPLATE.format((base_path / 'README.rst').read_text()),
106112
)

‎portalocker/constants.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
'''
22
Locking constants
33
44
Lock types:
@@ -13,7 +13,7 @@
1313
Manually unlock, only needed internally
1414
1515
- `UNBLOCK` unlock
16-
"""
16+
'''
1717

1818
import enum
1919
import os

‎portalocker/redis.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# pyright: reportUnknownMemberType=false
2+
from __future__ import annotations
3+
24
import _thread
35
import json
46
import logging
@@ -26,7 +28,7 @@ def run(self) -> None:
2628

2729

2830
class RedisLock(utils.LockBase):
29-
"""
31+
'''
3032
An extremely reliable Redis lock based on pubsub with a keep-alive thread
3133
3234
As opposed to most Redis locking systems based on key/value pairs,
@@ -60,7 +62,7 @@ class RedisLock(utils.LockBase):
6062
to override these you need to explicitly specify a value (e.g.
6163
`health_check_interval=0`)
6264
63-
"""
65+
'''
6466

6567
redis_kwargs: typing.Dict[str, typing.Any]
6668
thread: typing.Optional[PubSubWorkerThread]
@@ -137,7 +139,7 @@ def acquire( # type: ignore[override]
137139
timeout: typing.Optional[float] = None,
138140
check_interval: typing.Optional[float] = None,
139141
fail_when_locked: typing.Optional[bool] = None,
140-
) -> 'RedisLock':
142+
) -> RedisLock:
141143
timeout = utils.coalesce(timeout, self.timeout, 0.0)
142144
check_interval = utils.coalesce(
143145
check_interval,

‎portalocker/utils.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def acquire(
247247
check_interval: typing.Optional[float] = None,
248248
fail_when_locked: typing.Optional[bool] = None,
249249
) -> typing.IO[typing.AnyStr]:
250-
"""Acquire the locked filehandle"""
250+
'''Acquire the locked filehandle'''
251251

252252
fail_when_locked = coalesce(fail_when_locked, self.fail_when_locked)
253253

@@ -316,14 +316,14 @@ def __enter__(self) -> typing.IO[typing.AnyStr]:
316316
return self.acquire()
317317

318318
def release(self):
319-
"""Releases the currently locked file handle"""
319+
'''Releases the currently locked file handle'''
320320
if self.fh:
321321
portalocker.unlock(self.fh)
322322
self.fh.close()
323323
self.fh = None
324324

325325
def _get_fh(self) -> types.IO:
326-
"""Get a new filehandle"""
326+
'''Get a new filehandle'''
327327
return typing.cast(
328328
types.IO,
329329
open( # noqa: SIM115
@@ -334,20 +334,20 @@ def _get_fh(self) -> types.IO:
334334
)
335335

336336
def _get_lock(self, fh: types.IO) -> types.IO:
337-
"""
337+
'''
338338
Try to lock the given filehandle
339339
340-
returns LockException if it fails"""
340+
returns LockException if it fails'''
341341
portalocker.lock(fh, self.flags)
342342
return fh
343343

344344
def _prepare_fh(self, fh: types.IO) -> types.IO:
345-
"""
345+
'''
346346
Prepare the filehandle for usage
347347
348348
If truncate is a number, the file will be truncated to that amount of
349349
bytes
350-
"""
350+
'''
351351
if self.truncate:
352352
fh.seek(0)
353353
fh.truncate(0)
@@ -356,11 +356,11 @@ def _prepare_fh(self, fh: types.IO) -> types.IO:
356356

357357

358358
class RLock(Lock):
359-
"""
359+
'''
360360
A reentrant lock, functions in a similar way to threading.RLock in that it
361361
can be acquired multiple times. When the corresponding number of release()
362362
calls are made the lock will finally release the underlying file lock.
363-
"""
363+
'''
364364

365365
def __init__(
366366
self,

‎portalocker_tests/conftest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ def pytest_sessionstart(session):
2727

2828
@pytest.fixture(autouse=True)
2929
def reduce_timeouts(monkeypatch):
30-
"For faster testing we reduce the timeouts."
30+
'For faster testing we reduce the timeouts.'
3131
monkeypatch.setattr(utils, 'DEFAULT_TIMEOUT', 0.1)
3232
monkeypatch.setattr(utils, 'DEFAULT_CHECK_INTERVAL', 0.05)

‎portalocker_tests/tests.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_lock_fileno(tmpfile, locker):
412412
)
413413
@pytest.mark.parametrize('locker', LOCKERS, indirect=True)
414414
def test_locker_mechanism(tmpfile, locker):
415-
"""Can we switch the locking mechanism?"""
415+
'''Can we switch the locking mechanism?'''
416416
# We can test for flock vs lockf based on their different behaviour re.
417417
# locking the same file.
418418
with portalocker.Lock(tmpfile, 'a+', flags=LockFlags.EXCLUSIVE):
@@ -434,7 +434,7 @@ def test_locker_mechanism(tmpfile, locker):
434434

435435

436436
def test_exception(monkeypatch, tmpfile):
437-
"""Do we stop immediately if the locking fails, even with a timeout?"""
437+
'''Do we stop immediately if the locking fails, even with a timeout?'''
438438

439439
def patched_lock(*args, **kwargs):
440440
raise ValueError('Test exception')

0 commit comments

Comments
 (0)