-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
Fix warnings #140
Merged
Merged
Fix warnings #140
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,16 +122,17 @@ def test_http_pass(self): | |
"""Does http authentication work correctly""" | ||
responses.add(responses.GET, "http://127.0.0.1/index.html", body='line1\nline2') | ||
_ = smart_open.HttpOpenRead(smart_open.ParseUri("http://127.0.0.1/index.html"), user='me', password='pass') | ||
self.assertEquals(len(responses.calls), 1) | ||
self.assertEqual(len(responses.calls), 1) | ||
actual_request = responses.calls[0].request | ||
self.assert_('Authorization' in actual_request.headers) | ||
self.assert_(actual_request.headers['Authorization'].startswith('Basic ')) | ||
self.assertTrue('Authorization' in actual_request.headers) | ||
self.assertTrue(actual_request.headers['Authorization'].startswith('Basic ')) | ||
|
||
@responses.activate | ||
def test_http_gz(self): | ||
"""Can open gzip via http?""" | ||
fpath = os.path.join(CURR_DIR, 'test_data/crlf_at_1k_boundary.warc.gz') | ||
data = open(fpath, 'rb').read() | ||
with open(fpath, 'rb') as file: | ||
data = file.read() | ||
|
||
responses.add(responses.GET, "http://127.0.0.1/data.gz", | ||
body=data) | ||
|
@@ -146,7 +147,8 @@ def test_http_gz(self): | |
def test_http_bz2(self): | ||
"""Can open bz2 via http?""" | ||
test_string = b'Hello World Compressed.' | ||
test_file = tempfile.NamedTemporaryFile('wb', suffix='.bz2', delete=False).name | ||
with tempfile.NamedTemporaryFile('wb', suffix='.bz2', delete=False) as file: | ||
test_file = file.name | ||
|
||
with smart_open.smart_open(test_file, 'wb') as outfile: | ||
outfile.write(test_string) | ||
|
@@ -182,9 +184,9 @@ def test_read_never_returns_none(self): | |
fout.write(test_string.encode('utf8')) | ||
|
||
r = smart_open.smart_open("s3://mybucket/mykey", "rb") | ||
self.assertEquals(r.read(), test_string.encode("utf-8")) | ||
self.assertEquals(r.read(), b"") | ||
self.assertEquals(r.read(), b"") | ||
self.assertEqual(r.read(), test_string.encode("utf-8")) | ||
self.assertEqual(r.read(), b"") | ||
self.assertEqual(r.read(), b"") | ||
|
||
@mock_s3 | ||
def test_readline(self): | ||
|
@@ -196,7 +198,7 @@ def test_readline(self): | |
fout.write(test_string) | ||
|
||
reader = smart_open.smart_open("s3://mybucket/mykey", "rb") | ||
self.assertEquals(reader.readline(), u"hello žluťoučký world!\n".encode("utf-8")) | ||
self.assertEqual(reader.readline(), u"hello žluťoučký world!\n".encode("utf-8")) | ||
|
||
@mock_s3 | ||
def test_readline_iter(self): | ||
|
@@ -210,9 +212,9 @@ def test_readline_iter(self): | |
reader = smart_open.smart_open("s3://mybucket/mykey", "rb") | ||
|
||
actual_lines = [l.decode("utf-8") for l in reader] | ||
self.assertEquals(2, len(actual_lines)) | ||
self.assertEquals(lines[0], actual_lines[0]) | ||
self.assertEquals(lines[1], actual_lines[1]) | ||
self.assertEqual(2, len(actual_lines)) | ||
self.assertEqual(lines[0], actual_lines[0]) | ||
self.assertEqual(lines[1], actual_lines[1]) | ||
|
||
@mock_s3 | ||
def test_readline_eof(self): | ||
|
@@ -224,9 +226,9 @@ def test_readline_eof(self): | |
|
||
reader = smart_open.smart_open("s3://mybucket/mykey", "rb") | ||
|
||
self.assertEquals(reader.readline(), b"") | ||
self.assertEquals(reader.readline(), b"") | ||
self.assertEquals(reader.readline(), b"") | ||
self.assertEqual(reader.readline(), b"") | ||
self.assertEqual(reader.readline(), b"") | ||
self.assertEqual(reader.readline(), b"") | ||
|
||
@mock_s3 | ||
def test_s3_iter_lines(self): | ||
|
@@ -785,20 +787,23 @@ def write_read_assertion(self, test_file): | |
def test_open_gz(self): | ||
"""Can open gzip?""" | ||
fpath = os.path.join(CURR_DIR, 'test_data/crlf_at_1k_boundary.warc.gz') | ||
data = smart_open.smart_open(fpath).read() | ||
with smart_open.smart_open(fpath) as file: | ||
data = file.read() | ||
m = hashlib.md5(data) | ||
assert m.hexdigest() == '18473e60f8c7c98d29d65bf805736a0d', \ | ||
'Failed to read gzip' | ||
|
||
def test_write_read_gz(self): | ||
"""Can write and read gzip?""" | ||
test_file = tempfile.NamedTemporaryFile('wb', suffix='.gz', delete=False).name | ||
self.write_read_assertion(test_file) | ||
with tempfile.NamedTemporaryFile('wb', suffix='.gz', delete=False) as file: | ||
test_file_name = file.name | ||
self.write_read_assertion(test_file_name) | ||
|
||
def test_write_read_bz2(self): | ||
"""Can write and read bz2?""" | ||
test_file = tempfile.NamedTemporaryFile('wb', suffix='.bz2', delete=False).name | ||
self.write_read_assertion(test_file) | ||
with tempfile.NamedTemporaryFile('wb', suffix='.bz2', delete=False) as file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nitpick - can you rename |
||
test_file_name = file.name | ||
self.write_read_assertion(test_file_name) | ||
|
||
|
||
class MultistreamsBZ2Test(unittest.TestCase): | ||
|
@@ -906,11 +911,11 @@ def test_r(self): | |
key.set_contents_from_string(text.encode("utf-8")) | ||
|
||
with smart_open.s3_open_key(key, "r") as fin: | ||
self.assertEquals(fin.read(), u"физкульт-привет!") | ||
self.assertEqual(fin.read(), u"физкульт-привет!") | ||
|
||
parsed_uri = smart_open.ParseUri("s3://bucket/key") | ||
with smart_open.s3_open_uri(parsed_uri, "r") as fin: | ||
self.assertEquals(fin.read(), u"физкульт-привет!") | ||
self.assertEqual(fin.read(), u"физкульт-привет!") | ||
|
||
def test_bad_mode(self): | ||
"""Bad mode should raise and exception.""" | ||
|
@@ -930,10 +935,10 @@ def test_rw_encoding(self): | |
fout.write(text) | ||
|
||
with smart_open.s3_open_uri(uri, "r", encoding="koi8-r") as fin: | ||
self.assertEquals(text, fin.read()) | ||
self.assertEqual(text, fin.read()) | ||
|
||
with smart_open.s3_open_uri(uri, "rb") as fin: | ||
self.assertEquals(text.encode("koi8-r"), fin.read()) | ||
self.assertEqual(text.encode("koi8-r"), fin.read()) | ||
|
||
with smart_open.s3_open_uri(uri, "r", encoding="euc-jp") as fin: | ||
self.assertRaises(UnicodeDecodeError, fin.read) | ||
|
@@ -958,13 +963,13 @@ def test_rw_gzip(self): | |
# | ||
with smart_open.s3_open_uri(uri, "rb", ignore_extension=True) as fin: | ||
gz = gzip.GzipFile(fileobj=fin) | ||
self.assertEquals(gz.read().decode("utf-8"), text) | ||
self.assertEqual(gz.read().decode("utf-8"), text) | ||
|
||
# | ||
# We should be able to read it back as well. | ||
# | ||
with smart_open.s3_open_uri(uri, "rb") as fin: | ||
self.assertEquals(fin.read().decode("utf-8"), text) | ||
self.assertEqual(fin.read().decode("utf-8"), text) | ||
|
||
@mock_s3 | ||
def test_gzip_write_mode(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks slightly strange
file_obj)(file_obj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried redo as just classes