Skip to content

Commit

Permalink
test: Improve test coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Sep 8, 2024
1 parent b881652 commit 0f437a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def __init__(self):
self._complete = False

def _append(self, data):
if self._size < 0:
if self._size < 0: # pragma: no cover
raise RuntimeError("Invalid state")
self._size += len(data)
self._buffer += data
Expand Down
22 changes: 22 additions & 0 deletions test/test_push_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,25 @@ def test_header_bad_name(self):
self.reset()
with self.assertMPE("Malformed header: Empty name"):
self.parse(b"--boundary\r\n:just-value\r\n\r\ndata\r\n--boundary--")

def test_partial_parts(self):
self.reset()
self.assertEqual([], self.parse(b'--boundary\r\n'))
self.assertEqual([], self.parse(b'Header: value\r\n'))
self.assertEqual([], self.parse(b'\r\n'))
# Write enough body data to trigger a new part
part = self.parse(b'body'*10)[0]
self.assertTrue(part.incomplete)
self.assertFalse(part.complete)
self.assertTrue(part.buffersize > 0)
self.assertEqual(part.size, part.buffersize)
part.drain()
self.assertEqual(0, part.buffersize)
# Write partial boundary, should stay incomplete
self.assertEqual([part], self.parse(b'\r\n--boundary'))
self.assertTrue(part.incomplete)
self.assertTrue(part.buffersize > 0)
# Turn the incomplete boundary into a terminator
self.assertEqual([part], self.parse(b'--'))
self.assertTrue(part.complete)
self.assertEqual(40, part.size)

0 comments on commit 0f437a6

Please sign in to comment.