mocking out cursor

This commit is contained in:
Stuart Lynn 2016-06-22 20:21:52 +00:00
parent 1d7f62fa85
commit 89c47dcef6

View File

@ -1,5 +1,16 @@
import re import re
class MockCursor:
def __init__(self, data):
self.cursor_pos =0
self.data = data
def fetch(self, batch_size):
batch = self.data[self.cursor_pos : self.cursor_pos + batch_size]
self.cursor_pos += batch_size
return batch
class MockPlPy: class MockPlPy:
def __init__(self): def __init__(self):
self._reset() self._reset()
@ -27,6 +38,10 @@ class MockPlPy:
def info(self, msg): def info(self, msg):
self.infos.append(msg) self.infos.append(msg)
def cursor(self,query):
data = self.execute(query)
return MockCursor(data)
def execute(self, query): # TODO: additional arguments def execute(self, query): # TODO: additional arguments
for result in self.results: for result in self.results:
if result[0].match(query): if result[0].match(query):