Skip to content

Commit 927cf22

Browse files
authored
Improve error message on replay data mismatch (#3386)
Follow-up on #3385.
1 parent 0b4503c commit 927cf22

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/Connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def testRecordAndReplay(replaying_connection_class, protocol, response_body, exp
9191
connection.getresponse.return_value = response
9292

9393
# write mock response to buffer
94-
RecordingMockConnection.setOpenFile(lambda slf, mode: file)
94+
rdf = Framework.ReplayDataFile("string", file)
95+
RecordingMockConnection.setOpenFile(lambda slf, mode: rdf)
9596
recording_connection = RecordingMockConnection(protocol, host, None, lambda *args, **kwds: connection)
9697
recording_connection.request(verb, url, None, headers)
9798
recording_connection.getresponse()

tests/Framework.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
import base64
6363
import contextlib
64-
import io
6564
import json
6665
import os
6766
import traceback
@@ -140,7 +139,7 @@ def setOpenFile(func):
140139
def __init__(self, protocol, host, port, *args, **kwds):
141140
self.__file = self.__openFile("w")
142141
# write operations make the assumption that the file is not in binary mode
143-
assert isinstance(self.__file, io.TextIOBase)
142+
assert isinstance(self.__file, ReplayDataFile)
144143
self.__protocol = protocol
145144
self.__host = host
146145
self.__port = port
@@ -353,6 +352,9 @@ def __init__(self, filename: str, file):
353352
def __repr__(self) -> str:
354353
return f"{self.__filename}:{self.__line}"
355354

355+
def write(self, string: str):
356+
self.__file.write(string)
357+
356358
def readline(self) -> str:
357359
self.__line += 1
358360
line = self.__file.readline()

0 commit comments

Comments
 (0)