Restore compatibility with Python 2.6

Remove:
- dict comprehensions
- unittest.TestCase.assertRaises with only one argument
This commit is contained in:
Vincent Jacques
2012-06-01 19:05:02 +01:00
parent 9954a3fd1b
commit b3fce397c0
5 changed files with 27 additions and 25 deletions
@@ -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()
}
)
+1 -1
View File
@@ -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
+4 -4
View File
@@ -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 )
+1 -1
View File
@@ -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
+18 -16
View File
@@ -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"
}
)