Merge pull request #5782 from linchiwei123/patch-1

Fix TypeError
This commit is contained in:
Bruno Oliveira 2019-08-24 15:40:49 -03:00 committed by GitHub
commit 9859d37cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix decoding error when printing an error response from ``--pastebin``.

View File

@ -72,7 +72,7 @@ def create_new_paste(contents):
if m:
return "{}/show/{}".format(url, m.group(1))
else:
return "bad response: " + response
return "bad response: " + response.decode("utf-8")
def pytest_terminal_summary(terminalreporter):

View File

@ -116,3 +116,15 @@ class TestPaste:
assert "lexer=%s" % lexer in data.decode()
assert "code=full-paste-contents" in data.decode()
assert "expiry=1week" in data.decode()
def test_create_new_paste_failure(self, pastebin, monkeypatch):
import io
import urllib.request
def response(url, data):
stream = io.BytesIO(b"something bad occurred")
return stream
monkeypatch.setattr(urllib.request, "urlopen", response)
result = pastebin.create_new_paste(b"full-paste-contents")
assert result == "bad response: something bad occurred"