From 44f60ba141204073983e99b56cfb8ce061bc01cc Mon Sep 17 00:00:00 2001 From: mehdy Date: Sun, 29 Nov 2015 18:27:05 +0330 Subject: [PATCH 1/5] fixed #1198 issue by encoding the unicode parameters to bytes and decoding the bytes response to unicode --- _pytest/pastebin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py index f5e479158..0b662c62b 100644 --- a/_pytest/pastebin.py +++ b/_pytest/pastebin.py @@ -61,7 +61,7 @@ def create_new_paste(contents): 'expiry': '1week', } url = 'https://bpaste.net' - response = urlopen(url, data=urlencode(params)).read() + response = urlopen(url, data=urlencode(params).encode()).read().decode() m = re.search(r'href="/raw/(\w+)"', response) if m: return '%s/show/%s' % (url, m.group(1)) From 81ad1689b9961973c66d8454c03fe283b1973725 Mon Sep 17 00:00:00 2001 From: mehdy Date: Sun, 29 Nov 2015 19:20:37 +0330 Subject: [PATCH 2/5] fix #1198 - removed docoding the result --- _pytest/pastebin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py index 0b662c62b..02af6987a 100644 --- a/_pytest/pastebin.py +++ b/_pytest/pastebin.py @@ -61,7 +61,7 @@ def create_new_paste(contents): 'expiry': '1week', } url = 'https://bpaste.net' - response = urlopen(url, data=urlencode(params).encode()).read().decode() + response = urlopen(url, data=urlencode(params).encode()).read() m = re.search(r'href="/raw/(\w+)"', response) if m: return '%s/show/%s' % (url, m.group(1)) From f9b1e39b8a51f6f0b65c10ed05cf4311c6aeafca Mon Sep 17 00:00:00 2001 From: mehdy Date: Sun, 29 Nov 2015 19:42:50 +0330 Subject: [PATCH 3/5] fix #1198 - decoding monkeypatched data to unicode --- testing/test_pastebin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py index 1b5fb1dca..70485fbba 100644 --- a/testing/test_pastebin.py +++ b/testing/test_pastebin.py @@ -80,8 +80,8 @@ class TestPaste: url, data = mocked_urlopen[0] lexer = 'python3' if sys.version_info[0] == 3 else 'python' assert url == 'https://bpaste.net' - assert 'lexer=%s' % lexer in data - assert 'code=full-paste-contents' in data - assert 'expiry=1week' in data + assert 'lexer=%s' % lexer in data.decode() + assert 'code=full-paste-contents' in data.decode() + assert 'expiry=1week' in data.decode() From 6a2ebddc7c2fb6176d2b442c21239402da7b92ce Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 1 Dec 2015 23:30:05 -0200 Subject: [PATCH 4/5] Decode urlopen response in pastebin Fix #1198 --- _pytest/pastebin.py | 2 +- testing/test_pastebin.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/_pytest/pastebin.py b/_pytest/pastebin.py index 02af6987a..20738134e 100644 --- a/_pytest/pastebin.py +++ b/_pytest/pastebin.py @@ -62,7 +62,7 @@ def create_new_paste(contents): } url = 'https://bpaste.net' response = urlopen(url, data=urlencode(params).encode()).read() - m = re.search(r'href="/raw/(\w+)"', response) + m = re.search(r'href="/raw/(\w+)"', response.decode()) if m: return '%s/show/%s' % (url, m.group(1)) else: diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py index 70485fbba..2fe4bc137 100644 --- a/testing/test_pastebin.py +++ b/testing/test_pastebin.py @@ -1,7 +1,7 @@ import sys import pytest -class TestPasting: +class TestPasteCapture: @pytest.fixture def pastebinlist(self, monkeypatch, request): @@ -62,7 +62,7 @@ class TestPaste: class DummyFile: def read(self): # part of html of a normal response - return 'View raw.' + return b'View raw.' return DummyFile() if sys.version_info < (3, 0): @@ -78,6 +78,7 @@ class TestPaste: assert result == 'https://bpaste.net/show/3c0c6750bd' assert len(mocked_urlopen) == 1 url, data = mocked_urlopen[0] + assert type(data) is bytes lexer = 'python3' if sys.version_info[0] == 3 else 'python' assert url == 'https://bpaste.net' assert 'lexer=%s' % lexer in data.decode() From edfb567091584c7de87e1fa6070f481872e27016 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 1 Dec 2015 23:37:16 -0200 Subject: [PATCH 5/5] Add #1198 fix to CHANGELOG --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index ae766aa0d..288d9a6c6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ module. Thanks Mikhail Chernykh for the report and Bruno Oliveira for the PR. +- fix #1198: ``--pastebin`` option now works on Python 3. Thanks + Mehdy Khoshnoody for the PR. + 2.8.3 -----