Skip to content

Commit eb14ba0

Browse files
tests/test_httpaccessor.py: Split assert_http_get_request_data()
Split `assert_http_get_request_data()` using contextlib.contextmanager Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent 8cbe626 commit eb14ba0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/test_httpaccessor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import sys
55
import unittest
6+
from contextlib import contextmanager
67

78
import pytest
89

@@ -55,14 +56,19 @@ def handle_get(request):
5556

5657
cls.httpserver.expect_request("/" + read_file).respond_with_handler(handle_get)
5758

58-
def assert_http_get_request_data(self, url, read_file, error_handler):
59+
@contextmanager
60+
def http_get_request_data(self, url, read_file, error_handler):
5961
"""Serve a GET request, assert that the accessor returns the content of the GET Request"""
6062
self.serve_a_get_request(self.document_root, read_file, error_handler)
6163

6264
httpaccessor = createAccessor(url, True)
6365
self.assertEqual(type(httpaccessor), HTTPAccessor)
6466

6567
with open(self.document_root + read_file, "rb") as ref:
68+
yield httpaccessor, ref
69+
70+
def assert_http_get_request_data(self, url, read_file, error_handler):
71+
with self.http_get_request_data(url, read_file, error_handler) as (httpaccessor, ref):
6672
http_accessor_filehandle = httpaccessor.openAddress(read_file)
6773
if sys.version_info >= (3, 0):
6874
assert isinstance(http_accessor_filehandle, HTTPResponse)

0 commit comments

Comments
 (0)