def test_stub_module_function_with_obj_ref(self): res = stub(samples.mod_func_1) self.assertTrue(isinstance(res, StubFunction)) self.assertEquals(res, getattr(samples, 'mod_func_1')) self.assertEquals(res, samples.mod_func_1) self.assertEquals(res, stub(samples.mod_func_1)) res.teardown()
def test_stub_module_function_with_obj_ref(self): res = stub(samples.mod_func_1) self.assertTrue(isinstance(res,StubFunction)) self.assertEquals(res, getattr(samples,'mod_func_1')) self.assertEquals(res, samples.mod_func_1) self.assertEquals(res, stub(samples.mod_func_1)) res.teardown()
def test_stub_unbound_method_with_obj_ref(self): class Foo(object): def bar(self): pass res = stub(Foo.bar) self.assertTrue(isinstance(res,StubUnboundMethod)) self.assertEquals(res, stub(Foo.bar)) self.assertEquals(res, getattr(Foo,'bar'))
def test_stub_type_with_obj_ref(self): class Foo(object): def bar(self): pass res = stub( Foo ) self.assertTrue( isinstance(res, StubNew) ) self.assertEquals( res, Foo.__new__ ) self.assertEquals( res, stub(Foo) )
def test_stub_property_with_obj_ref_for_the_reader(self): class Foo(object): @property def prop(self): return 3 res = stub(Foo.prop) self.assertTrue(isinstance(res, StubProperty)) self.assertTrue(stub(Foo.prop) is res)
def test_stub_property_on_class_with_attr_name(self): class Foo(object): @property def prop(self): return 3 res = stub(Foo, 'prop') self.assertTrue(isinstance(res,StubProperty)) self.assertTrue(stub(Foo,'prop') is res)
def test_stub_property_on_class_with_attr_name_applies_to_instance(self): class Foo(object): @property def prop(self): return 3 foo = Foo() res = stub(Foo, 'prop') self.assertTrue(stub(foo,'prop') is res)
def test_stub_method_wrapper_with_obj_ref(self): class Foo(object): pass foo = Foo() res = stub(foo.__hash__) self.assertTrue(isinstance(res,StubMethodWrapper)) self.assertEquals(res, stub(foo.__hash__)) self.assertEquals(res, getattr(foo, '__hash__'))
def test_stub_property_on_class_with_attr_name_applies_to_instance(self): class Foo(object): @property def prop(self): return 3 foo = Foo() res = stub(Foo, 'prop') self.assertTrue(stub(foo, 'prop') is res)
def test_stub_method_wrapper_with_obj_ref(self): class Foo(object): pass foo = Foo() res = stub(foo.__hash__) self.assertTrue(isinstance(res, StubMethodWrapper)) self.assertEquals(res, stub(foo.__hash__)) self.assertEquals(res, getattr(foo, '__hash__'))
def test_stub_property_on_class_with_attr_name(self): class Foo(object): @property def prop(self): return 3 res = stub(Foo, 'prop') self.assertTrue(isinstance(res, StubProperty)) self.assertTrue(stub(Foo, 'prop') is res)
def test_stub_unbound_method_with_obj_ref(self): class Foo(object): def bar(self): pass res = stub(Foo.bar) self.assertTrue(isinstance(res, StubUnboundMethod)) self.assertEquals(res, stub(Foo.bar)) self.assertEquals(res, getattr(Foo, 'bar'))
def test_stub_bound_method_for_classmethod_with_attr_name(self): class Foo(object): @classmethod def bar(self): pass res = stub(Foo, 'bar') self.assertTrue(isinstance(res,StubMethod)) self.assertEquals(res, stub(Foo,'bar')) self.assertEquals(res, getattr(Foo,'bar'))
def test_stub_bound_method_for_classmethod_with_attr_name(self): class Foo(object): @classmethod def bar(self): pass res = stub(Foo, 'bar') self.assertTrue(isinstance(res, StubMethod)) self.assertEquals(res, stub(Foo, 'bar')) self.assertEquals(res, getattr(Foo, 'bar'))
def test_stub_mock_with_obj_ref(self): class Foo(object): def bar(self): pass f = Foo() f.bar = Mock() res = stub(f.bar) self.assertTrue(isinstance(res, StubMethod)) self.assertEquals(res, f.bar.__call__) self.assertEquals(res, stub(f.bar))
def test_stub_mock_with_attr_name(self): class Foo(object): def bar(self): pass f = Foo() f.bar = Mock() res = stub(f, 'bar') self.assertTrue(isinstance(res, StubMethod)) self.assertEqual(res, f.bar.__call__) self.assertEqual(res, stub(f, 'bar'))
def test_stub_bound_method_for_instance_with_obj_ref(self): class Foo(object): def bar(self): pass foo = Foo() orig = foo.bar res = stub(foo.bar) self.assertTrue(isinstance(res,StubMethod)) self.assertEquals(res._instance, foo) self.assertEquals(res._obj, orig) self.assertEquals(res._attr, 'bar') self.assertEquals(res, stub(foo.bar)) self.assertEquals(res, getattr(foo,'bar'))
def test_stub_bound_method_for_instance_with_obj_ref(self): class Foo(object): def bar(self): pass foo = Foo() orig = foo.bar res = stub(foo.bar) self.assertTrue(isinstance(res, StubMethod)) self.assertEquals(res._instance, foo) self.assertEquals(res._obj, orig) self.assertEquals(res._attr, 'bar') self.assertEquals(res, stub(foo.bar)) self.assertEquals(res, getattr(foo, 'bar'))
def test_stub_type_with_obj_ref(self): class Foo(object): def bar(self): pass res = stub(Foo) self.assertTrue(isinstance(res, StubNew)) self.assertEquals(res, Foo.__new__) self.assertEquals(res, stub(Foo)) # test that __init__ called only once res.expect() self.assertEquals(1, len(res._expectations)) res = stub(Foo) self.assertEquals(1, len(res._expectations))
def test_stub_property_with_obj_ref_for_the_deleter(self): class Foo(object): @property def prop(self): return 3 res = stub(Foo.prop.deleter) self.assertTrue(isinstance(res, StubMethod)) self.assertTrue(isinstance(Foo.prop, StubProperty))
def test_stub_module_function_with_attr_name(self): res = stub(samples, 'mod_func_1') self.assertTrue( isinstance(res,StubFunction) ) self.assertEquals( res, getattr(samples,'mod_func_1') ) self.assertEquals( res, stub(samples,'mod_func_1') )