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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import unittest
6
7 # pylint: disable=F0401
8 import mojo.embedder
9 from mojo import system
10
11
12 def _Increment(array):
13 def _Closure():
14 array.append(0)
15 return _Closure
16
17
18 class RunLoopTest(unittest.TestCase):
19
20 def setUp(self):
21 mojo.embedder.Init()
22
23 def testRunLoop(self):
24 loop = system.RunLoop()
25 array = []
26 for _ in xrange(10):
27 loop.PostDelayedTask(_Increment(array))
28 loop.RunUntilIdle()
29 self.assertEquals(len(array), 10)
30
31 def testRunLoopWithException(self):
32 loop = system.RunLoop()
33 def Throw():
34 raise Exception("error")
35 array = []
36 loop.PostDelayedTask(Throw)
37 loop.PostDelayedTask(_Increment(array))
38 with self.assertRaisesRegexp(Exception, '^error$'):
39 loop.Run()
40 self.assertEquals(len(array), 0)
41 loop.RunUntilIdle()
42 self.assertEquals(len(array), 1)
OLDNEW
« 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