From 702b867bb33edb575492aac8ba3e8785901dfeb9 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 6 Aug 2009 09:58:57 -0700 Subject: [PATCH] Merged test__api into api_test --- tests/api_test.py | 33 +++++++++++++++++++++++++ tests/test__api.py | 60 ---------------------------------------------- 2 files changed, 33 insertions(+), 60 deletions(-) delete mode 100644 tests/test__api.py diff --git a/tests/api_test.py b/tests/api_test.py index 2472199..d97e76c 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -220,6 +220,39 @@ class TestApi(TestCase): result = evt.wait() self.assertEquals(result, 'sent via event') + + + def test_killing_dormant(self): + DELAY = 0.1 + state = [] + def test(): + try: + state.append('start') + api.sleep(DELAY) + except: + state.append('except') + # catching GreenletExit + pass + # when switching to hub, hub makes itself the parent of this greenlet, + # thus after the function's done, the control will go to the parent + # QQQ why the first sleep is not enough? + api.sleep(0) + state.append('finished') + g = api.spawn(test) + api.sleep(DELAY/2) + assert state == ['start'], state + api.kill(g) + # will not get there, unless switching is explicitly scheduled by kill + assert state == ['start', 'except'], state + api.sleep(DELAY) + assert state == ['start', 'except', 'finished'], state + + def test_nested_with_timeout(self): + def func(): + return api.with_timeout(0.2, api.sleep, 2, timeout_value=1) + self.assertRaises(api.TimeoutError, api.with_timeout, 0.1, func) + + class Foo(object): diff --git a/tests/test__api.py b/tests/test__api.py deleted file mode 100644 index ed08e62..0000000 --- a/tests/test__api.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2008 AG Projects -# Author: Denis Bilenko -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -import unittest -from eventlet.api import sleep, spawn, kill, with_timeout, TimeoutError - -DELAY = 0.1 - -class Test(unittest.TestCase): - - def test_killing_dormant(self): - state = [] - def test(): - try: - state.append('start') - sleep(DELAY) - except: - state.append('except') - # catching GreenletExit - pass - # when switching to hub, hub makes itself the parent of this greenlet, - # thus after the function's done, the control will go to the parent - # QQQ why the first sleep is not enough? - sleep(0) - state.append('finished') - g = spawn(test) - sleep(DELAY/2) - assert state == ['start'], state - kill(g) - # will not get there, unless switching is explicitly scheduled by kill - assert state == ['start', 'except'], state - sleep(DELAY) - assert state == ['start', 'except', 'finished'], state - - def test_nested_with_timeout(self): - def func(): - return with_timeout(0.2, sleep, 2, timeout_value=1) - self.assertRaises(TimeoutError, with_timeout, 0.1, func) - -if __name__=='__main__': - unittest.main() -