예제 #1
0
class TestAsyncState(tornado.testing.AsyncTestCase):

    def setUp(self):
        super(TestAsyncState, self).setUp()
        self._valid_states = ['on', 'off', 'floating']
        self._state = AsyncState(self._valid_states, 'off', self.io_loop)

    def test_init(self):
        self.assertEqual(self._state.state, 'off')
        self.assertEqual(sorted(self._state.valid_states),
                         sorted(self._valid_states))

    @tornado.testing.gen_test
    def test_timeout_of_until_state(self):
        @tornado.gen.coroutine
        def set_state_on():
            self._state.set_state('on')
        # Test for timing out
        with self.assertRaises(tornado.gen.TimeoutError):
            yield self._state.until_state('on', timeout=0.1)
        # Test for NOT timing out
        self.io_loop.add_callback(set_state_on)
        yield self._state.until_state('on', timeout=0.1)

    @tornado.testing.gen_test
    def test_timeout_of_until_state_in(self):
        @tornado.gen.coroutine
        def set_state_floating():
            self._state.set_state('floating')
        # Test for timing out
        with self.assertRaises(tornado.gen.TimeoutError):
            yield self._state.until_state_in('on', 'floating', timeout=0.1)
        # Test for NOT timing out
        self.io_loop.add_callback(set_state_floating)
        yield self._state.until_state_in('on', 'floating', timeout=0.1)
예제 #2
0
class TestAsyncState(tornado.testing.AsyncTestCase):

    def setUp(self):
        super(TestAsyncState, self).setUp()
        self._valid_states = ['on', 'off', 'floating']
        self._state = AsyncState(self._valid_states, 'off', self.io_loop)

    def test_init(self):
        self.assertEqual(self._state.state, 'off')
        self.assertEqual(sorted(self._state.valid_states),
                         sorted(self._valid_states))

    @tornado.testing.gen_test
    def test_timeout_of_until_state(self):
        @tornado.gen.coroutine
        def set_state_on():
            self._state.set_state('on')
        # Test for timing out
        with self.assertRaises(tornado.gen.TimeoutError):
            yield self._state.until_state('on', timeout=0.1)
        # Test for NOT timing out
        self.io_loop.add_callback(set_state_on)
        yield self._state.until_state('on', timeout=0.1)

    @tornado.testing.gen_test
    def test_timeout_of_until_state_in(self):
        @tornado.gen.coroutine
        def set_state_floating():
            self._state.set_state('floating')
        # Test for timing out
        with self.assertRaises(tornado.gen.TimeoutError):
            yield self._state.until_state_in('on', 'floating', timeout=0.1)
        # Test for NOT timing out
        self.io_loop.add_callback(set_state_floating)
        yield self._state.until_state_in('on', 'floating', timeout=0.1)
예제 #3
0
 def setUp(self):
     super(TestAsyncState, self).setUp()
     self._valid_states = ['on', 'off', 'floating']
     self._state = AsyncState(self._valid_states, 'off', self.io_loop)
예제 #4
0
 def setUp(self):
     super(TestAsyncState, self).setUp()
     self._valid_states = ['on', 'off', 'floating']
     self._state = AsyncState(self._valid_states, 'off', self.io_loop)