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

Unified Diff: mojo/python/tests/runloop_unittest.py

Issue 552783004: mojo: Add a runloop utility in python (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not acquire GIL when called from python. Created 6 years, 3 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 | « mojo/public/python/src/python_system_helper.cc ('k') | third_party/cython/rules.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/python/tests/runloop_unittest.py
diff --git a/mojo/python/tests/runloop_unittest.py b/mojo/python/tests/runloop_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..3549dbe5e1afbeb16c5abe01619f00d52e8d9903
--- /dev/null
+++ b/mojo/python/tests/runloop_unittest.py
@@ -0,0 +1,42 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+# pylint: disable=F0401
+import mojo.embedder
+from mojo import system
+
+
+def _Increment(array):
+ def _Closure():
+ array.append(0)
+ return _Closure
+
+
+class RunLoopTest(unittest.TestCase):
+
+ def setUp(self):
+ mojo.embedder.Init()
+
+ def testRunLoop(self):
+ loop = system.RunLoop()
+ array = []
+ for _ in xrange(10):
+ loop.PostDelayedTask(_Increment(array))
+ loop.RunUntilIdle()
+ self.assertEquals(len(array), 10)
+
+ def testRunLoopWithException(self):
+ loop = system.RunLoop()
+ def Throw():
+ raise Exception("error")
+ array = []
+ loop.PostDelayedTask(Throw)
+ loop.PostDelayedTask(_Increment(array))
+ with self.assertRaisesRegexp(Exception, '^error$'):
+ loop.Run()
+ self.assertEquals(len(array), 0)
+ loop.RunUntilIdle()
+ self.assertEquals(len(array), 1)
« no previous file with comments | « mojo/public/python/src/python_system_helper.cc ('k') | third_party/cython/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698