Skip to content

Commit

Permalink
Support moto 4 & 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Feb 19, 2024
1 parent 2ad2305 commit 7aeff9d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 61 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def read(fname):

all_deps = aws_deps + gcs_deps + azure_deps + http_deps + ssh_deps
tests_require = all_deps + [
'moto[server]<5.0',
'moto[server]',
'responses',
'boto3',
'pytest',
Expand Down
32 changes: 18 additions & 14 deletions smart_open/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import boto3
import botocore.client
import botocore.endpoint
import moto
import pytest

try:
from moto import mock_s3
except ImportError:
from moto import mock_aws as mock_s3

import smart_open
import smart_open.s3

Expand Down Expand Up @@ -189,7 +193,7 @@ def test_every_second_read_fails(self):
mock_sleep.reset_mock()


@moto.mock_s3
@mock_s3
class ReaderTest(BaseTest):
def setUp(self):
# lower the multipart upload size, to speed up these tests
Expand Down Expand Up @@ -411,7 +415,7 @@ def test_read_empty_file_no_actual_size(self):
self.assertEqual(data, b'')


@moto.mock_s3
@mock_s3
class MultipartWriterTest(unittest.TestCase):
"""
Test writing into s3 files.
Expand Down Expand Up @@ -566,7 +570,7 @@ def test_writebuffer(self):
assert actual == contents


@moto.mock_s3
@mock_s3
class SinglepartWriterTest(unittest.TestCase):
"""
Test writing into s3 files using single part upload.
Expand Down Expand Up @@ -676,7 +680,7 @@ def test_writebuffer(self):
ARBITRARY_CLIENT_ERROR = botocore.client.ClientError(error_response={}, operation_name='bar')


@moto.mock_s3
@mock_s3
class IterBucketTest(unittest.TestCase):
def setUp(self):
ignore_resource_warnings()
Expand Down Expand Up @@ -766,7 +770,7 @@ def test_list_bucket_long(self):
self.assertEqual(sorted(keys), sorted(expected))


@moto.mock_s3
@mock_s3
@pytest.mark.skipif(
condition=not smart_open.concurrency._CONCURRENT_FUTURES,
reason='concurrent.futures unavailable',
Expand Down Expand Up @@ -797,7 +801,7 @@ def test(self):
self.assertEqual(sorted(keys), sorted(expected))


@moto.mock_s3
@mock_s3
@pytest.mark.skipif(
condition=not smart_open.concurrency._MULTIPROCESSING,
reason='multiprocessing unavailable',
Expand Down Expand Up @@ -828,7 +832,7 @@ def test(self):
self.assertEqual(sorted(keys), sorted(expected))


@moto.mock_s3
@mock_s3
class IterBucketSingleProcessTest(unittest.TestCase):
def setUp(self):
self.old_flag_multi = smart_open.concurrency._MULTIPROCESSING
Expand Down Expand Up @@ -858,7 +862,7 @@ def test(self):
# This has to be a separate test because we cannot run it against real S3
# (we don't want to expose our real S3 credentials).
#
@moto.mock_s3
@mock_s3
class IterBucketCredentialsTest(unittest.TestCase):
def test(self):
_resource('s3').create_bucket(Bucket=BUCKET_NAME).wait_until_exists()
Expand All @@ -875,7 +879,7 @@ def test(self):
self.assertEqual(len(result), num_keys)


@moto.mock_s3
@mock_s3
class DownloadKeyTest(unittest.TestCase):
def setUp(self):
ignore_resource_warnings()
Expand Down Expand Up @@ -920,7 +924,7 @@ def test_propagates_other_exception(self):
KEY_NAME, bucket_name=BUCKET_NAME)


@moto.mock_s3
@mock_s3
class OpenTest(unittest.TestCase):
def setUp(self):
ignore_resource_warnings()
Expand Down Expand Up @@ -962,7 +966,7 @@ def test_failure(self):
self.assertEqual(partial.call_count, 3)


@moto.mock_s3()
@mock_s3
def test_client_propagation_singlepart():
"""Does the client parameter make it from the caller to Boto3?"""
#
Expand All @@ -985,7 +989,7 @@ def test_client_propagation_singlepart():
assert id(writer._client.client) == id(client)


@moto.mock_s3()
@mock_s3
def test_client_propagation_multipart():
"""Does the resource parameter make it from the caller to Boto3?"""
session = boto3.Session()
Expand All @@ -1004,7 +1008,7 @@ def test_client_propagation_multipart():
assert id(writer._client.client) == id(client)


@moto.mock_s3()
@mock_s3
def test_resource_propagation_reader():
"""Does the resource parameter make it from the caller to Boto3?"""
session = boto3.Session()
Expand Down
9 changes: 6 additions & 3 deletions smart_open/tests/test_s3_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import time

import boto3
import moto

from smart_open import open
try:
from moto import mock_s3
except ImportError:
from moto import mock_aws as mock_s3

from smart_open import open

BUCKET_NAME = 'test-smartopen'
KEY_NAME = 'test-key'
Expand All @@ -32,7 +35,7 @@ def get_versions(bucket, key):
]


@moto.mock_s3
@mock_s3
class TestVersionId(unittest.TestCase):
def setUp(self):
#
Expand Down
Loading

0 comments on commit 7aeff9d

Please sign in to comment.