Skip to content
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

Using moto 1.1.25 with smart_open raises ValueError: file descriptor cannot be a negative integer (-1) #160

Closed
matt-pazien opened this issue Dec 18, 2017 · 4 comments
Assignees

Comments

@matt-pazien
Copy link

Smart open uses an older version of moto to test - using a later release causes test issues.

Creating a simple unit test case using smart_open
smart-open==1.5.5
moto==1.1.25

from unittest import TestCase

import boto
import smart_open
from moto import mock_s3_deprecated


class TestSimpleSmartOpen(TestCase):
    @mock_s3_deprecated
    def test_write_encoding(self):
        conn = boto.connect_s3()
        conn.create_bucket('bucket')
        key = "s3://bucket/key.txt"
        text = u'Hello there'

        with smart_open.smart_open(key, 'w', encoding='utf-8') as fout:
            fout.write(text)
        with smart_open.smart_open(key, encoding='utf-8') as fin:
            actual = fin.read()
        self.assertEqual(text, actual)

This raises an error

ValueError: file descriptor cannot be a negative integer (-1)
@menshikh-iv
Copy link
Contributor

menshikh-iv commented Dec 21, 2017

@matt-pazien I tried to reproduce, works fine for py27, reproduced only in py36
P/S typically, we used moto==0.4.31 for tests

smart-open==1.5.5
moto==1.1.25
import unittest

import boto
import smart_open
from moto import mock_s3_deprecated


class TestSimpleSmartOpen(unittest.TestCase):
    @mock_s3_deprecated
    def test_write_encoding(self):
        conn = boto.connect_s3()
        conn.create_bucket('bucket')
        key = "s3://bucket/key.txt"
        text = u'Hello there'

        with smart_open.smart_open(key, 'w', encoding='utf-8') as fout:
            fout.write(text)
        with smart_open.smart_open(key, encoding='utf-8') as fin:
            actual = fin.read()
        self.assertEqual(text, actual)

if __name__ == '__main__':
    unittest.main()

@mpenkov wdyt about this problem?

@mpenkov
Copy link
Collaborator

mpenkov commented Dec 22, 2017

We pin the moto version for a reason: newer versions of moto treat boto and boto3 mocks differently. Our tests are older and use boto to mock the data, but our newer implementation uses boto3 to read the mocked data. Therefore, we expect our tests not to work under newer versions of moto.

In order for them to work, we'd have to move to boto3 entirely and rewrite our tests. That is issue #43. I recommend we close the current issue as a duplicate, and add update moto to the scope of #43.

@matt-pazien
Copy link
Author

@mpenkov I understand - but it's harder to integrate smart_open into other projects if we want to test it ourselves with moto.

@mpenkov
Copy link
Collaborator

mpenkov commented Dec 22, 2017

@matt-pazien I understand. We will work on this issue as part of #43. Unfortunately, dealing with this change of behavior between old & new moto versions will require some effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants