From b3fce397c053900384df20e863fb89ea09d79c4a Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Fri, 1 Jun 2012 19:05:02 +0100 Subject: [PATCH] Restore compatibility with Python 2.6 Remove: - dict comprehensions - unittest.TestCase.assertRaises with only one argument --- ...ithubObject.AttributeValue.complex.dict.py | 6 ++-- src/github/AuthenticatedUser.py | 2 +- src/github/Gist.py | 8 ++--- src/github/NamedUser.py | 2 +- test/Exceptions.py | 34 ++++++++++--------- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/codegen/templates/GithubObject.AttributeValue.complex.dict.py b/codegen/templates/GithubObject.AttributeValue.complex.dict.py index f0992386..7babe871 100644 --- a/codegen/templates/GithubObject.AttributeValue.complex.dict.py +++ b/codegen/templates/GithubObject.AttributeValue.complex.dict.py @@ -1,4 +1,4 @@ -{ - key : {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) +dict( + ( key, {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self._requester, element, completed = False ) ) for key, element in attributes[ "{{ attribute.name }}" ].iteritems() - } \ No newline at end of file + ) \ No newline at end of file diff --git a/src/github/AuthenticatedUser.py b/src/github/AuthenticatedUser.py index 504c083d..a08afbc7 100644 --- a/src/github/AuthenticatedUser.py +++ b/src/github/AuthenticatedUser.py @@ -209,7 +209,7 @@ class AuthenticatedUser( GithubObject.GithubObject ): assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description post_parameters = { "public": public, - "files": { key : value._identity() for key, value in files.iteritems() }, + "files": dict( ( key, value._identity() ) for key, value in files.iteritems() ), } if description is not GithubObject.NotSet: post_parameters[ "description" ] = description diff --git a/src/github/Gist.py b/src/github/Gist.py index f256ae23..ca749781 100644 --- a/src/github/Gist.py +++ b/src/github/Gist.py @@ -127,7 +127,7 @@ class Gist( GithubObject.GithubObject ): if description is not GithubObject.NotSet: post_parameters[ "description" ] = description if files is not GithubObject.NotSet: - post_parameters[ "files" ] = { key : value._identity() for key, value in files.iteritems() } + post_parameters[ "files" ] = dict( ( key, value._identity() ) for key, value in files.iteritems() ) status, headers, data = self._request( "PATCH", str( self.url ), @@ -219,10 +219,10 @@ class Gist( GithubObject.GithubObject ): self._description = attributes[ "description" ] if "files" in attributes: # pragma no branch assert attributes[ "files" ] is None or all( isinstance( element, dict ) for element in attributes[ "files" ].itervalues() ), attributes[ "files" ] - self._files = None if attributes[ "files" ] is None else { - key : GistFile.GistFile( self._requester, element, completed = False ) + self._files = None if attributes[ "files" ] is None else dict( + ( key, GistFile.GistFile( self._requester, element, completed = False ) ) for key, element in attributes[ "files" ].iteritems() - } + ) if "fork_of" in attributes: # pragma no branch assert attributes[ "fork_of" ] is None or isinstance( attributes[ "fork_of" ], dict ), attributes[ "fork_of" ] self._fork_of = None if attributes[ "fork_of" ] is None else Gist( self._requester, attributes[ "fork_of" ], completed = False ) diff --git a/src/github/NamedUser.py b/src/github/NamedUser.py index bf864c29..ff3592d4 100644 --- a/src/github/NamedUser.py +++ b/src/github/NamedUser.py @@ -149,7 +149,7 @@ class NamedUser( GithubObject.GithubObject ): assert description is GithubObject.NotSet or isinstance( description, ( str, unicode ) ), description post_parameters = { "public": public, - "files": { key : value._identity() for key, value in files.iteritems() }, + "files": dict( ( key, value._identity() ) for key, value in files.iteritems() ), } if description is not GithubObject.NotSet: post_parameters[ "description" ] = description diff --git a/test/Exceptions.py b/test/Exceptions.py index 0f83c9d8..c4d08673 100644 --- a/test/Exceptions.py +++ b/test/Exceptions.py @@ -4,20 +4,22 @@ import Framework class Exceptions( Framework.TestCase ): def testInvalidInput( self ): - with self.assertRaises( github.GithubException ) as cm: + try: # Stay compatible with Python 2.6: do not use self.assertRaises with only one argument self.g.get_user().create_key( "Bad key", "xxx" ) - self.assertEqual( cm.exception.status, 422 ) - self.assertEqual( - cm.exception.data, - { - "errors": [ - { - "code": "custom", - "field": "key", - "message": "key is invalid. It must begin with 'ssh-rsa' or 'ssh-dss'. Check that you're copying the public half of the key", - "resource": "PublicKey" - } - ], - "message": "Validation Failed" - } - ) + self.fail( "Should have raised" ) + except github.GithubException, exception: + self.assertEqual( exception.status, 422 ) + self.assertEqual( + exception.data, + { + "errors": [ + { + "code": "custom", + "field": "key", + "message": "key is invalid. It must begin with 'ssh-rsa' or 'ssh-dss'. Check that you're copying the public half of the key", + "resource": "PublicKey" + } + ], + "message": "Validation Failed" + } + )