def should_increment(self): ''' total() should increment as verifiable_fn is included ''' spec = Spec(AllVerifiable, given=silent_listener) spec.total().should_be(0) spec.when(spec.include(raise_index_error)) spec.then(spec.total()).should_be(1) spec.when(spec.include(dont_raise_index_error)) spec.then(spec.total()).should_be(2)
def should_return_all_results(self): ''' verify() should return the result of all attempted / successful verifications ''' spec = Spec(AllVerifiable, given=silent_listener) spec.verify().should_be({'total': 0, 'verified': 0, 'unverified': 0}) spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(number_one)) spec.then(spec.verify()) spec.should_be({'total': 1, 'verified': 1, 'unverified': 0}) spec.when(spec.include(raise_index_error)) spec.then(spec.verify()) spec.should_be({'total': 2, 'verified': 1, 'unverified': 1})
def all_verif_failfast_behaviour(): ''' verify(fail_fast=True) should stop after the first unmet specification or unexpected exception''' spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(raise_index_error), spec.include(dont_raise_index_error)) spec.then(spec.verify(fail_fast=True)) spec.should_be({'total':2, 'verified':0, 'unverified':2, 'fail_fast':True}) spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(unmet_specification), spec.include(dont_raise_index_error)) spec.then(spec.verify(fail_fast=True)) spec.should_be({'total':2, 'verified':0, 'unverified':2, 'fail_fast':True})
def should_return_all_results(self): ''' verify() should return the result of all attempted / successful verifications ''' spec = Spec(AllVerifiable, given=silent_listener) spec.verify().should_be({'total':0, 'verified':0, 'unverified':0}) spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(number_one)) spec.then(spec.verify()) spec.should_be({'total':1, 'verified':1, 'unverified':0}) spec.when(spec.include(raise_index_error)) spec.then(spec.verify()) spec.should_be({'total':2, 'verified':1, 'unverified':1})
def should_verify_each_item(self): ''' verify() should execute each included item ''' a_list = [] lambda_list_append1 = lambda: a_list.append(0) lambda_list_append2 = lambda: a_list.extend((1, 2)) spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(lambda_list_append1), spec.include(lambda_list_append2), spec.verify()) spec.then(a_list.__len__).should_be(3)
def notification_behaviour(): ''' listener should receive notifications AllVerifiable.verify() ''' listener = MockSpec() all_verifiable_with_mock_listener = AllVerifiable(listener) results = {'total': 3, 'verified': 1, 'unverified': 2} spec = Spec(all_verifiable_with_mock_listener) spec.when(spec.include(string_abc), spec.include(raise_index_error), spec.include(unmet_specification)) spec.then(spec.verify()) spec.should_collaborate_with( listener.all_verifiable_starting(all_verifiable_with_mock_listener), listener.verification_started(string_abc), listener.specification_met(string_abc), listener.verification_started(raise_index_error), listener.unexpected_exception(raise_index_error, Type(IndexError)), listener.verification_started(unmet_specification), listener.specification_unmet(unmet_specification, Type(UnmetSpecification)), listener.all_verifiable_ending(all_verifiable_with_mock_listener, results), and_result=results)
def notification_behaviour(): ''' listener should receive notifications AllVerifiable.verify() ''' listener = MockSpec() all_verifiable_with_mock_listener = AllVerifiable(listener) results = {'total': 3, 'verified': 1, 'unverified': 2} spec = Spec(all_verifiable_with_mock_listener) spec.when(spec.include(string_abc), spec.include(raise_index_error), spec.include(unmet_specification)) spec.then(spec.verify()) spec.should_collaborate_with( listener.all_verifiable_starting(all_verifiable_with_mock_listener), listener.verification_started(string_abc), listener.specification_met(string_abc), listener.verification_started(raise_index_error), listener.unexpected_exception(raise_index_error, Type(IndexError)), listener.verification_started(unmet_specification), listener.specification_unmet(unmet_specification, Type(UnmetSpecification)), listener.all_verifiable_ending(all_verifiable_with_mock_listener, results), and_result = results)
def all_verif_failfast_behaviour(): ''' verify(fail_fast=True) should stop after the first unmet specification or unexpected exception''' spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(raise_index_error), spec.include(dont_raise_index_error)) spec.then(spec.verify(fail_fast=True)) spec.should_be({ 'total': 2, 'verified': 0, 'unverified': 2, 'fail_fast': True }) spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(unmet_specification), spec.include(dont_raise_index_error)) spec.then(spec.verify(fail_fast=True)) spec.should_be({ 'total': 2, 'verified': 0, 'unverified': 2, 'fail_fast': True })
def all_verif_include_behaviour(): ''' include() method should return self ''' all_verifiable = silent_listener() spec = Spec(all_verifiable) spec.include(string_abc).should_be(all_verifiable)
def should_ignore_duplicates(self): ''' total() should ignore duplicate include()s ''' spec = Spec(AllVerifiable, given=silent_listener) spec.when(spec.include(raise_index_error), spec.include(raise_index_error)) spec.then(spec.total()).should_be(1)