def test_timeout(self): with patch('jnpr.junos.Device.timeout', new_callable=PropertyMock) as mock_timeout: mock_timeout.return_value = 30 function = lambda x: x decorator = timeoutDecorator(function) decorator(self.dev, dev_timeout=10) calls = [call(), call(10), call(30)] mock_timeout.assert_has_calls(calls)
def test_timeout(self): with patch('jnpr.junos.Device.timeout', new_callable=PropertyMock) as mock_timeout: mock_timeout.return_value = 30 def function(x): return x decorator = timeoutDecorator(function) decorator(self.dev, dev_timeout=10) calls = [call(), call(10), call(30)] mock_timeout.assert_has_calls(calls)
def test_timeout_except(self): with patch('jnpr.junos.Device.timeout', new_callable=PropertyMock) as mock_timeout: mock_timeout.return_value = 30 def function(*args, **kwargs): raise Exception() decorator = timeoutDecorator(function) # test to ensure the exception is raised with self.assertRaises(Exception): decorator(self.dev, dev_timeout=10) calls = [call(), call(10), call(30)] # verify timeout was set/reset mock_timeout.assert_has_calls(calls)