Ejemplo n.º 1
0
    def test_nested_apiclassmethod_funcname(self):
        """
        Tests that a nested _apiclassmethod appropriately
        returns the function name
        """
        class MyClass(object):
            @_apiclassmethod
            @_apiclassmethod
            def fake(cls, first, second):
                return cls, first, second
        self.assertEqual(MyClass.fake.__name__, 'fake')

        class OtherClass(object):
            def fake2(cls, req):
                return cls, req
        method = _apiclassmethod(OtherClass.fake2)
        method = _apiclassmethod(method)
        self.assertEqual(method.__name__, 'fake2')

        # Python 3 compatibility
        if hasattr(method, 'func_name'):
            self.assertEqual(method.__name__, method.func_name)
Ejemplo n.º 2
0
    def test_nested_apiclassmethod_funcname(self):
        """
        Tests that a nested _apiclassmethod appropriately
        returns the function name
        """
        class MyClass(object):
            @_apiclassmethod
            @_apiclassmethod
            def fake(cls, first, second):
                return cls, first, second
        self.assertEqual(MyClass.fake.__name__, 'fake')

        class OtherClass(object):
            def fake2(cls, req):
                return cls, req
        method = _apiclassmethod(OtherClass.fake2)
        method = _apiclassmethod(method)
        self.assertEqual(method.__name__, 'fake2')

        # Python 3 compatibility
        if hasattr(method, 'func_name'):
            self.assertEqual(method.__name__, method.func_name)
Ejemplo n.º 3
0
    def test_apiclassmethod_getter(self):
        """
        Tests the __get__ method on the
        apiclassmethod class.
        """
        mck = mock.Mock(return_value='HEY', __name__=str('blah'), func_dict=dict())
        clsmethod = _apiclassmethod(mck)
        resp = clsmethod.__get__(1)
        func_resp = resp()
        self.assertEqual(mck.call_count, 1)
        self.assertEqual(mck.call_args_list[0][0][0], int)

        resp = clsmethod.__get__('string')
        func_resp = resp('string')
        self.assertEqual(mck.call_args_list[1][0][0], six.text_type)
        self.assertEqual(mck.call_args_list[1][0][1], 'string')

        func_resp = resp(str)
        self.assertEqual(mck.call_args_list[2][0][0], str)
Ejemplo n.º 4
0
    def test_apiclassmethod_getter(self):
        """
        Tests the __get__ method on the
        apiclassmethod class.
        """
        mck = mock.Mock(return_value='HEY', __name__=str('blah'), func_dict=dict())
        clsmethod = _apiclassmethod(mck)
        resp = clsmethod.__get__(1)
        func_resp = resp()
        self.assertEqual(mck.call_count, 1)
        self.assertEqual(mck.call_args_list[0][0][0], int)

        resp = clsmethod.__get__('string')
        func_resp = resp('string')
        self.assertEqual(mck.call_args_list[1][0][0], six.text_type)
        self.assertEqual(mck.call_args_list[1][0][1], 'string')

        func_resp = resp(str)
        self.assertEqual(mck.call_args_list[2][0][0], str)