def test_returns_queried_record(self): Record.persistence_strategy.query.return_value = [{ "lab_member_id": 1 }, { "lab_member_id": 2 }] result = list(Record.all()) expect(result).to( contain_exactly(Record(lab_member_id=1), Record(lab_member_id=2)))
module = _load_module(INCLUDED_CONTEXT_PATH) examples = loader.Loader().load_examples_from(module) expect(examples[1]).to(have_length(1)) expect(examples[1].examples[0]).to(be_a(example_group.ExampleGroup)) with it('inserts the examples of the shared context'): module = _load_module(INCLUDED_CONTEXT_PATH) examples = loader.Loader().load_examples_from(module) expect(examples[1]).to(have_length(1)) included_context = examples[1].examples[0] expect(example_names(included_context.examples)).to(equal(['it shared example', 'it added example'])) with context('when loading with relative import'): with it('loads module and perform relative import'): module = _load_module(WITH_RELATIVE_IMPORT_PATH) expect(module).to(have_property('HelperClass')) with context('when loading helper methods'): with it('loads all functions and properties'): module = _load_module(HELPER_METHODS_PATH) examples = loader.Loader().load_examples_from(module) expect(examples[0].helpers.keys()).to(contain_exactly('helper_method', 'helper_property', 'wrapped_helper_method'))
create_basket_created_event(basket_id), create_item_added_event(basket_id, item_id, item_price), create_item_added_event(basket_id, item_id, item_price), ]) consumer = BasketConsumer(events_repository=events_repository, items_repository=Stub()) next_events = consumer.process(checkout_command) expect(next_events).to(have_len(2)) expect(next_events).to( contain_exactly( have_keys({ 'kind': CHECKOUT_STARTED, 'payload': { 'basket_id': basket_id, 'total_price': 2 * item_price, 'num_unique_items': 1, 'num_items': 2, } }), have_keys({ 'kind': PAY_ORDER, 'payload': { 'basket_id': basket_id, 'total_price': 2 * item_price, } }), ))
decorated_function = Spy().decorated_function expect(on_failure('some_integration')(decorated_function)).to( be(decorated_function)) with it('doesn\'t call the decorated function'): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(decorated_function).to_not(have_been_called) with it('aborts the program if it references a non-existent integration' ): expect(lambda: integrations._create('bogus_name')).to( raise_error(SystemExit)) with it('has the (convenient) side effect of registering the integration name with a subject' ): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(list(integrations.registered_integrations.keys())).to( contain_exactly(decorated_function.__name__)) for setup_function in integrations.registered_integrations: for subject in integrations.registered_integrations[ setup_function]['integrations']: expect(subject).to(be_a(rx.subjects.Subject))
with it('accomplish another example'): provided_filename = '/tmp/example1' generated_filename = self.example1.save(provided_filename) expect(isfile(generated_filename)).to(be_true) with it('accomplish another example'): provided_filename = '/tmp/example2' generated_filename = self.example2.save(provided_filename) expect(isfile(generated_filename)).to(be_true) with context('save barcode in a file with extension'): with it('create a filename with extension if it is not provided'): path = '/tmp/example-c57' file = self.example_c57.save(path) expect(file).to(contain_exactly('/tmp/example-c57.svg')) with it('create a filename with only one extension if it is provided'): path = '/tmp/example-c57.svg' file = self.example_c57.save(path) expect(file).to(contain_exactly('/tmp/example-c57.svg')) with context('SVG barcode'): with it('accomplish the example of cuaderno57.pdf'): svg = self.example_c57.svg() expect(svg).to(contain('<svg', '</svg>')) with it('accomplish another example'): path = '/tmp/example1' svg = self.example1.svg() expect(svg).to(contain('<svg', '</svg>'))
from mamba import description, context, it from expects import expect, contain_exactly, contain import os from simpledatamigrate import collector with description('MigrationCollector') as self: with context('when returning migrations'): with it('returns python files with older in first place'): relative_path = os.path.relpath( os.path.join(os.path.dirname(__file__), 'fixtures/migrations')) migration_collector = collector.MigrationCollector(relative_path) migrations = migration_collector.migrations() expect(migrations).to( contain_exactly('{}/001.py'.format(relative_path), '{}/002.py'.format(relative_path), '{}/003.py'.format(relative_path))) with it('returns migrations with relative path'): relative_path = os.path.relpath( os.path.join(os.path.dirname(__file__), 'fixtures/migrations')) migration_collector = collector.MigrationCollector(relative_path) migrations = migration_collector.migrations() expect(migrations[0]).to(contain(relative_path)) expect(migrations[1]).to(contain(relative_path)) expect(migrations[2]).to(contain(relative_path))
'some_integration': some_integration_instance } with after.each: integrations.registered_integrations = {} integration_config.loaded_integrations = {} with it('returns the decorated function as is'): decorated_function = Spy().decorated_function expect(on_failure('some_integration')(decorated_function)).to(be(decorated_function)) with it('doesn\'t call the decorated function'): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(decorated_function).to_not(have_been_called) with it('has the (convenient) side effect of registering the integration name with a subject'): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(list(integrations.registered_integrations.keys())).to(contain_exactly(decorated_function.__name__)) for setup_function in integrations.registered_integrations: for subject in integrations.registered_integrations[setup_function]['integrations']: expect(subject).to(be_a(rx.subjects.Subject))
from co import factory from expects import expect, be_true, contain_exactly with description('Persistence'): with before.each: self.nickname = '@foolano' self.follower = '@futano' self.follower2 = '@futano2' try: os.remove('users.pickle') except OSError: pass with it('persist users'): user_service = factory.create_user_service() user_service.register(self.nickname) new_user_service = factory.create_user_service() expect(new_user_service.is_registered(self.nickname)).to(be_true) with it('persist followers'): user_service = factory.create_user_service() user_service.register(self.nickname) user_service.add_follower(self.nickname, follower=self.follower) user_service.add_follower(self.nickname, follower=self.follower2) new_user_service = factory.create_user_service() expect(new_user_service.followers_for(self.nickname)).to(contain_exactly(self.follower, self.follower2))
with description('User followers'): with before.each: self.nickname = '@foolano' self.follower = '@futano' self.follower2 = '@futano2' self.user_service = factory.create_user_service(factory.in_memory_user_repository()) with it('initialy a user have no followers'): expect(self.user_service.followers_for(self.nickname)).to(be_empty) with it('register a follower'): self.user_service.register(self.nickname) self.user_service.add_follower(self.nickname, follower=self.follower) expect(self.user_service.followers_for(self.nickname)).to(contain_exactly(self.follower)) with it('register two followers'): self.user_service.register(self.nickname) self.user_service.add_follower(self.nickname, follower=self.follower) self.user_service.add_follower(self.nickname, follower=self.follower2) expect(self.user_service.followers_for(self.nickname)).to(contain_exactly(self.follower, self.follower2)) with description('User cos'): with before.each: self.nickname = '@foolano' self.user_service = factory.create_user_service(factory.in_memory_user_repository())
integrations.registered_integrations = {} integrations.loaded_integrations = {} with it('returns the decorated function as is'): decorated_function = Spy().decorated_function expect(on_failure('some_integration')(decorated_function)).to(be(decorated_function)) with it('doesn\'t call the decorated function'): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(decorated_function).to_not(have_been_called) with it('aborts the program if it references a non-existent integration'): expect(lambda: integrations._create('bogus_name')).to(raise_error(SystemExit)) with it('has the (convenient) side effect of registering the integration name with a subject'): decorated_function = Spy().decorated_function on_failure('some_integration')(decorated_function) expect(list(integrations.registered_integrations.keys())).to( contain_exactly(decorated_function.__name__) ) for setup_function in integrations.registered_integrations: for subject in integrations.registered_integrations[setup_function]['integrations']: expect(subject).to(be_a(rx.subjects.Subject))