Skip to content

Commit fe12363

Browse files
authored
Merge pull request #81 from lsst/tickets/DM-42698
DM-42698: Switch to the moto v5 API
2 parents bee90fe + a757480 commit fe12363

9 files changed

+44
-58
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
- id: trailing-whitespace
88
- id: check-toml
99
- repo: https://github.com/psf/black-pre-commit-mirror
10-
rev: 23.11.0
10+
rev: 24.1.1
1111
hooks:
1212
- id: black
1313
# It is recommended to specify the latest version of Python
@@ -16,13 +16,13 @@ repos:
1616
# https://pre-commit.com/#top_level-default_language_version
1717
language_version: python3.11
1818
- repo: https://github.com/pycqa/isort
19-
rev: 5.13.1
19+
rev: 5.13.2
2020
hooks:
2121
- id: isort
2222
name: isort (python)
2323
- repo: https://github.com/astral-sh/ruff-pre-commit
2424
# Ruff version.
25-
rev: v0.1.7
25+
rev: v0.1.14
2626
hooks:
2727
- id: ruff
2828
- repo: https://github.com/numpy/numpydoc

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ gs = [
4545
"google-cloud-storage",
4646
]
4747
test = [
48-
"moto >= 1.3",
48+
"moto >= 1.3,!=5.0.0",
4949
"pytest >= 3.2",
5050
"pytest-openfiles >= 0.5.0",
5151
"responses >= 0.12.0",

python/lsst/resources/_resourceHandles/_baseResourceHandle.py

+18-36
Original file line numberDiff line numberDiff line change
@@ -45,84 +45,66 @@ class ResourceHandleProtocol(Protocol, Generic[U]):
4545
"""
4646

4747
@abstractproperty
48-
def mode(self) -> str:
49-
...
48+
def mode(self) -> str: ...
5049

5150
@abstractmethod
52-
def close(self) -> None:
53-
...
51+
def close(self) -> None: ...
5452

5553
@abstractproperty
56-
def closed(self) -> bool:
57-
...
54+
def closed(self) -> bool: ...
5855

5956
@abstractmethod
60-
def fileno(self) -> int:
61-
...
57+
def fileno(self) -> int: ...
6258

6359
@abstractmethod
64-
def flush(self) -> None:
65-
...
60+
def flush(self) -> None: ...
6661

6762
@abstractproperty
68-
def isatty(self) -> bool | Callable[[], bool]:
69-
...
63+
def isatty(self) -> bool | Callable[[], bool]: ...
7064

7165
@abstractmethod
72-
def readable(self) -> bool:
73-
...
66+
def readable(self) -> bool: ...
7467

7568
@abstractmethod
76-
def readline(self, size: int = -1) -> U:
77-
...
69+
def readline(self, size: int = -1) -> U: ...
7870

7971
@abstractmethod
80-
def readlines(self, hint: int = -1) -> Iterable[U]:
81-
...
72+
def readlines(self, hint: int = -1) -> Iterable[U]: ...
8273

8374
@abstractmethod
8475
def seek(self, offset: int, whence: int = SEEK_SET, /) -> int:
8576
pass
8677

8778
@abstractmethod
88-
def seekable(self) -> bool:
89-
...
79+
def seekable(self) -> bool: ...
9080

9181
@abstractmethod
92-
def tell(self) -> int:
93-
...
82+
def tell(self) -> int: ...
9483

9584
@abstractmethod
96-
def truncate(self, size: int | None = None) -> int:
97-
...
85+
def truncate(self, size: int | None = None) -> int: ...
9886

9987
@abstractmethod
100-
def writable(self) -> bool:
101-
...
88+
def writable(self) -> bool: ...
10289

10390
@abstractmethod
104-
def writelines(self, lines: Iterable[U], /) -> None:
105-
...
91+
def writelines(self, lines: Iterable[U], /) -> None: ...
10692

10793
@abstractmethod
108-
def read(self, size: int = -1) -> U:
109-
...
94+
def read(self, size: int = -1) -> U: ...
11095

11196
@abstractmethod
112-
def write(self, b: U, /) -> int:
113-
...
97+
def write(self, b: U, /) -> int: ...
11498

115-
def __enter__(self: S) -> S:
116-
...
99+
def __enter__(self: S) -> S: ...
117100

118101
def __exit__(
119102
self,
120103
exc_type: type[BaseException] | None,
121104
exc_val: BaseException | None,
122105
exc_tb: TracebackType | None,
123106
/,
124-
) -> bool | None:
125-
...
107+
) -> bool | None: ...
126108

127109

128110
class BaseResourceHandle(ABC, ResourceHandleProtocol[U]):

python/lsst/resources/_resourcePath.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,7 @@ def findFileResources(
12711271
candidates: Iterable[ResourcePathExpression],
12721272
file_filter: str | re.Pattern | None,
12731273
grouped: Literal[True],
1274-
) -> Iterator[Iterator[ResourcePath]]:
1275-
...
1274+
) -> Iterator[Iterator[ResourcePath]]: ...
12761275

12771276
@overload
12781277
@classmethod
@@ -1281,8 +1280,7 @@ def findFileResources(
12811280
candidates: Iterable[ResourcePathExpression],
12821281
*,
12831282
grouped: Literal[True],
1284-
) -> Iterator[Iterator[ResourcePath]]:
1285-
...
1283+
) -> Iterator[Iterator[ResourcePath]]: ...
12861284

12871285
@overload
12881286
@classmethod
@@ -1291,8 +1289,7 @@ def findFileResources(
12911289
candidates: Iterable[ResourcePathExpression],
12921290
file_filter: str | re.Pattern | None = None,
12931291
grouped: Literal[False] = False,
1294-
) -> Iterator[ResourcePath]:
1295-
...
1292+
) -> Iterator[ResourcePath]: ...
12961293

12971294
@classmethod
12981295
def findFileResources(

python/lsst/resources/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ class TransactionProtocol(Protocol):
135135
"""Protocol for type checking transaction interface."""
136136

137137
@contextlib.contextmanager
138-
def undoWith(self, name: str, undoFunc: Callable, *args: Any, **kwargs: Any) -> Iterator[None]:
139-
...
138+
def undoWith(self, name: str, undoFunc: Callable, *args: Any, **kwargs: Any) -> Iterator[None]: ...
140139

141140

142141
def makeTestTempDir(default_base: str | None = None) -> str:

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ importlib_resources
55
backoff >= 1.10
66
boto3 >= 1.13
77
botocore >= 1.15
8-
moto >= 1.3
8+
moto >= 1.3,!=5.0.0
99
responses >= 0.12.0
1010
urllib3 >= 1.25.10
1111
requests >= 2.26.0

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
22
max-line-length = 110
33
max-doc-length = 79
4-
ignore = N802, N803, N806, N812, N815, N816, W503, E203
4+
ignore = N802, N803, N806, N812, N815, N816, W503, E203, E704
55
exclude = __init__.py

tests/test_s3.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
try:
2525
import boto3
2626
import botocore
27-
from moto import mock_s3
27+
28+
try:
29+
from moto import mock_aws # v5
30+
except ImportError:
31+
from moto import mock_s3 as mock_aws
2832
except ImportError:
2933
boto3 = None
3034

31-
def mock_s3(cls):
32-
"""No-op decorator in case moto mock_s3 can not be imported."""
35+
def mock_aws(cls):
36+
"""No-op decorator in case moto mock_aws can not be imported."""
3337
return cls
3438

3539

@@ -47,13 +51,13 @@ class S3ReadWriteTestCase(GenericReadWriteTestCase, unittest.TestCase):
4751
scheme = "s3"
4852
netloc = "my_2nd_bucket"
4953

50-
mock_s3 = mock_s3()
54+
mock_aws = mock_aws()
5155
"""The mocked s3 interface from moto."""
5256

5357
def setUp(self):
5458
self.enterContext(clean_test_environment_for_s3())
5559
# Enable S3 mocking of tests.
56-
self.mock_s3.start()
60+
self.mock_aws.start()
5761

5862
# MOTO needs to know that we expect Bucket bucketname to exist
5963
s3 = boto3.resource("s3")
@@ -77,7 +81,7 @@ def tearDown(self):
7781
bucket.delete()
7882

7983
# Stop the S3 mock.
80-
self.mock_s3.stop()
84+
self.mock_aws.stop()
8185

8286
S3ResourcePath.use_threads = None
8387

tests/test_s3utils.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
try:
2727
import boto3
2828
from botocore.exceptions import ParamValidationError
29-
from moto import mock_s3
29+
30+
try:
31+
from moto import mock_aws # v5
32+
except ImportError:
33+
from moto import mock_s3 as mock_aws
3034
except ImportError:
3135
boto3 = None
3236

@@ -44,7 +48,7 @@ class S3UtilsTestCase(unittest.TestCase):
4448

4549
def setUp(self):
4650
self.enterContext(clean_test_environment_for_s3())
47-
self.enterContext(mock_s3())
51+
self.enterContext(mock_aws())
4852

4953
self.client = getS3Client()
5054
try:

0 commit comments

Comments
 (0)