コード例 #1
0
 def test_invalid_timeout_string(self):
     for inv in ['invalid', '1s 1']:
         err = "Setting test timeout failed: Invalid time string '%s'."
         self._verify_tout(TestTimeout(inv),
                           str=inv,
                           secs=0.000001,
                           err=err % inv)
コード例 #2
0
class TestRun(unittest.TestCase):

    def setUp(self):
        self.tout = TestTimeout('1s', variables=VariableMock())
        self.tout.start()

    def test_passing(self):
        assert_equals(self.tout.run(passing), None)

    def test_returning(self):
        for arg in [ 10, 'hello', ['l','i','s','t'], unittest]:
            ret = self.tout.run(returning, args=(arg,))
            assert_equals(ret, arg)

    def test_failing(self):
        assert_raises_with_msg(MyException, 'hello world',
                               self.tout.run, failing, ('hello world',))

    if JYTHON:

        def test_java_failing(self):
            from java.lang import Error
            from thread_resources import java_failing
            assert_raises_with_msg(Error, 'java.lang.Error: hi tellus',
                                   self.tout.run, java_failing, ('hi tellus',))

    def test_sleeping(self):
        assert_equals(self.tout.run(sleeping, args=(0.01,)), 0.01)

    def test_method_executed_normally_if_no_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.run(sleeping, (0.05,))
        assert_equals(os.environ['ROBOT_THREAD_TESTING'], '0.05')

    def test_method_stopped_if_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.secs = 0.001
        # PyThreadState_SetAsyncExc thrown exceptions are not guaranteed
        # to occur in a specific timeframe ,, thus the actual Timeout exception
        # maybe thrown too late in Windows.
        # This is why we need to have an action that really will take some time (sleep 5 secs)
        # to (almost) ensure that the 'ROBOT_THREAD_TESTING' setting is not executed before
        # timeout exception occurs
        assert_raises_with_msg(TimeoutError, 'Test timeout 1 second exceeded.',
                               self.tout.run, sleeping, (5,))
        assert_equals(os.environ['ROBOT_THREAD_TESTING'], 'initial value')

    def test_zero_and_negative_timeout(self):
        for tout in [0, 0.0, -0.01, -1, -1000]:
            self.tout.time_left = lambda: tout
            assert_raises(TimeoutError, self.tout.run, sleeping, (10,))

    def test_customized_message(self):
        tout = KeywordTimeout('1s', 'My message', VariableMock())
        tout.start()
        tout.run(passing)
        tout.secs = 0.001
        assert_raises_with_msg(TimeoutError, 'My message',
                               tout.run, sleeping, (10,))
コード例 #3
0
class TestRun(unittest.TestCase):

    def setUp(self):
        self.tout = TestTimeout('1s', variables=VariableMock())
        self.tout.start()

    def test_passing(self):
        assert_equal(self.tout.run(passing), None)

    def test_returning(self):
        for arg in [ 10, 'hello', ['l','i','s','t'], unittest]:
            ret = self.tout.run(returning, args=(arg,))
            assert_equal(ret, arg)

    def test_failing(self):
        assert_raises_with_msg(MyException, 'hello world',
                               self.tout.run, failing, ('hello world',))

    if JYTHON:

        def test_java_failing(self):
            from java.lang import Error
            from thread_resources import java_failing
            assert_raises_with_msg(Error, 'java.lang.Error: hi tellus',
                                   self.tout.run, java_failing, ('hi tellus',))

    def test_sleeping(self):
        assert_equal(self.tout.run(sleeping, args=(0.01,)), 0.01)

    def test_method_executed_normally_if_no_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.run(sleeping, (0.05,))
        assert_equal(os.environ['ROBOT_THREAD_TESTING'], '0.05')

    def test_method_stopped_if_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.secs = 0.001
        # PyThreadState_SetAsyncExc thrown exceptions are not guaranteed
        # to occur in a specific timeframe ,, thus the actual Timeout exception
        # maybe thrown too late in Windows.
        # This is why we need to have an action that really will take some time (sleep 5 secs)
        # to (almost) ensure that the 'ROBOT_THREAD_TESTING' setting is not executed before
        # timeout exception occurs
        assert_raises_with_msg(TimeoutError, 'Test timeout 1 second exceeded.',
                               self.tout.run, sleeping, (5,))
        assert_equal(os.environ['ROBOT_THREAD_TESTING'], 'initial value')

    def test_zero_and_negative_timeout(self):
        for tout in [0, 0.0, -0.01, -1, -1000]:
            self.tout.time_left = lambda: tout
            assert_raises(TimeoutError, self.tout.run, sleeping, (10,))

    def test_customized_message(self):
        tout = KeywordTimeout('1s', 'My message', VariableMock())
        tout.start()
        tout.run(passing)
        tout.secs = 0.001
        assert_raises_with_msg(TimeoutError, 'My message',
                               tout.run, sleeping, (10,))
コード例 #4
0
ファイル: test_timeouts.py プロジェクト: gdw2/robot-framework
class TestRun(unittest.TestCase):
    def setUp(self):
        self.tout = TestTimeout('1s', variables=VariableMock())
        self.tout.start()

    def test_passing(self):
        assert_none(self.tout.run(passing))

    def test_returning(self):
        for arg in [10, 'hello', ['l', 'i', 's', 't'], unittest]:
            ret = self.tout.run(returning, args=(arg, ))
            assert_equals(ret, arg)

    def test_failing(self):
        assert_raises_with_msg(MyException, 'hello world', self.tout.run,
                               failing, ('hello world', ))

    if sys.platform.startswith('java'):

        def test_java_failing(self):
            from java.lang import Error
            from thread_resources import java_failing
            assert_raises_with_msg(Error, 'java.lang.Error: hi tellus',
                                   self.tout.run, java_failing,
                                   ('hi tellus', ))

    def test_sleeping(self):
        assert_equals(self.tout.run(sleeping, args=(0.01, )), 0.01)

    def test_method_executed_normally_if_no_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.run(sleeping, (0.05, ))
        assert_equals(os.environ['ROBOT_THREAD_TESTING'], '0.05')

    def test_method_stopped_if_timeout(self):
        os.environ['ROBOT_THREAD_TESTING'] = 'initial value'
        self.tout.secs = 0.001
        assert_raises_with_msg(TimeoutError, 'Test timeout 1 second exceeded.',
                               self.tout.run, sleeping, (0.05, ))
        time.sleep(0.1)
        assert_equals(os.environ['ROBOT_THREAD_TESTING'], 'initial value')

    def test_zero_and_negative_timeout(self):
        for tout in [0, 0.0, -0.01, -1, -1000]:
            self.tout.time_left = lambda: tout
            assert_raises(TimeoutError, self.tout.run, sleeping, (10, ))

    def test_customized_message(self):
        tout = KeywordTimeout('1s', 'My message', VariableMock())
        tout.start()
        tout.run(passing)
        tout.secs = 0.001
        time.sleep(0.01)
        assert_raises_with_msg(TimeoutError, 'My message', tout.run, sleeping,
                               (1, ))
コード例 #5
0
 def setUp(self):
     self.tout = TestTimeout('1s', variables=VariableMock())
     self.tout.start()
コード例 #6
0
 def _create_timeouts(self, tout_strs):
     touts = []
     for tout_str in tout_strs:
         touts.append(TestTimeout(tout_str, variables=VariableMock()))
         touts[-1].start()
     return touts
コード例 #7
0
 def test_timed_out_with_exceeded_timeout(self):
     tout = TestTimeout('1ms', variables=VariableMock())
     tout.start()
     time.sleep(0.02)
     assert_true(tout.timed_out())
コード例 #8
0
 def test_timed_out_with_non_exceeded_timeout(self):
     tout = TestTimeout('10s', variables=VariableMock())
     tout.start()
     time.sleep(0.01)
     assert_false(tout.timed_out())
コード例 #9
0
 def test_timed_out_with_non_exceeded_timeout(self):
     tout = TestTimeout('10s', variables=VariableMock())
     tout.start()
     time.sleep(0.01)
     assert_false(tout.timed_out())
コード例 #10
0
 def test_timeout_string(self):
     for tout_str, exp_str, exp_secs in [ ('1s', '1 second', 1),
                                          ('10 sec', '10 seconds', 10),
                                          ('2h 1minute', '2 hours 1 minute', 7260),
                                          ('42', '42 seconds', 42) ]:
         self._verify_tout(TestTimeout(tout_str), exp_str, exp_secs)
コード例 #11
0
 def test_no_params(self):
     self._verify_tout(TestTimeout())
コード例 #12
0
 def test_failed_default(self):
     tout = TestTimeout('1s', variables=VariableMock())
     tout.starttime = time.time() - 2
     assert_equal(tout.get_message(), 'Test timeout 1 second exceeded.')
コード例 #13
0
 def test_non_active(self):
     assert_equal(TestTimeout().get_message(), 'Test timeout not active.')
コード例 #14
0
 def setUp(self):
     self.tout = TestTimeout('1s', variables=VariableMock())
     self.tout.start()
コード例 #15
0
 def test_failed_default(self):
     tout = TestTimeout('1s', variables=VariableMock())
     tout.starttime = time.time() - 2
     assert_equals(tout.get_message(), 'Test timeout 1 second exceeded.')
コード例 #16
0
 def test_time_left(self):
     tout = TestTimeout('1s', variables=VariableMock())
     tout.start()
     assert_true(tout.time_left() > 0.9)
     time.sleep(0.2)
     assert_true(tout.time_left() < 0.9)
コード例 #17
0
 def test_invalid_timeout_string(self):
     for inv in ['invalid', '1s 1']:
         for params in [ [inv], [inv,'whatever'] ]:
             tout = TestTimeout(*params)
             err = "Setting test timeout failed: Invalid time string '%s'."
             self._verify_tout(tout, str=inv, secs=0.000001, err=err % inv)
コード例 #18
0
 def test_timed_out_with_exceeded_timeout(self):
     tout = TestTimeout('1ms', variables=VariableMock())
     tout.start()
     time.sleep(0.02)
     assert_true(tout.timed_out())
コード例 #19
0
 def test_time_left(self):
     tout = TestTimeout('1s', variables=VariableMock())
     tout.start()
     assert_true(tout.time_left() > 0.9)
     time.sleep(0.2)
     assert_true(tout.time_left() < 0.9)