def test_raises_if_unmet_expectations(self): class Milk(object): def pour(self): pass milk = Milk() case = CupOf() stub = Stub(milk.pour) stub.expect() case._stubs = deque([stub]) self.assertRaises(ExpectationNotSatisfied, case.test_something)
def test_teardown_closes_out_stubs_and_mocks(self): class Stub(object): calls = 0 def teardown(self): self.calls += 1 obj = type('test', (object, ), {})() setattr(obj, 'mock1', 'foo') setattr(obj, 'mock2', 'bar') case = CupOf() stub = Stub() case._stubs = deque([stub]) case._mocks = deque([(obj, 'mock1', 'fee'), (obj, 'mock2')]) case.teardown() self.assertEqual(1, stub.calls) self.assertEqual('fee', obj.mock1) self.assertFalse(hasattr(obj, 'mock2'))
def test_runs_unmet_expectations(self): class Stub(object): unmet_calls = 0 teardown_calls = 0 def unmet_expectations(self): self.unmet_calls += 1 return [] def teardown(self): self.teardown_calls += 1 # obj = type('test',(object,),{})() # setattr(obj, 'mock1', 'foo') # setattr(obj, 'mock2', 'bar') case = CupOf() stub = Stub() case._stubs = deque([stub]) case.test_local_definitions_work_and_are_global() self.assertEqual(1, stub.unmet_calls) self.assertEqual(1, stub.teardown_calls)
def setUp(self): self.stub = Stub(object)