-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PythonParser is now resumable if _stream IO is interrupted * Add test for parse resumability * Clear PythonParser state when connection or parsing errors occur. * disable test for cluster mode. * Perform "closed" check in a single place. * Update tests * Simplify code. * Remove reduntant test, EOF is detected inside _readline() * Make syncronous PythonParser restartable on error, same as HiredisParser Fix sync PythonParser * Add CHANGES * isort * Move MockStream and MockSocket into their own files
- Loading branch information
1 parent
a947728
commit a9ef0c5
Showing
7 changed files
with
269 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Various mocks for testing | ||
|
||
|
||
class MockSocket: | ||
""" | ||
A class simulating an readable socket, optionally raising a | ||
special exception every other read. | ||
""" | ||
|
||
class TestError(BaseException): | ||
pass | ||
|
||
def __init__(self, data, interrupt_every=0): | ||
self.data = data | ||
self.counter = 0 | ||
self.pos = 0 | ||
self.interrupt_every = interrupt_every | ||
|
||
def tick(self): | ||
self.counter += 1 | ||
if not self.interrupt_every: | ||
return | ||
if (self.counter % self.interrupt_every) == 0: | ||
raise self.TestError() | ||
|
||
def recv(self, bufsize): | ||
self.tick() | ||
bufsize = min(5, bufsize) # truncate the read size | ||
result = self.data[self.pos : self.pos + bufsize] | ||
self.pos += len(result) | ||
return result | ||
|
||
def recv_into(self, buffer, nbytes=0, flags=0): | ||
self.tick() | ||
if nbytes == 0: | ||
nbytes = len(buffer) | ||
nbytes = min(5, nbytes) # truncate the read size | ||
result = self.data[self.pos : self.pos + nbytes] | ||
self.pos += len(result) | ||
buffer[: len(result)] = result | ||
return len(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import asyncio | ||
|
||
# Helper Mocking classes for the tests. | ||
|
||
|
||
class MockStream: | ||
""" | ||
A class simulating an asyncio input buffer, optionally raising a | ||
special exception every other read. | ||
""" | ||
|
||
class TestError(BaseException): | ||
pass | ||
|
||
def __init__(self, data, interrupt_every=0): | ||
self.data = data | ||
self.counter = 0 | ||
self.pos = 0 | ||
self.interrupt_every = interrupt_every | ||
|
||
def tick(self): | ||
self.counter += 1 | ||
if not self.interrupt_every: | ||
return | ||
if (self.counter % self.interrupt_every) == 0: | ||
raise self.TestError() | ||
|
||
async def read(self, want): | ||
self.tick() | ||
want = 5 | ||
result = self.data[self.pos : self.pos + want] | ||
self.pos += len(result) | ||
return result | ||
|
||
async def readline(self): | ||
self.tick() | ||
find = self.data.find(b"\n", self.pos) | ||
if find >= 0: | ||
result = self.data[self.pos : find + 1] | ||
else: | ||
result = self.data[self.pos :] | ||
self.pos += len(result) | ||
return result | ||
|
||
async def readexactly(self, length): | ||
self.tick() | ||
result = self.data[self.pos : self.pos + length] | ||
if len(result) < length: | ||
raise asyncio.IncompleteReadError(result, None) | ||
self.pos += len(result) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.