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
+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