mirror of
https://github.com/CartoDB/crankshaft.git
synced 2024-11-01 10:20:48 +08:00
mocking out cursor
This commit is contained in:
parent
1d7f62fa85
commit
89c47dcef6
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user