async def test_process_same_version(self, target, api_client, test_files_path): with open(path.join(test_files_path, 'fixerio-same-version.jsonl')) as file: async for _ in target.process_lines(file): # noqa: F841 pass assert_that(api_client.truncate_stream_records, never(called()))
def test_load_dataset_existing_expired(self, monkeypatch, api_client, dw, dataset_key): monkeypatch.setattr(os.path, 'getmtime', lambda _: 1468195199) with warnings.catch_warnings(record=True) as w: dataset = dw.load_dataset(dataset_key) assert_that(w, has_length(1)) assert_that(w[-1].category, equal_to(UserWarning)) assert_that(api_client.download_datapackage, never(called())) assert_that(dataset.raw_data, has_length(3))
def test_never_called_with_matcher(self): spy = doublex.Spy() spy.unexpected(2) self.assert_with_message( spy.unexpected, doublex.never(doublex.called().with_args(greater_than(1))), ''' Expected: none of these calls: Spy.unexpected(a value greater than <1>) but: calls that actually ocurred were: Spy.unexpected(2)''')
def test_unexpected_set(self): expected_message = ''' Expected: none of these calls: set ObjCollaborator.prop to ANYTHING but: calls that actually ocurred were: set ObjCollaborator.prop to unexpected ''' spy = doublex.Spy(ObjCollaborator) spy.prop = 'unexpected' self.assert_with_message( spy, doublex.never(doublex.property_set('prop')), expected_message)
def test_unexpected_get(self): expected_message = ''' Expected: none of these calls: get ObjCollaborator.prop but: calls that actually ocurred were: get ObjCollaborator.prop ''' spy = doublex.Spy(ObjCollaborator) spy.prop self.assert_with_message( spy, doublex.never(doublex.property_got('prop')), expected_message)
def test_account_creation__argument_values(self): with Stub(PasswordService) as password_service: password_service.generate().returns('some') store = Spy(AccountStore) service = AccountService(store, password_service) service.create_user('John') assert_that(store.save, called().with_args('John', 'some')) assert_that(store.save, called().with_args('John', ANY_ARG)) assert_that(store.save, never(called().with_args('Alice', anything()))) assert_that(store.save, called().with_args(contains_string('oh'), ANY_ARG))
def test_nerver_called(self): spy = doublex.Spy() spy.foo(1) spy.foo(2) spy.unexpected(5) self.assert_with_message( spy.unexpected, doublex.never(doublex.called()), ''' Expected: none of these calls: Spy.unexpected(ANY_ARG) but: calls that actually ocurred were: Spy.foo(1) Spy.foo(2) Spy.unexpected(5)''')
def test_if_a_consumer_raises_an_exception_the_message_is_not_acknowledged( self): serializer = SerializerStub() serialized_event = serializer.serialize(BananaHappened("apple")) messages = [ Message.create(serialized_event, None, serializer.identifier()) for _ in range(2) ] backend = a_backend_with_messages(messages) consumer = ExceptionaleConsumer() registry = SerializerRegistry(serializer_settings) sut = SimpleMessageDispatcher(consumer, serializer_registry=registry, backend=backend) sut.consume_event("queue") assert_that(backend.acknowledge, never(called()))
def test_consume_on_queue_but_no_consumer_interested_in_the_messages(self): serializer = SerializerStub() serialized_event = serializer.serialize(BananaHappened("apple")) messages = [ Message.create(serialized_event, None, serializer.identifier()) for _ in range(2) ] backend = a_backend_with_messages(messages) consumer = ProxySpy(NoBananaConsumer()) registry = SerializerRegistry(serializer_settings) sut = SimpleMessageDispatcher(consumer, serializer_registry=registry, backend=backend) sut.consume_event("queue") assert_that(consumer.process, never(called())) assert_that(backend.acknowledge, called().times(2))
def test_load_dataset_existing(self, api_client, dw, dataset_key): with warnings.catch_warnings(record=True) as w: dataset = dw.load_dataset(dataset_key) assert_that(w, has_length(0)) assert_that(api_client.download_datapackage, never(called())) assert_that(dataset.raw_data, has_length(3))
def test_load_dataset_existing(self, api_client, dw, dataset_key): dataset = dw.load_dataset(dataset_key) assert_that(api_client.download_datapackage, never(called())) assert_that(dataset.raw_data, has_length(3))