Skip to content

Commit 8522b4c

Browse files
committed
Correct types passed to content_from_stream
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent aa4727c commit 8522b4c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tests/test_testresult.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,11 +2108,13 @@ def setUp(self):
21082108
self.result = TextTestResult(io.StringIO())
21092109

21102110
def getvalue(self):
2111+
assert isinstance(self.result.stream, io.StringIO)
21112112
return self.result.stream.getvalue()
21122113

21132114
def test__init_sets_stream(self):
2114-
result = TextTestResult("fp")
2115-
self.assertEqual("fp", result.stream)
2115+
stream = io.StringIO()
2116+
result = TextTestResult(stream)
2117+
self.assertEqual(stream, result.stream)
21162118

21172119
def reset_output(self):
21182120
self.result.stream = io.StringIO()
@@ -2285,6 +2287,7 @@ def __init__(self, stream):
22852287

22862288
def addSuccess(self, test, details=None):
22872289
super().addSuccess(test, details)
2290+
assert self.stream is not None
22882291
self.stream.write("CUSTOM_SUCCESS_MARKER\n")
22892292

22902293
stream = io.StringIO()
@@ -3562,7 +3565,7 @@ def test_no_details(self):
35623565

35633566
def test_binary_content(self):
35643567
content = content_from_stream(
3565-
io.StringIO("foo"), content_type=ContentType("image", "jpeg")
3568+
io.BytesIO(b"foo"), content_type=ContentType("image", "jpeg")
35663569
)
35673570
string = _details_to_str({"attachment": content})
35683571
self.assertThat(
@@ -3617,16 +3620,16 @@ def test_empty_attachment(self):
36173620
)
36183621

36193622
def test_lots_of_different_attachments(self):
3620-
def jpg(x):
3621-
return content_from_stream(io.StringIO(x), ContentType("image", "jpeg"))
3623+
def jpg(x: bytes) -> Content:
3624+
return content_from_stream(io.BytesIO(x), ContentType("image", "jpeg"))
36223625

36233626
attachments = {
36243627
"attachment": text_content("foo"),
36253628
"attachment-1": text_content("traceback"),
3626-
"attachment-2": jpg("pic1"),
3629+
"attachment-2": jpg(b"pic1"),
36273630
"attachment-3": text_content("bar"),
36283631
"attachment-4": text_content(""),
3629-
"attachment-5": jpg("pic2"),
3632+
"attachment-5": jpg(b"pic2"),
36303633
}
36313634
string = _details_to_str(attachments, special="attachment-1")
36323635
self.assertThat(

0 commit comments

Comments
 (0)