IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 3216432e authored by Emi Simpson's avatar Emi Simpson
Browse files

Noop queries offer an indication of their value in .get_query()

parent e4e11215
Pipeline #854 passed with stage
in 58 seconds
......@@ -44,7 +44,7 @@ class Unfinished(Generic[T, E]):
class Noop(Generic[T]):
value: T
def get_query(self) -> QueryRequest:
return QueryRequest('', tuple())
return QueryRequest('',(self.value,))
def handle_results(self, results: QueryResult | SqlIntegrityError) -> Finished[T] | Error[NoReturn]:
assert results
return Finished(self.value)
......@@ -53,7 +53,7 @@ class Noop(Generic[T]):
class ENoop(Generic[T]):
value: T
def get_query(self) -> QueryRequest:
return QueryRequest('', tuple())
return QueryRequest('',(self.value,))
def handle_results(self, results: QueryResult | SqlIntegrityError) -> Finished[NoReturn] | Error[T]:
assert results
return Error(self.value)
......
......@@ -14,7 +14,7 @@ class TestQueries(unittest.TestCase):
def test_noop(self):
str_noop = Noop("hello")
self.assertEqual(str_noop.get_query(), ('', tuple()))
self.assertEqual(str_noop.get_query(), ('', ('hello',)))
self.assertEqual( # Well behaved called
str_noop.handle_results(QueryResult(0, 0, lambda: None, lambda: [])),
Finished("hello")
......@@ -26,7 +26,7 @@ class TestQueries(unittest.TestCase):
del str_noop
int_noop = Noop(1337)
self.assertEqual(int_noop.get_query(), ('', tuple()))
self.assertEqual(int_noop.get_query(), ('',(1337,)))
self.assertEqual(
int_noop.handle_results(QueryResult(1, 1, panic, panic)),
Finished(1337)
......@@ -34,7 +34,7 @@ class TestQueries(unittest.TestCase):
def test_enoop(self):
str_noop = ENoop("hello")
self.assertEqual(str_noop.get_query(), ('', tuple()))
self.assertEqual(str_noop.get_query(), ('',('hello',)))
self.assertEqual( # Well behaved called
str_noop.handle_results(QueryResult(0, 0, lambda: None, lambda: [])),
Error("hello")
......@@ -46,7 +46,7 @@ class TestQueries(unittest.TestCase):
del str_noop
int_noop = ENoop(1337)
self.assertEqual(int_noop.get_query(), ('', tuple()))
self.assertEqual(int_noop.get_query(), ('',(1337,)))
self.assertEqual(
int_noop.handle_results(QueryResult(1, 1, panic, panic)),
Error(1337)
......@@ -60,13 +60,13 @@ class TestQueries(unittest.TestCase):
)
self.assertEqual(
bound1.get_query(),
('', tuple())
('',('woop!',))
)
bound1result = bound1.handle_results(QueryResult(0, 0, panic, panic))
assert isinstance(bound1result, Unfinished)
next = bound1result.next_query
self.assertIsInstance(next, Noop)
self.assertEqual(next.get_query(), ('', tuple()))
self.assertEqual(next.get_query(), ('',(1337,)))
self.assertEqual(next.handle_results(null_result), Finished(1337))
del next, bound1, bound1result, result1
......@@ -77,7 +77,7 @@ class TestQueries(unittest.TestCase):
)
self.assertEqual(
bound2.get_query(),
('', tuple())
('',('schloop!',))
)
bound2result = bound2.handle_results(QueryResult(0, 0, panic, panic))
self.assertEqual(bound2result, Error(result2))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment