From 89c47dcef6fcf4a8f3f56c6419632add85895995 Mon Sep 17 00:00:00 2001 From: Stuart Lynn Date: Wed, 22 Jun 2016 20:21:52 +0000 Subject: [PATCH] mocking out cursor --- src/py/crankshaft/test/mock_plpy.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/py/crankshaft/test/mock_plpy.py b/src/py/crankshaft/test/mock_plpy.py index 63c88f6..c849ec4 100644 --- a/src/py/crankshaft/test/mock_plpy.py +++ b/src/py/crankshaft/test/mock_plpy.py @@ -1,5 +1,16 @@ 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: def __init__(self): self._reset() @@ -27,6 +38,10 @@ class MockPlPy: def info(self, msg): self.infos.append(msg) + def cursor(self,query): + data = self.execute(query) + return MockCursor(data) + def execute(self, query): # TODO: additional arguments for result in self.results: if result[0].match(query):