def given_the_circuit_was_about_to_be_broken(self): self.patch = mock.patch('time.perf_counter', return_value=0) self.mock = self.patch.start() contexts.catch(self.function_to_break) self.mock.return_value = 0.5 contexts.catch(self.function_to_break) self.mock.return_value = 1.1
def given_the_circuit_was_half_broken_and_the_function_failed_again(self): self.x = 0 self.patch = mock.patch('time.perf_counter', return_value=0) self.mock = self.patch.start() contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) self.mock.return_value = 1.1 contexts.catch(self.function_to_break)
def given_the_function_has_failed_three_times(self): self.patch = mock.patch('time.perf_counter', return_value=0) self.mock = self.patch.start() self.x = 0 contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) self.x = 0
def given_the_circuit_was_broken_in_the_past(self): self.x = 0 self.expected_exception = ValueError() self.patch = mock.patch('time.perf_counter', return_value=0) self.mock = self.patch.start() contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) contexts.catch(self.function_to_break)
def given_the_circuit_was_broken_in_the_past(self): self.x = 0 self.expected_return_value = "some thing that was returned" self.patch = mock.patch('time.perf_counter', return_value=0) self.mock = self.patch.start() contexts.catch(self.function_to_break) contexts.catch(self.function_to_break) contexts.catch(self.function_to_break)
def when_i_call_the_circuit_breaker_function(self): self.exception = contexts.catch(self.function_to_break)
def because_the_bad_frame_arrives(self): self.exception = contexts.catch(self.protocol.data_received, self.raw)
def when_i_override_a_nonexistent_property(self): self.exception = catch(lambda name: getattr(self.builder, name), 'with_nonexistent')
def when_we_import_the_module_and_prompt_it_to_raise_the_exception(self): self.module = self.importer.import_module(TEST_DATA_DIR, self.module_name) self.exc = contexts.catch(self.module.assertion_func)
def because_we_call_catch(self): self.caught = contexts.catch(self.throwing_function, 3, c='yes', b=None)
def because_we_read_the_table(self, bytes): # We expect the serialisation to read over the bounds, but only if it is unsigned self.exception = contexts.catch(serialisation.read_table, BytesIO(bytes))
def when_i_poll_the_function(self): self.exception = catch(poll_, self.function_to_poll, lambda x: x == 1, interval=0.001)
def when_i_execute_the_retryable_function(self): self.exception = catch(self.function_to_retry)
def when_the_call_fails_again(self): self.exception = contexts.catch(self.function_to_break)
def when_we_run_the_function_again(self): self.exception1 = contexts.catch(self.function_to_break) self.exception2 = contexts.catch(self.function_to_break) self.exception3 = contexts.catch(self.function_to_break)
def when_i_call_the_circuit_breaker_function(self): self.mock.return_value = 0.5 self.exception = contexts.catch(self.function_to_break)
def when_I_cancel_the_consumer_and_also_get_a_message(self): self.consumer.cancel() self.exception = contexts.catch(self.loop.run_until_complete, asyncio.wait_for(self.queue.get(), 0.2))
def when_we_wait_for_the_timeout_and_retry(self): self.exception = contexts.catch(self.function_to_break)
def when_i_execute_the_function_to_poll(self): self.exception = catch(self.function_to_poll)
def given_the_function_has_failed_twice(self): self.expected_exception = ValueError() contexts.catch(self.function_to_break) contexts.catch(self.function_to_break)
def when_I_set_the_handler(self): self.exception = contexts.catch(self.channel.set_return_handler, "i am not callable")
def because_the_framework_asks_the_plugin_to_identify_the_method( self, method): self.exception = contexts.catch(self.identifier.identify_method, method)
def when_i_retry_the_function(self): self.exception = catch(retry_, self.function_to_retry, [ValueError, IndexError], times=3, interval=0.001)
def because_the_bad_frame_arrives(self): self.exception = contexts.catch(self.server.send_bytes, self.raw)
def it_should_raise_error_in_connection_methods(self): exc = contexts.catch(self.wait_for, self.connection.open_channel()) assert isinstance(exc, exceptions.ConnectionClosed)
def because_the_framework_asks_the_plugin_to_identify_the_method(self, method): self.exception = contexts.catch(self.identifier.identify_method, method)
def because_we_try_to_initialise_the_plugin(self): self.exception = contexts.catch(self.supplier.initialise, self.args, {})
def when_we_try_to_use_the_decorators(self): self.exception = catch(self.throwing_func)
def when_I_cancel_the_consumer_and_also_get_a_message(self): self.consumer.cancel() self.exception = contexts.catch( self.loop.run_until_complete, asyncio.wait_for(self.queue.get(), 0.2))
def because_an_unexpected_error_occurs(self): self.exception = contexts.catch(self.before.unexpected_error, Exception())
def it_should_raise_error_in_connection_methods(self): exc = contexts.catch(self.wait_for, self.connection.open_channel()) assert isinstance(exc, exceptions.AlreadyClosed)
def when_i_poll_the_function(self): self.exception = catch(poll_, self.function_to_poll, lambda x: x == 3, timeout=0.04, interval=0.03)
def because_we_read_the_table(self, bytes): self.exception = contexts.catch(serialisation.read_table, BytesIO(bytes))
def when_i_poll_the_function(self): self.exception = catch(poll_, self.function_to_poll, lambda self: self.throw(), interval=0.001)
def because_we_read_a_bad_long_string(self): self.exception = contexts.catch( serialisation.read_long_string, BytesIO(b"\x00\x00\x00\x10hello")) # length too long
def because_we_read_a_bad_long_string(self): self.exception = contexts.catch( serialisation.read_long_string, BytesIO(b"\x00\x00\x00\x10hello") ) # length too long
def because_we_try_to_import_the_file(self): self.exception = contexts.catch(self.importer.import_module, TEST_DATA_DIR, self.module_name)
def when_the_connection_dies(self): contexts.catch(self.protocol.connection_lost, self.exception) self.tick()