diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 61114fee..0dc91eb2 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -237,4 +237,21 @@ class GithubObjectWithModifiableListOfReferences( TestCaseWithGithubTestObject ) self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 404 ) self.assertFalse( self.o.has_in_a3s( a3ToQuery ) ) +def myCallable( obj, mock, arg ): + return mock.call( arg ) + +class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ): + GithubTestObject = GithubObject( + "GithubTestObject", + BaseUrl( lambda obj: "/test" ), + BasicAttributes( "a1", "a2" ), + MethodFromCallable( "myMethod", myCallable ) + ) + + def testCallMethod( self ): + mock = MockMockMock.Mock( "myCallable" ) + mock.expect.call( 42 ).andReturn( 72 ) + self.assertEqual( self.o.myMethod( mock.object, 42 ), 72 ) + mock.tearDown() + unittest.main() diff --git a/github/GithubObject.py b/github/GithubObject.py index 076f05ad..6d5263a5 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -9,8 +9,6 @@ class BasicAttributes: self.__attributeNames = attributeNames def getValueFromRawValue( self, obj, rawValue ): - # if isinstance( rawValue, dict ): - # print rawValue, "is a dict, you may want to use an extended attribute for it" return rawValue def updateAttributes( self, obj ): @@ -149,6 +147,14 @@ class Deletable: def __execute( self, obj, *args, **kwds ): obj._github._statusRequest( "DELETE", obj._baseUrl ) +class MethodFromCallable: + def __init__( self, name, callable ): + self.__name = name + self.__callable = callable + + def apply( self, cls ): + cls._addMethod( self.__name, self.__callable ) + def GithubObject( className, *attributePolicies ): class GithubObject: __attributeDefinitions = dict()