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()
Пример #2
0
 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()
Пример #3
0
  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'))
Пример #4
0
  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) )
Пример #5
0
  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)
Пример #6
0
  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)
Пример #7
0
  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)
Пример #8
0
  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_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)
Пример #10
0
    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)
Пример #11
0
    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__'))
Пример #12
0
    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)
Пример #13
0
    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'))
Пример #14
0
  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'))
Пример #15
0
    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'))
Пример #16
0
  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))
Пример #17
0
    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'))
Пример #18
0
    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))
Пример #19
0
  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'))
Пример #20
0
    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'))
Пример #21
0
  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))
Пример #22
0
    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))
Пример #23
0
  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))
Пример #24
0
    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))
Пример #25
0
 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') )