Skip to content

Commit

Permalink
fix mocks for older python versions
Browse files Browse the repository at this point in the history
The .name property handling is different for older versions of mock.
It's far easier to just pass in a real file object instead of mocking
it.
  • Loading branch information
mpenkov committed May 25, 2021
1 parent 930c897 commit 33d9ee7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions smart_open/tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class SmartOpenHttpTest(unittest.TestCase):
Test reading from HTTP connections in various ways.
"""
@mock.patch('smart_open.ssh.open')
@mock.patch('smart_open.ssh.open', return_value=open(__file__))
def test_read_ssh(self, mock_open):
"""Is SSH line iterator called correctly?"""
obj = smart_open.open(
Expand Down Expand Up @@ -1686,7 +1686,7 @@ def test_gzip_write_mode(self):
s3 = boto3.resource('s3')
s3.create_bucket(Bucket='bucket')

with mock.patch('smart_open.s3.open') as mock_open:
with mock.patch('smart_open.s3.open', return_value=open(__file__, 'rb')) as mock_open:
smart_open.open("s3://bucket/key.gz", "wb")
mock_open.assert_called_with('bucket', 'key.gz', 'wb')

Expand All @@ -1702,7 +1702,7 @@ def test_gzip_read_mode(self):
with smart_open.open(key, "wb") as fout:
fout.write(text.encode("utf-8"))

with mock.patch('smart_open.s3.open') as mock_open:
with mock.patch('smart_open.s3.open', return_value=open(__file__)) as mock_open:
smart_open.open(key, "r")
mock_open.assert_called_with('bucket', 'key.gz', 'rb')

Expand Down

0 comments on commit 33d9ee7

Please sign in to comment.