From 97626140d4b76c19cfdecac32ca1ea456fe4b339 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 16 Aug 2018 22:11:41 +0900 Subject: [PATCH] fix test_request on python 3 (#11746) --- .../wptserve/tests/functional/test_request.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/wptserve/tests/functional/test_request.py b/tools/wptserve/tests/functional/test_request.py index de29638f6c11da..97d75eb71289ad 100644 --- a/tools/wptserve/tests/functional/test_request.py +++ b/tools/wptserve/tests/functional/test_request.py @@ -64,25 +64,23 @@ def handler(request, response): finally: InputFile.max_buffer_size = old_max_buf - @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2") def test_iter(self): @wptserve.handlers.handler def handler(request, response): f = request.raw_input - return " ".join(line for line in f) + return b" ".join(line for line in f) route = ("POST", "/test/test_iter", handler) self.server.router.register(*route) - resp = self.request(route[1], method="POST", body="12345\nabcdef\r\nzyxwv") + resp = self.request(route[1], method="POST", body=b"12345\nabcdef\r\nzyxwv") self.assertEqual(200, resp.getcode()) - self.assertEqual(["12345\n", "abcdef\r\n", "zyxwv"], resp.read().split(" ")) + self.assertEqual([b"12345\n", b"abcdef\r\n", b"zyxwv"], resp.read().split(b" ")) - @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2") def test_iter_input_longer_than_buffer(self): @wptserve.handlers.handler def handler(request, response): f = request.raw_input - return " ".join(line for line in f) + return b" ".join(line for line in f) route = ("POST", "/test/test_iter", handler) self.server.router.register(*route) @@ -90,15 +88,14 @@ def handler(request, response): old_max_buf = InputFile.max_buffer_size InputFile.max_buffer_size = 10 try: - resp = self.request(route[1], method="POST", body="12345\nabcdef\r\nzyxwv") + resp = self.request(route[1], method="POST", body=b"12345\nabcdef\r\nzyxwv") self.assertEqual(200, resp.getcode()) - self.assertEqual(["12345\n", "abcdef\r\n", "zyxwv"], resp.read().split(" ")) + self.assertEqual([b"12345\n", b"abcdef\r\n", b"zyxwv"], resp.read().split(b" ")) finally: InputFile.max_buffer_size = old_max_buf class TestRequest(TestUsingServer): - @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2") def test_body(self): @wptserve.handlers.handler def handler(request, response): @@ -107,10 +104,9 @@ def handler(request, response): route = ("POST", "/test/test_body", handler) self.server.router.register(*route) - resp = self.request(route[1], method="POST", body="12345ab\ncdef") - self.assertEqual("12345ab\ncdef", resp.read()) + resp = self.request(route[1], method="POST", body=b"12345ab\ncdef") + self.assertEqual(b"12345ab\ncdef", resp.read()) - @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2") def test_route_match(self): @wptserve.handlers.handler def handler(request, response): @@ -119,7 +115,7 @@ def handler(request, response): route = ("GET", "/test/{match}_*", handler) self.server.router.register(*route) resp = self.request("/test/some_route") - self.assertEqual("some route", resp.read()) + self.assertEqual(b"some route", resp.read()) class TestAuth(TestUsingServer):