Skip to content

Commit

Permalink
Specify utf-8 encoding explicitly in tests
Browse files Browse the repository at this point in the history
If we don't specify it, smart_open will use the system encoding.  This
may be ascii on some systems (e.g. Py2.7), which will fail the test
because it contains non-ascii characters.
  • Loading branch information
mpenkov committed Dec 4, 2017
1 parent a3f9fe1 commit 2188b2b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions smart_open/tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,12 +977,15 @@ def test_r(self):
text = u"физкульт-привет!"
key.set_contents_from_string(text.encode("utf-8"))

with smart_open.s3_open_key(key, "r") as fin:
self.assertEqual(fin.read(), u"физкульт-привет!")
with smart_open.s3_open_key(key, "rb") as fin:
self.assertEqual(fin.read(), text.encode('utf-8'))

with smart_open.s3_open_key(key, "r", encoding='utf-8') as fin:
self.assertEqual(fin.read(), text)

parsed_uri = smart_open.ParseUri("s3://bucket/key")
with smart_open.s3_open_uri(parsed_uri, "r") as fin:
self.assertEqual(fin.read(), u"физкульт-привет!")
with smart_open.s3_open_uri(parsed_uri, "r", encoding='utf-8') as fin:
self.assertEqual(fin.read(), text)

def test_bad_mode(self):
"""Bad mode should raise and exception."""
Expand Down

0 comments on commit 2188b2b

Please sign in to comment.