From 1c47be4e895b823baf907b25c647e43ab63c16dd Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 28 Mar 2013 21:50:17 +0100 Subject: [PATCH] Document `#pragma no cover`s (Issue #154) --- github/Requester.py | 14 +++++++------- github/__init__.py | 2 +- github/tests/ContentFile.py | 2 +- github/tests/Exceptions.py | 6 +++--- github/tests/Framework.py | 16 ++++++++-------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/github/Requester.py b/github/Requester.py index 81de4c3c..eacda7ab 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -25,8 +25,8 @@ atLeastPython3 = sys.hexversion >= 0x03000000 if atLeastPython26: import json -else: # pragma no cover - import simplejson as json # pragma no cover +else: # pragma no cover (Covered by all tests with Python 2.5) + import simplejson as json # pragma no cover (Covered by all tests with Python 2.5) import GithubException @@ -49,7 +49,7 @@ class Requester: if password is not None: login = login_or_token if atLeastPython3: - self.__authorizationHeader = "Basic " + base64.b64encode((login + ":" + password).encode("utf-8")).decode("utf-8").replace('\n', '') # pragma no cover + self.__authorizationHeader = "Basic " + base64.b64encode((login + ":" + password).encode("utf-8")).decode("utf-8").replace('\n', '') # pragma no cover (Covered by Authentication.testAuthorizationHeaderWithXxx with Python 3) else: self.__authorizationHeader = "Basic " + base64.b64encode(login + ":" + password).replace('\n', '') elif login_or_token is not None: @@ -97,8 +97,8 @@ class Requester: if len(data) == 0: return None else: - if atLeastPython3 and isinstance(data, bytes): # pragma no branch - data = data.decode("utf-8") # pragma no cover + if atLeastPython3 and isinstance(data, bytes): # pragma no branch (Covered by Issue142.testDecodeJson with Python 3) + data = data.decode("utf-8") # pragma no cover (Covered by Issue142.testDecodeJson with Python 3) return json.loads(data) def requestJson(self, verb, url, parameters, input): @@ -201,9 +201,9 @@ class Requester: def __createConnection(self): kwds = {} - if not atLeastPython3: # pragma no branch + if not atLeastPython3: # pragma no branch (Branch useful only with Python 3) kwds["strict"] = True # Useless in Python3, would generate a deprecation warning - if atLeastPython26: # pragma no branch + if atLeastPython26: # pragma no branch (Branch useful only with Python 2.5) kwds["timeout"] = self.__timeout # Did not exist before Python2.6 return self.__connectionClass(host=self.__hostname, port=self.__port, **kwds) diff --git a/github/__init__.py b/github/__init__.py index 3f20d650..3e8deb3f 100644 --- a/github/__init__.py +++ b/github/__init__.py @@ -30,7 +30,7 @@ from InputGitAuthor import InputGitAuthor from InputGitTreeElement import InputGitTreeElement -def enable_console_debug_logging(): # pragma no cover +def enable_console_debug_logging(): # pragma no cover (Function useful only outside test environment) """ This function sets up a very simple logging configuration (log everything on standard output) that is useful for troubleshooting. """ diff --git a/github/tests/ContentFile.py b/github/tests/ContentFile.py index ba88872f..3323c4a6 100644 --- a/github/tests/ContentFile.py +++ b/github/tests/ContentFile.py @@ -36,7 +36,7 @@ class ContentFile(Framework.TestCase): self.assertEqual(self.file.name, "ReadMe.md") self.assertEqual(self.file.path, "ReadMe.md") if atLeastPython3: - self.assertEqual(len(base64.b64decode(bytearray(self.file.content, "utf-8"))), 7531) # pragma no cover + self.assertEqual(len(base64.b64decode(bytearray(self.file.content, "utf-8"))), 7531) # pragma no cover (Covered with Python 3) else: self.assertEqual(len(base64.b64decode(self.file.content)), 7531) self.assertEqual(self.file.sha, "5628799a7d517a4aaa0c1a7004d07569cd154df0") diff --git a/github/tests/Exceptions.py b/github/tests/Exceptions.py index c068122f..eded7944 100644 --- a/github/tests/Exceptions.py +++ b/github/tests/Exceptions.py @@ -57,7 +57,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we 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 + self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) self.assertTrue(raised) def testUnknownUser(self): @@ -71,7 +71,7 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we 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 + self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) self.assertTrue(raised) def testBadAuthentication(self): @@ -85,5 +85,5 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we 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 + self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover (Covered with Python 3) self.assertTrue(raised) diff --git a/github/tests/Framework.py b/github/tests/Framework.py index 931088e6..a766fa3b 100644 --- a/github/tests/Framework.py +++ b/github/tests/Framework.py @@ -27,8 +27,8 @@ atMostPython32 = sys.hexversion < 0x03030000 if atLeastPython26: import json -else: # pragma no cover - import simplejson as json # pragma no cover +else: # pragma no cover (Covered by all tests with Python 2.5) + import simplejson as json # pragma no cover (Covered by all tests with Python 2.5) def readLine(file): @@ -65,7 +65,7 @@ def fixAuthorizationHeader(headers): headers["Authorization"] = "Basic login_and_password_removed" -class RecordingConnection: # pragma no cover +class RecordingConnection: # pragma no cover (Class useful only when recording new tests, not used during automated tests) def __init__(self, file, protocol, host, port, *args, **kwds): self.__file = file self.__protocol = protocol @@ -107,14 +107,14 @@ class RecordingConnection: # pragma no cover self.__file.write(line + "\n") -class RecordingHttpConnection(RecordingConnection): # pragma no cover +class RecordingHttpConnection(RecordingConnection): # pragma no cover (Class useful only when recording new tests, not used during automated tests) _realConnection = httplib.HTTPConnection def __init__(self, file, *args, **kwds): RecordingConnection.__init__(self, file, "http", *args, **kwds) -class RecordingHttpsConnection(RecordingConnection): # pragma no cover +class RecordingHttpsConnection(RecordingConnection): # pragma no cover (Class useful only when recording new tests, not used during automated tests) _realConnection = httplib.HTTPSConnection def __init__(self, file, *args, **kwds): @@ -179,7 +179,7 @@ class BasicTestCase(unittest.TestCase): unittest.TestCase.setUp(self) self.__fileName = "" self.__file = None - if self.recordMode: # pragma no cover + if self.recordMode: # pragma no cover (Branch useful only when recording new tests, not used during automated tests) github.Requester.Requester.injectConnectionClasses( lambda ignored, *args, **kwds: RecordingHttpConnection(self.__openFile("wb"), *args, **kwds), lambda ignored, *args, **kwds: RecordingHttpsConnection(self.__openFile("wb"), *args, **kwds) @@ -220,7 +220,7 @@ class BasicTestCase(unittest.TestCase): def __closeReplayFileIfNeeded(self): if self.__file is not None: - if not self.recordMode: # pragma no branch + if not self.recordMode: # pragma no branch (Branch useful only when recording new tests, not used during automated tests) self.assertEqual(readLine(self.__file), "") self.__file.close() @@ -239,5 +239,5 @@ class TestCase(BasicTestCase): self.g = github.Github(self.login, self.password) -def activateRecordMode(): # pragma no cover +def activateRecordMode(): # pragma no cover (Function useful only when recording new tests, not used during automated tests) BasicTestCase.recordMode = True