From: A. Jesse Jiryu Davis Date: Tue, 17 Feb 2015 18:16:07 +0000 (-0500) Subject: Combine lock tests into locks_test.py X-Git-Tag: v4.2.0b1~103^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2114d9ded593c2f6a91b29150daf361fed71a1b;p=thirdparty%2Ftornado.git Combine lock tests into locks_test.py --- diff --git a/tornado/test/event_test.py b/tornado/test/event_test.py deleted file mode 100644 index 78fe36683..000000000 --- a/tornado/test/event_test.py +++ /dev/null @@ -1,60 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from datetime import timedelta -import unittest - -from tornado import gen, locks -from tornado.gen import TimeoutError -from tornado.testing import gen_test, AsyncTestCase - - -class TestEvent(AsyncTestCase): - def test_str(self): - event = locks.Event() - self.assertTrue('clear' in str(event)) - self.assertFalse('set' in str(event)) - event.set() - self.assertFalse('clear' in str(event)) - self.assertTrue('set' in str(event)) - - def test_event(self): - e = locks.Event() - future_0 = e.wait() - e.set() - future_1 = e.wait() - e.clear() - future_2 = e.wait() - - self.assertTrue(future_0.done()) - self.assertTrue(future_1.done()) - self.assertFalse(future_2.done()) - - @gen_test - def test_event_timeout(self): - e = locks.Event() - with self.assertRaises(TimeoutError): - yield e.wait(timedelta(seconds=0.01)) - - # After a timed-out waiter, normal operation works. - self.io_loop.add_timeout(timedelta(seconds=0.01), e.set) - yield e.wait(timedelta(seconds=1)) - - def test_event_set_multiple(self): - e = locks.Event() - e.set() - e.set() - self.assertTrue(e.is_set()) - - -if __name__ == '__main__': - unittest.main() diff --git a/tornado/test/condition_test.py b/tornado/test/locks_test.py similarity index 74% rename from tornado/test/condition_test.py rename to tornado/test/locks_test.py index 1ad828907..49e6199cc 100644 --- a/tornado/test/condition_test.py +++ b/tornado/test/locks_test.py @@ -1,9 +1,21 @@ -from __future__ import absolute_import, division, print_function, with_statement +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. from datetime import timedelta +import unittest from tornado import gen, locks -from tornado.testing import AsyncTestCase, gen_test, unittest +from tornado.gen import TimeoutError +from tornado.testing import gen_test, AsyncTestCase class ConditionTest(AsyncTestCase): @@ -157,5 +169,43 @@ class ConditionTest(AsyncTestCase): self.assertTrue(future.done()) +class TestEvent(AsyncTestCase): + def test_str(self): + event = locks.Event() + self.assertTrue('clear' in str(event)) + self.assertFalse('set' in str(event)) + event.set() + self.assertFalse('clear' in str(event)) + self.assertTrue('set' in str(event)) + + def test_event(self): + e = locks.Event() + future_0 = e.wait() + e.set() + future_1 = e.wait() + e.clear() + future_2 = e.wait() + + self.assertTrue(future_0.done()) + self.assertTrue(future_1.done()) + self.assertFalse(future_2.done()) + + @gen_test + def test_event_timeout(self): + e = locks.Event() + with self.assertRaises(TimeoutError): + yield e.wait(timedelta(seconds=0.01)) + + # After a timed-out waiter, normal operation works. + self.io_loop.add_timeout(timedelta(seconds=0.01), e.set) + yield e.wait(timedelta(seconds=1)) + + def test_event_set_multiple(self): + e = locks.Event() + e.set() + e.set() + self.assertTrue(e.is_set()) + + if __name__ == '__main__': unittest.main() diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 1cdcdde0a..1215cc920 100644 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -25,10 +25,8 @@ TEST_MODULES = [ 'tornado.test.asyncio_test', 'tornado.test.auth_test', 'tornado.test.concurrent_test', - 'tornado.test.condition_test', 'tornado.test.curl_httpclient_test', 'tornado.test.escape_test', - 'tornado.test.event_test', 'tornado.test.gen_test', 'tornado.test.httpclient_test', 'tornado.test.httpserver_test', @@ -37,6 +35,7 @@ TEST_MODULES = [ 'tornado.test.ioloop_test', 'tornado.test.iostream_test', 'tornado.test.locale_test', + 'tornado.test.locks_test', 'tornado.test.netutil_test', 'tornado.test.log_test', 'tornado.test.options_test',