222
230
def test_has_useful_string_representation(self):
223
231
matcher = MockNotCalled()
224
232
self.assertEqual("MockNotCalled", matcher.__str__())
235
class TestHasAttribute(MAASTestCase, MockTestMixin):
237
def test__returns_none_if_attribute_exists(self):
238
attribute = factory.make_string(3, prefix="attr")
239
setattr(self, attribute, factory.make_name("value"))
240
matcher = HasAttribute(attribute)
241
result = matcher.match(self)
242
self.assertIsNone(result)
244
def test__returns_mismatch_if_attribute_does_not_exist(self):
245
attribute = factory.make_string(3, prefix="attr")
246
matcher = HasAttribute(attribute)
247
result = matcher.match(self)
249
result, " does not have a %r attribute" % attribute)
252
class TestIsCallableMock(MAASTestCase, MockTestMixin):
254
def test__returns_none_when_its_a_callable_mock(self):
256
matcher = IsCallableMock()
257
result = matcher.match(mock)
258
self.assertIsNone(result)
260
def test__returns_none_when_its_a_callable_autospec(self):
261
mock = create_autospec(lambda: None)
262
matcher = IsCallableMock()
263
result = matcher.match(mock)
264
self.assertIsNone(result)
266
def test__returns_mismatch_when_its_a_non_callable_mock(self):
267
mock = NonCallableMock()
268
matcher = IsCallableMock()
269
result = matcher.match(mock)
271
result, " is not callable")
273
def test__returns_mismatch_when_its_a_non_callable_autospec(self):
274
mock = create_autospec(None)
275
matcher = IsCallableMock()
276
result = matcher.match(mock)
278
result, " is not callable")
280
def test__returns_mismatch_when_its_a_non_callable_object(self):
281
matcher = IsCallableMock()
282
result = matcher.match(object())
284
result, " is not callable")
287
class TestIsFiredDeferred(MAASTestCase, MockTestMixin):
289
def test__matches_fired_deferred(self):
292
self.assertThat(d, IsFiredDeferred())
294
def test__does_not_match_unfired_deferred(self):
297
IsFiredDeferred().match(d),
298
" has not been called")
300
def test__does_not_match_non_deferred(self):
302
IsFiredDeferred().match(object()),
303
" is not a Deferred")
306
class TestIsUnfiredDeferred(MAASTestCase, MockTestMixin):
308
def test__matches_unfired_deferred(self):
310
self.assertThat(d, IsUnfiredDeferred())
312
def test__does_not_match_fired_deferred(self):
316
IsUnfiredDeferred().match(d),
317
" has been called (result=None)")
319
def test__does_not_match_non_deferred(self):
321
IsUnfiredDeferred().match(object()),
322
" is not a Deferred")