Restore measure of test coverage

This commit is contained in:
Vincent Jacques
2012-10-28 15:53:03 +01:00
parent 1867f461ed
commit ca1e799826
12 changed files with 101 additions and 55 deletions
+28 -28
View File
@@ -59,17 +59,17 @@ def convertUser(attributes):
"login": attributes["login"],
"url": "/users/" + attributes["login"],
}
if "gravatar_id" in attributes:
if "gravatar_id" in attributes: # pragma no branch
convertedAttributes["gravatar_id"] = attributes["gravatar_id"]
if "followers" in attributes:
if "followers" in attributes: # pragma no branch
convertedAttributes["followers"] = attributes["followers"]
if "repos" in attributes:
if "repos" in attributes: # pragma no branch
convertedAttributes["public_repos"] = attributes["repos"]
if "name" in attributes:
if "name" in attributes: # pragma no branch
convertedAttributes["name"] = attributes["name"]
if "created_at" in attributes:
if "created_at" in attributes: # pragma no branch
convertedAttributes["created_at"] = attributes["created_at"]
if "location" in attributes:
if "location" in attributes: # pragma no branch
convertedAttributes["location"] = attributes["location"]
return convertedAttributes
@@ -79,35 +79,35 @@ def convertRepo(attributes):
"owner": {"login": attributes["owner"], "url": "/users/" + attributes["owner"]},
"url": "/repos/" + attributes["owner"] + "/" + attributes["name"],
}
if "pushed_at" in attributes:
if "pushed_at" in attributes: # pragma no branch
convertedAttributes["pushed_at"] = attributes["pushed_at"]
if "homepage" in attributes:
if "homepage" in attributes: # pragma no branch
convertedAttributes["homepage"] = attributes["homepage"]
if "created_at" in attributes:
if "created_at" in attributes: # pragma no branch
convertedAttributes["created_at"] = attributes["created_at"]
if "watchers" in attributes:
if "watchers" in attributes: # pragma no branch
convertedAttributes["watchers"] = attributes["watchers"]
if "has_downloads" in attributes:
if "has_downloads" in attributes: # pragma no branch
convertedAttributes["has_downloads"] = attributes["has_downloads"]
if "fork" in attributes:
if "fork" in attributes: # pragma no branch
convertedAttributes["fork"] = attributes["fork"]
if "has_issues" in attributes:
if "has_issues" in attributes: # pragma no branch
convertedAttributes["has_issues"] = attributes["has_issues"]
if "has_wiki" in attributes:
if "has_wiki" in attributes: # pragma no branch
convertedAttributes["has_wiki"] = attributes["has_wiki"]
if "forks" in attributes:
if "forks" in attributes: # pragma no branch
convertedAttributes["forks"] = attributes["forks"]
if "size" in attributes:
if "size" in attributes: # pragma no branch
convertedAttributes["size"] = attributes["size"]
if "private" in attributes:
if "private" in attributes: # pragma no branch
convertedAttributes["private"] = attributes["private"]
if "open_issues" in attributes:
if "open_issues" in attributes: # pragma no branch
convertedAttributes["open_issues"] = attributes["open_issues"]
if "description" in attributes:
if "description" in attributes: # pragma no branch
convertedAttributes["description"] = attributes["description"]
if "language" in attributes:
if "language" in attributes: # pragma no branch
convertedAttributes["language"] = attributes["language"]
if "name" in attributes:
if "name" in attributes: # pragma no branch
convertedAttributes["name"] = attributes["name"]
return convertedAttributes
@@ -118,18 +118,18 @@ def convertIssue(attributes):
"url": "/repos" + urlparse.urlparse(attributes["html_url"]).path,
"user": {"login": attributes["user"], "url": "/users/" + attributes["user"]},
}
if "labels" in attributes:
if "labels" in attributes: # pragma no branch
convertedAttributes["labels"] = [{"name": label} for label in attributes["labels"]]
if "title" in attributes:
if "title" in attributes: # pragma no branch
convertedAttributes["title"] = attributes["title"]
if "created_at" in attributes:
if "created_at" in attributes: # pragma no branch
convertedAttributes["created_at"] = attributes["created_at"]
if "comments" in attributes:
if "comments" in attributes: # pragma no branch
convertedAttributes["comments"] = attributes["comments"]
if "body" in attributes:
if "body" in attributes: # pragma no branch
convertedAttributes["body"] = attributes["body"]
if "updated_at" in attributes:
if "updated_at" in attributes: # pragma no branch
convertedAttributes["updated_at"] = attributes["updated_at"]
if "state" in attributes:
if "state" in attributes: # pragma no branch
convertedAttributes["state"] = attributes["state"]
return convertedAttributes
+1 -1
View File
@@ -122,7 +122,7 @@ class Requester:
requestHeaders["Authorization"] = "Basic (login and password removed)"
elif requestHeaders["Authorization"].startswith("token"):
requestHeaders["Authorization"] = "token (oauth token removed)"
else:
else: # pragma no cover
requestHeaders["Authorization"] = "Unknown authorization removed"
logger.debug("%s %s://%s%s %s %s ==> %i %s %s", str(verb), self.__scheme, self.__hostname, str(url), str(requestHeaders), str(input), status, str(responseHeaders), str(output))
+1 -1
View File
@@ -20,7 +20,7 @@ from InputGitAuthor import InputGitAuthor
from InputGitTreeElement import InputGitTreeElement
def enable_console_debug_logging():
def enable_console_debug_logging(): # pragma no cover
logger = logging.getLogger("github")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
+16 -8
View File
@@ -21,10 +21,11 @@ atLeastPython26 = sys.hexversion >= 0x02060000
class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument
def testInvalidInput(self):
raised = False
try:
self.g.get_user().create_key("Bad key", "xxx")
self.fail("Should have raised")
except github.GithubException, exception:
raised = True
self.assertEqual(exception.status, 422)
self.assertEqual(
exception.data,
@@ -43,40 +44,47 @@ class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we
if atLeastPython26:
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\'}]}")
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
self.assertTrue(raised)
def testUnknownObject(self):
raised = False
try:
self.g.get_user().get_repo("Xxx")
self.fail("Should have raised")
except github.GithubException, exception:
raised = True
self.assertEqual(exception.status, 404)
self.assertEqual(exception.data, {"message": "Not Found"})
if atLeastPython26:
self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
else:
self.assertEqual(str(exception), "404 {'message': 'Not Found'}")
self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover
self.assertTrue(raised)
def testUnknownUser(self):
raised = False
try:
self.g.get_user("ThisUserShouldReallyNotExist")
self.fail("Should have raised")
except github.GithubException, exception:
raised = True
self.assertEqual(exception.status, 404)
self.assertEqual(exception.data, {"message": "Not Found"})
if atLeastPython26:
self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
else:
self.assertEqual(str(exception), "404 {'message': 'Not Found'}")
self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover
self.assertTrue(raised)
def testBadAuthentication(self):
raised = False
try:
github.Github("BadUser", "BadPassword").get_user().login
self.fail("Should have raised")
except github.GithubException, exception:
raised = True
self.assertEqual(exception.status, 401)
self.assertEqual(exception.data, {"message": "Bad credentials"})
if atLeastPython26:
self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}")
else:
self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}")
self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover
self.assertTrue(raised)
+7 -7
View File
@@ -39,11 +39,11 @@ def fixAuthorizationHeader(headers):
headers["Authorization"] = "token private_token_removed"
elif headers["Authorization"].startswith("Basic "):
headers["Authorization"] = "Basic login_and_password_removed"
else:
else: # pragma no cover
assert False
class RecordingConnection:
class RecordingConnection: # pragma no cover
def __init__(self, file, protocol, host, port, *args, **kwds):
self.__file = file
self.__protocol = protocol
@@ -76,14 +76,14 @@ class RecordingConnection:
return self.__cnx.close()
class RecordingHttpConnection(RecordingConnection):
class RecordingHttpConnection(RecordingConnection): # pragma no cover
_realConnection = httplib.HTTPConnection
def __init__(self, file, *args, **kwds):
RecordingConnection.__init__(self, file, "http", *args, **kwds)
class RecordingHttpsConnection(RecordingConnection):
class RecordingHttpsConnection(RecordingConnection): # pragma no cover
_realConnection = httplib.HTTPSConnection
def __init__(self, file, *args, **kwds):
@@ -130,7 +130,7 @@ class BasicTestCase(unittest.TestCase):
unittest.TestCase.setUp(self)
self.__fileName = ""
self.__file = None
if self.recordMode:
if self.recordMode: # pragma no cover
github.Requester.Requester.injectConnectionClasses(
lambda ignored, *args, **kwds: RecordingHttpConnection(self.__openFile("wb"), *args, **kwds),
lambda ignored, *args, **kwds: RecordingHttpsConnection(self.__openFile("wb"), *args, **kwds)
@@ -165,7 +165,7 @@ class BasicTestCase(unittest.TestCase):
def __closeReplayFileIfNeeded(self):
if self.__file is not None:
if not self.recordMode:
if not self.recordMode: # pragma no branch
self.assertEqual(self.__file.readline(), "")
self.__file.close()
@@ -184,5 +184,5 @@ class TestCase(BasicTestCase):
self.g = github.Github(self.login, self.password)
def activateRecordMode():
def activateRecordMode(): # pragma no cover
BasicTestCase.recordMode = True
+1 -1
View File
@@ -95,6 +95,6 @@ class Issue(Framework.TestCase):
question = self.repo.get_label("Question")
self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Project management", "Question"])
self.issue.delete_labels()
self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, [])
self.assertListKeyEqual(self.issue.get_labels(), None, [])
self.issue.set_labels(bug, question)
self.assertListKeyEqual(self.issue.get_labels(), lambda l: l.name, ["Bug", "Question"])
+2 -2
View File
@@ -66,7 +66,7 @@ class PaginatedList(Framework.TestCase):
def testInterruptedIteration(self):
# No asserts, but checks that only three pages are fetched
l = 0
for element in self.list:
for element in self.list: # pragma no branch (exits only by break)
l += 1
if l == 75:
break
@@ -74,7 +74,7 @@ class PaginatedList(Framework.TestCase):
def testInterruptedIterationInSlice(self):
# No asserts, but checks that only three pages are fetched
l = 0
for element in self.list[:100]:
for element in self.list[:100]: # pragma no branch (exits only by break)
l += 1
if l == 75:
break
+3 -1
View File
@@ -409,9 +409,11 @@ class Repository(Framework.TestCase):
self.assertEqual(commit, None)
def testMergeWithConflict(self):
raised = False
try:
commit = self.repo.merge("branchForBase", "branchForHead")
self.fail("Should have raised")
except github.GithubException, exception:
raised = True
self.assertEqual(exception.status, 409)
self.assertEqual(exception.data, {"message": "Merge conflict"})
self.assertTrue(raised)
+4 -4
View File
@@ -30,24 +30,24 @@ class Team(Framework.TestCase):
def testMembers(self):
user = self.g.get_user("jacquev6")
self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, [])
self.assertListKeyEqual(self.team.get_members(), None, [])
self.assertFalse(self.team.has_in_members(user))
self.team.add_to_members(user)
self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, ["jacquev6"])
self.assertTrue(self.team.has_in_members(user))
self.team.remove_from_members(user)
self.assertListKeyEqual(self.team.get_members(), lambda u: u.login, [])
self.assertListKeyEqual(self.team.get_members(), None, [])
self.assertFalse(self.team.has_in_members(user))
def testRepos(self):
repo = self.org.get_repo("FatherBeaver")
self.assertListKeyEqual(self.team.get_repos(), lambda r: r.name, [])
self.assertListKeyEqual(self.team.get_repos(), None, [])
self.assertFalse(self.team.has_in_repos(repo))
self.team.add_to_repos(repo)
self.assertListKeyEqual(self.team.get_repos(), lambda r: r.name, ["FatherBeaver"])
self.assertTrue(self.team.has_in_repos(repo))
self.team.remove_from_repos(repo)
self.assertListKeyEqual(self.team.get_repos(), lambda r: r.name, [])
self.assertListKeyEqual(self.team.get_repos(), None, [])
self.assertFalse(self.team.has_in_repos(repo))
def testEditWithoutArguments(self):
+1 -1
View File
@@ -17,4 +17,4 @@ import AllTests
def run():
unittest.main(module=AllTests, argv=["Dummy Script Name"])
return unittest.main(module=AllTests, argv=["Dummy Script Name"], exit=False).result
+13
View File
@@ -1,3 +1,16 @@
# Copyright 2012 Vincent Jacques
# vincent@vincent-jacques.net
# This file is part of PyGithub. http://vincent-jacques.net/PyGithub
# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see <http://www.gnu.org/licenses/>.
import sys
import unittest