コード例 #1
0
def not_behaviour():
    ''' Not should raise exception iff underlying check succeeds '''
    spec = Spec(Not(Constraint(EqualsEquals(2))))
    spec.verify(number_one).should_not_raise(UnmetSpecification)

    spec = Spec(Not(Constraint(EqualsEquals(1))))
    msg = 'should not be == 1'
    spec.describe_constraint().should_be(msg)
    spec.verify(number_one).should_raise(UnmetSpecification(msg))

    spec = Spec(Not(Not(Constraint(EqualsEquals(2)))))
    msg = 'should be == 2'
    spec.describe_constraint().should_be(msg)
    spec.verify(number_one).should_raise(UnmetSpecification(msg))
コード例 #2
0
 def verify_should_invoke_callable(self):
     ''' verify should invoke callable and compare result '''
     a_list = []
     with_callable = lambda: a_list.append(True)
     spec = Spec(Constraint())
     spec.verify(with_callable).should_raise(UnmetSpecification)
     spec.then(a_list.__len__).should_be(1)
コード例 #3
0
 def desc_should_use_comparator(self):
     ''' describe_constraint should delegate to comparator.description '''
     comparator = MockSpec()
     spec = Spec(Constraint(comparator))
     comparator_description = comparator.description()
     comparator_description.will_return('subtitled')
     spec.describe_constraint()
     spec.should_collaborate_with(comparator_description,
                                  and_result='should be subtitled')
コード例 #4
0
 def should_use_nothing_comparator(self):
     ''' Constraint should use Nothing comparator by default'''
     spec = Spec(Constraint())
     spec.describe_constraint().should_be('should be nothing')
     spec.verify_value(1).should_be(False)
     spec.verify_value(2).should_be(False)
     spec.verify_value(None).should_be(False)
     spec.verify_value(['majestic', 'moose']).should_be(False)
     spec.verify_value({'gumby': 'brain surgeon'}).should_be(False)
コード例 #5
0
ファイル: specification.py プロジェクト: peterdemin/lancelot
 def __init__(self, spec_for, given=None):
     ''' A new specification, for an object, class or standalone function.
     Usage: Spec(standalone fn), Spec(object),
     or Spec(class, given=descriptive_callable_setting_up_initial_state) '''
     self._call_stack = []
     self._spec_for = spec_for
     self._constraint = Constraint()
     self._given = given
     if given:
         self._setup_initial_state()
コード例 #6
0
ファイル: specification.py プロジェクト: peterdemin/lancelot
 def should_not_be(self, unspecified):
     ''' An action's behaviour should not return a specified value. '''
     if isinstance(unspecified, Comparator):
         return self.should(Constraint(NotComparator(unspecified)))
     return self.should(Not(Constraint(EqualsEquals(unspecified))))
コード例 #7
0
ファイル: specification.py プロジェクト: peterdemin/lancelot
 def should_be(self, specified):
     ''' An action's behaviour should return a specified value. '''
     if isinstance(specified, Comparator):
         return self.should(Constraint(specified))
     return self.should(Constraint(EqualsEquals(specified)))
コード例 #8
0
ファイル: specification.py プロジェクト: peterdemin/lancelot
 def should_not_contain(self, unspecified):
     ''' The result of an action's behaviour should not contain a specified
     value (e.g. tuples, lists or dicts). '''
     return self.should(Constraint(NotComparator(Contain(unspecified))))
コード例 #9
0
ファイル: specification.py プロジェクト: peterdemin/lancelot
 def should_contain(self, specified):
     ''' The result of an action's behaviour should contain a specified
     value (e.g. tuples, lists or dicts). '''
     return self.should(Constraint(Contain(specified)))
コード例 #10
0
 def verify_should_use_comparator(self):
     ''' verify should delegate to comparator.compares_to '''
     comparator = MockSpec()
     spec = Spec(Constraint(comparator))
     comparator_compares_to = comparator.compares_to(1).will_return(True)
     spec.verify(lambda: 1).should_collaborate_with(comparator_compares_to)