Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6342)

Unified Diff: chrome/common/extensions/docs/server2/future_test.py

Issue 438403002: Conver APIListDataSource to use Future.Then() rather than Get(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/server2/future.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/server2/future_test.py
diff --git a/chrome/common/extensions/docs/server2/future_test.py b/chrome/common/extensions/docs/server2/future_test.py
index 1c188d1ccdf6f25e2dd4cfceb0cb7b749de1a743..db056c58d54e5c48a8729b2ceacfefbecb1026b0 100755
--- a/chrome/common/extensions/docs/server2/future_test.py
+++ b/chrome/common/extensions/docs/server2/future_test.py
@@ -161,11 +161,12 @@ class FutureTest(unittest.TestCase):
def testThen(self):
def assertIs42(val):
- self.assertEquals(val, 42)
+ self.assertEqual(val, 42)
+ return val
then = Future(value=42).Then(assertIs42)
# Shouldn't raise an error.
- then.Get()
+ self.assertEqual(42, then.Get())
# Test raising an error.
then = Future(value=41).Then(assertIs42)
@@ -184,7 +185,7 @@ class FutureTest(unittest.TestCase):
raise Exception
then = Future(callback=raiseValueError).Then(assertIs42, handle)
- self.assertEquals(then.Get(), 'Caught')
+ self.assertEqual('Caught', then.Get())
then = Future(callback=raiseException).Then(assertIs42, handle)
self.assertRaises(Exception, then.Get)
@@ -192,7 +193,7 @@ class FutureTest(unittest.TestCase):
addOne = lambda val: val + 1
then = Future(value=40).Then(addOne).Then(addOne).Then(assertIs42)
# Shouldn't raise an error.
- then.Get()
+ self.assertEqual(42, then.Get())
# Test error in chain.
then = Future(value=40).Then(addOne).Then(assertIs42).Then(addOne)
@@ -216,6 +217,46 @@ class FutureTest(unittest.TestCase):
myHandle)
self.assertEquals(then.Get(), 10)
+ def testThenResolvesReturnedFutures(self):
+ def returnsFortyTwo():
+ return Future(value=42)
+ def inc(x):
+ return x + 1
+ def incFuture(x):
+ return Future(value=x + 1)
+
+ self.assertEqual(43, returnsFortyTwo().Then(inc).Get())
+ self.assertEqual(43, returnsFortyTwo().Then(incFuture).Get())
+ self.assertEqual(44, returnsFortyTwo().Then(inc).Then(inc).Get())
+ self.assertEqual(44, returnsFortyTwo().Then(inc).Then(incFuture).Get())
+ self.assertEqual(44, returnsFortyTwo().Then(incFuture).Then(inc).Get())
+ self.assertEqual(
+ 44, returnsFortyTwo().Then(incFuture).Then(incFuture).Get())
+
+ # The same behaviour should apply to error handlers.
+ def raisesSomething():
+ def boom(): raise ValueError
+ return Future(callback=boom)
+ def shouldNotHappen(_):
+ raise AssertionError()
+ def oops(error):
+ return 'oops'
+ def oopsFuture(error):
+ return Future(value='oops')
+
+ self.assertEqual(
+ 'oops', raisesSomething().Then(shouldNotHappen, oops).Get())
+ self.assertEqual(
+ 'oops', raisesSomething().Then(shouldNotHappen, oopsFuture).Get())
+ self.assertEqual(
+ 'oops',
+ raisesSomething().Then(shouldNotHappen, raisesSomething)
+ .Then(shouldNotHappen, oops).Get())
+ self.assertEqual(
+ 'oops',
+ raisesSomething().Then(shouldNotHappen, raisesSomething)
+ .Then(shouldNotHappen, oopsFuture).Get())
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « chrome/common/extensions/docs/server2/future.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698