def test_positional_then_optional(self): opt_val = 1 class DemoGroup(CommandGroup): name = 'demo' @command('callme') @command_arg('arg1') @command_arg('--opt-arg', required=False, default=opt_val) def maybe(self, arg1, opt_arg): return (arg1, opt_arg) parser = argparse.ArgumentParser() DemoGroup().build(parser.add_subparsers()) arg1_val = 'yay' args = parser.parse_args(['demo', 'callme', arg1_val]) expect(args).to(have_properties(arg1=arg1_val, opt_arg=opt_val)) args = parser.parse_args( ['demo', 'callme', arg1_val, '--opt-arg', '2']) expect(args).to(have_properties(arg1=arg1_val, opt_arg='2'))
def test_word_list_validity(self): """Tests the the words returned from the json decoder are valid""" words = NetworkManager.words_from_json(self, self.sample_json) for word in words: expect(word).to( have_properties("word", "definition", "pronunciation")) expect(word.word).to_not(be_empty) expect(word.definition).to_not(be_empty) expect(word.pronunciation).to_not(be_empty)
def test_positional_args(self): class DemoGroup(CommandGroup): name = 'demo' @command('callme') @command_arg('arg1') @command_arg('arg2') def maybe(self, arg1, arg2): return arg1, arg2 parser = argparse.ArgumentParser() DemoGroup().build(parser.add_subparsers()) arg1_val = 'yay' arg2_val = 'works' args = parser.parse_args(['demo', 'callme', arg1_val, arg2_val]) expect(args).to(have_properties(arg1=arg1_val, arg2=arg2_val)) expect(args.func(args.arg1, args.arg2))\ .to(equal((arg1_val, arg2_val)))
from expects import expect, equal, have_properties from doublex import Spy, when from agenda_create_action import AgendaCreateAction from agenda_service import AgendaService from agenda_models import Contact A_NAME = 'a_name' A_SURNAME = 'a_surname' A_PHONE_NUMBER = 'a_phone_number' AN_EMAIL = 'an_email' with describe('Agenda create action'): with context('creating a contact'): with it('returns the created contact'): contact = { 'name': A_NAME, 'surname': A_SURNAME, 'phone_number': A_PHONE_NUMBER, 'email': AN_EMAIL } an_agenda_service = Spy(AgendaService) a_contact = Contact(A_NAME, A_SURNAME, A_PHONE_NUMBER, AN_EMAIL) when(an_agenda_service).add(A_NAME, A_SURNAME, A_PHONE_NUMBER, AN_EMAIL).returns(a_contact) create_action = AgendaCreateAction(an_agenda_service) creation = create_action.execute(contact) expect(creation).to(have_properties(name=A_NAME))
def test_can_set_new_attributes(self, record): record = record() record.name = "Daru" expect(record).to(have_properties(name="Daru"))
def test_cannot_get_unset_attributes(self, record): record = record(name="Okarin", age=18) expect(record).not_to(have_properties("occupation"))
def test_can_get_the_attributes_set_in_constructor(self, record): record = record(name="Okarin", age=18) expect(record).to(have_properties(name="Okarin", age=18))