From d8e50c7937db9a1deb35bd031ece37c73283b3a9 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 21 Nov 2012 20:30:35 +0100 Subject: [PATCH] Small fixes => tests pass after 2to3 --- github/Requester.py | 2 +- github/tests/ContentFile.py | 2 +- github/tests/Exceptions.py | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/github/Requester.py b/github/Requester.py index 26d28f51..75bc918e 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -42,7 +42,7 @@ class Requester: def __init__(self, login_or_token, password, base_url, timeout, client_id, client_secret, user_agent): if password is not None: login = login_or_token - self.__authorizationHeader = "Basic " + base64.b64encode(login + ":" + password).replace('\n', '') + self.__authorizationHeader = "Basic " + str(base64.b64encode(bytearray(login + ":" + password, "utf-8"))).replace('\n', '') elif login_or_token is not None: token = login_or_token self.__authorizationHeader = "token " + token diff --git a/github/tests/ContentFile.py b/github/tests/ContentFile.py index 21b85ec0..0d2ae6a7 100644 --- a/github/tests/ContentFile.py +++ b/github/tests/ContentFile.py @@ -32,5 +32,5 @@ class ContentFile(Framework.TestCase): self.assertEqual(self.file.size, 7531) self.assertEqual(self.file.name, "ReadMe.md") self.assertEqual(self.file.path, "ReadMe.md") - self.assertEqual(len(base64.b64decode(self.file.content)), 7531) + self.assertEqual(len(base64.b64decode(bytearray(self.file.content, "utf-8"))), 7531) self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0") diff --git a/github/tests/Exceptions.py b/github/tests/Exceptions.py index c1a51f12..ddbdbd1d 100644 --- a/github/tests/Exceptions.py +++ b/github/tests/Exceptions.py @@ -19,6 +19,7 @@ import sys import Framework atLeastPython26 = sys.hexversion >= 0x02060000 +atMostPython2 = sys.hexversion < 0x03000000 class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument @@ -43,7 +44,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we "message": "Validation Failed" } ) - if atLeastPython26: + if atLeastPython26 and atMostPython2: self.assertEqual(str(exception), "422 {u\'message\': u\'Validation Failed\', u\'errors\': [{u\'field\': u\'key\', u\'message\': u\"key is invalid. It must begin with \'ssh-rsa\' or \'ssh-dss\'. Check that you\'re copying the public half of the key\", u\'code\': u\'custom\', u\'resource\': u\'PublicKey\'}]}") else: self.assertEqual(str(exception), "422 {\'message\': \'Validation Failed\', \'errors\': [{\'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\", \'code\': \'custom\', \'resource\': \'PublicKey\'}]}") # pragma no cover @@ -57,7 +58,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 404) self.assertEqual(exception.data, {"message": "Not Found"}) - if atLeastPython26: + if atLeastPython26 and atMostPython2: self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") else: self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover @@ -71,7 +72,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 404) self.assertEqual(exception.data, {"message": "Not Found"}) - if atLeastPython26: + if atLeastPython26 and atMostPython2: self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") else: self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover @@ -85,7 +86,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we raised = True self.assertEqual(exception.status, 401) self.assertEqual(exception.data, {"message": "Bad credentials"}) - if atLeastPython26: + if atLeastPython26 and atMostPython2: self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}") else: self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover