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

Side by Side Diff: mojo/python/tests/runloop_unittest.py

Issue 644773002: mojo: Add RunLoop::Current() and refactor unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 2 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/python/tests/mojo_unittest.py ('k') | mojo/python/tests/system_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import mojo_unittest
6 6
7 # pylint: disable=F0401 7 # pylint: disable=F0401
8 import mojo.embedder
9 from mojo import system 8 from mojo import system
10 9
11 10
12 def _Increment(array): 11 def _Increment(array):
13 def _Closure(): 12 def _Closure():
14 array.append(0) 13 array.append(0)
15 return _Closure 14 return _Closure
16 15
17 16
18 class RunLoopTest(unittest.TestCase): 17 class RunLoopTest(mojo_unittest.MojoTestCase):
19
20 def setUp(self):
21 mojo.embedder.Init()
22 18
23 def testRunLoop(self): 19 def testRunLoop(self):
24 loop = system.RunLoop()
25 array = [] 20 array = []
26 for _ in xrange(10): 21 for _ in xrange(10):
27 loop.PostDelayedTask(_Increment(array)) 22 self.loop.PostDelayedTask(_Increment(array))
28 loop.RunUntilIdle() 23 self.loop.RunUntilIdle()
29 self.assertEquals(len(array), 10) 24 self.assertEquals(len(array), 10)
30 25
31 def testRunLoopWithException(self): 26 def testRunLoopWithException(self):
32 loop = system.RunLoop()
33 def Throw(): 27 def Throw():
34 raise Exception("error") 28 raise Exception("error")
35 array = [] 29 array = []
36 loop.PostDelayedTask(Throw) 30 self.loop.PostDelayedTask(Throw)
37 loop.PostDelayedTask(_Increment(array)) 31 self.loop.PostDelayedTask(_Increment(array))
38 with self.assertRaisesRegexp(Exception, '^error$'): 32 with self.assertRaisesRegexp(Exception, '^error$'):
39 loop.Run() 33 self.loop.Run()
40 self.assertEquals(len(array), 0) 34 self.assertEquals(len(array), 0)
41 loop.RunUntilIdle() 35 self.loop.RunUntilIdle()
42 self.assertEquals(len(array), 1) 36 self.assertEquals(len(array), 1)
37
38 def testCurrent(self):
39 self.assertEquals(system.RunLoop.Current(), self.loop)
40 self.loop = None
41 self.assertIsNone(system.RunLoop.Current())
OLDNEW
« no previous file with comments | « mojo/python/tests/mojo_unittest.py ('k') | mojo/python/tests/system_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698