##// END OF EJS Templates
tests: self.fail is better written as pytest.fail now
domruf -
r5723:1883a4e4 default
parent child Browse files
Show More
@@ -196,7 +196,7 b' class BaseTestController(object):'
196 'password': password})
196 'password': password})
197
197
198 if 'Invalid username or password' in response.body:
198 if 'Invalid username or password' in response.body:
199 self.fail('could not login using %s %s' % (username, password))
199 pytest.fail('could not login using %s %s' % (username, password))
200
200
201 self.assertEqual(response.status, '302 Found')
201 self.assertEqual(response.status, '302 Found')
202 self.assert_authenticated_user(response, username)
202 self.assert_authenticated_user(response, username)
@@ -219,14 +219,14 b' class BaseTestController(object):'
219
219
220 def checkSessionFlash(self, response, msg=None, skip=0, _matcher=lambda msg, m: msg in m):
220 def checkSessionFlash(self, response, msg=None, skip=0, _matcher=lambda msg, m: msg in m):
221 if 'flash' not in response.session:
221 if 'flash' not in response.session:
222 self.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
222 pytest.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
223 try:
223 try:
224 level, m = response.session['flash'][-1 - skip]
224 level, m = response.session['flash'][-1 - skip]
225 if _matcher(msg, m):
225 if _matcher(msg, m):
226 return
226 return
227 except IndexError:
227 except IndexError:
228 pass
228 pass
229 self.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
229 pytest.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
230 (msg, skip,
230 (msg, skip,
231 ', '.join('`%s`' % m for level, m in response.session['flash']))))
231 ', '.join('`%s`' % m for level, m in response.session['flash']))))
232
232
@@ -82,7 +82,7 b' class _BaseTest(object):'
82 try:
82 try:
83 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
83 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
84 except vcs.exceptions.VCSError:
84 except vcs.exceptions.VCSError:
85 self.fail('no repo %s in filesystem' % repo_name)
85 pytest.fail('no repo %s in filesystem' % repo_name)
86
86
87 RepoModel().delete(repo_name)
87 RepoModel().delete(repo_name)
88 Session().commit()
88 Session().commit()
@@ -136,7 +136,7 b' class _BaseTest(object):'
136 except vcs.exceptions.VCSError:
136 except vcs.exceptions.VCSError:
137 RepoGroupModel().delete(group_name)
137 RepoGroupModel().delete(group_name)
138 Session().commit()
138 Session().commit()
139 self.fail('no repo %s in filesystem' % repo_name)
139 pytest.fail('no repo %s in filesystem' % repo_name)
140
140
141 RepoModel().delete(repo_name_full)
141 RepoModel().delete(repo_name_full)
142 RepoGroupModel().delete(group_name)
142 RepoGroupModel().delete(group_name)
@@ -228,7 +228,7 b' class _BaseTest(object):'
228 except vcs.exceptions.VCSError:
228 except vcs.exceptions.VCSError:
229 RepoGroupModel().delete(group_name)
229 RepoGroupModel().delete(group_name)
230 Session().commit()
230 Session().commit()
231 self.fail('no repo %s in filesystem' % repo_name)
231 pytest.fail('no repo %s in filesystem' % repo_name)
232
232
233 RepoModel().delete(repo_name_full)
233 RepoModel().delete(repo_name_full)
234 RepoGroupModel().delete(group_name)
234 RepoGroupModel().delete(group_name)
@@ -285,7 +285,7 b' class _BaseTest(object):'
285 except vcs.exceptions.VCSError:
285 except vcs.exceptions.VCSError:
286 RepoGroupModel().delete(group_name)
286 RepoGroupModel().delete(group_name)
287 Session().commit()
287 Session().commit()
288 self.fail('no repo %s in filesystem' % repo_name)
288 pytest.fail('no repo %s in filesystem' % repo_name)
289
289
290 #check if inherited permissiona are applied
290 #check if inherited permissiona are applied
291 inherited_perms = UserRepoToPerm.query() \
291 inherited_perms = UserRepoToPerm.query() \
@@ -360,7 +360,7 b' class _BaseTest(object):'
360 try:
360 try:
361 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
361 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
362 except vcs.exceptions.VCSError:
362 except vcs.exceptions.VCSError:
363 self.fail('no repo %s in filesystem' % repo_name)
363 pytest.fail('no repo %s in filesystem' % repo_name)
364
364
365 response = self.app.post(url('delete_repo', repo_name=repo_name),
365 response = self.app.post(url('delete_repo', repo_name=repo_name),
366 params={'_method': 'delete', '_authentication_token': self.authentication_token()})
366 params={'_method': 'delete', '_authentication_token': self.authentication_token()})
@@ -413,7 +413,7 b' class _BaseTest(object):'
413 try:
413 try:
414 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
414 vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
415 except vcs.exceptions.VCSError:
415 except vcs.exceptions.VCSError:
416 self.fail('no repo %s in filesystem' % repo_name)
416 pytest.fail('no repo %s in filesystem' % repo_name)
417
417
418 response = self.app.post(url('delete_repo', repo_name=repo_name),
418 response = self.app.post(url('delete_repo', repo_name=repo_name),
419 params={'_method': 'delete', '_authentication_token': self.authentication_token()})
419 params={'_method': 'delete', '_authentication_token': self.authentication_token()})
@@ -4,6 +4,9 b' import sys'
4 import mock
4 import mock
5 import datetime
5 import datetime
6 import urllib2
6 import urllib2
7
8 import pytest
9
7 from kallithea.lib.vcs.backends.git import GitRepository, GitChangeset
10 from kallithea.lib.vcs.backends.git import GitRepository, GitChangeset
8 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
11 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
9 from kallithea.lib.vcs.nodes import NodeKind, FileNode, DirNode, NodeState
12 from kallithea.lib.vcs.nodes import NodeKind, FileNode, DirNode, NodeState
@@ -17,7 +20,7 b' class GitRepositoryTest(unittest.TestCas'
17
20
18 def __check_for_existing_repo(self):
21 def __check_for_existing_repo(self):
19 if os.path.exists(TEST_GIT_REPO_CLONE):
22 if os.path.exists(TEST_GIT_REPO_CLONE):
20 self.fail('Cannot test git clone repo as location %s already '
23 pytest.fail('Cannot test git clone repo as location %s already '
21 'exists. You should manually remove it first.'
24 'exists. You should manually remove it first.'
22 % TEST_GIT_REPO_CLONE)
25 % TEST_GIT_REPO_CLONE)
23
26
@@ -339,7 +342,7 b' class GitChangesetTest(unittest.TestCase'
339 idx += 1
342 idx += 1
340 rev_id = self.repo.revisions[rev]
343 rev_id = self.repo.revisions[rev]
341 if idx > limit:
344 if idx > limit:
342 self.fail("Exceeded limit already (getting revision %s, "
345 pytest.fail("Exceeded limit already (getting revision %s, "
343 "there are %s total revisions, offset=%s, limit=%s)"
346 "there are %s total revisions, offset=%s, limit=%s)"
344 % (rev_id, count, offset, limit))
347 % (rev_id, count, offset, limit))
345 self.assertEqual(changeset, self.repo.get_changeset(rev_id))
348 self.assertEqual(changeset, self.repo.get_changeset(rev_id))
@@ -347,7 +350,7 b' class GitChangesetTest(unittest.TestCase'
347 start = offset
350 start = offset
348 end = limit and offset + limit or None
351 end = limit and offset + limit or None
349 sliced = list(self.repo[start:end])
352 sliced = list(self.repo[start:end])
350 self.failUnlessEqual(result, sliced,
353 pytest.failUnlessEqual(result, sliced,
351 msg="Comparison failed for limit=%s, offset=%s"
354 msg="Comparison failed for limit=%s, offset=%s"
352 "(get_changeset returned: %s and sliced: %s"
355 "(get_changeset returned: %s and sliced: %s"
353 % (limit, offset, result, sliced))
356 % (limit, offset, result, sliced))
@@ -1,5 +1,8 b''
1
1
2 import os
2 import os
3
4 import pytest
5
3 from kallithea.lib.utils2 import safe_str
6 from kallithea.lib.utils2 import safe_str
4 from kallithea.lib.vcs.backends.hg import MercurialRepository, MercurialChangeset
7 from kallithea.lib.vcs.backends.hg import MercurialRepository, MercurialChangeset
5 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
8 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
@@ -20,7 +23,7 b' class MercurialRepositoryTest(unittest.T'
20
23
21 def __check_for_existing_repo(self):
24 def __check_for_existing_repo(self):
22 if os.path.exists(TEST_HG_REPO_CLONE):
25 if os.path.exists(TEST_HG_REPO_CLONE):
23 self.fail('Cannot test mercurial clone repo as location %s already '
26 pytest.fail('Cannot test mercurial clone repo as location %s already '
24 'exists. You should manually remove it first.'
27 'exists. You should manually remove it first.'
25 % TEST_HG_REPO_CLONE)
28 % TEST_HG_REPO_CLONE)
26
29
@@ -67,7 +70,7 b' class MercurialRepositoryTest(unittest.T'
67
70
68 def test_pull(self):
71 def test_pull(self):
69 if os.path.exists(TEST_HG_REPO_PULL):
72 if os.path.exists(TEST_HG_REPO_PULL):
70 self.fail('Cannot test mercurial pull command as location %s '
73 pytest.fail('Cannot test mercurial pull command as location %s '
71 'already exists. You should manually remove it first'
74 'already exists. You should manually remove it first'
72 % TEST_HG_REPO_PULL)
75 % TEST_HG_REPO_PULL)
73 repo_new = MercurialRepository(TEST_HG_REPO_PULL, create=True)
76 repo_new = MercurialRepository(TEST_HG_REPO_PULL, create=True)
@@ -76,7 +76,7 b' class NodeBasicTest(unittest.TestCase):'
76 '''
76 '''
77 def _test_trailing_slash(self, path):
77 def _test_trailing_slash(self, path):
78 if not path.endswith('/'):
78 if not path.endswith('/'):
79 self.fail("Trailing slash tests needs paths to end with slash")
79 pytest.fail("Trailing slash tests needs paths to end with slash")
80 for kind in NodeKind.FILE, NodeKind.DIR:
80 for kind in NodeKind.FILE, NodeKind.DIR:
81 self.assertRaises(NodeError, Node, path=path, kind=kind)
81 self.assertRaises(NodeError, Node, path=path, kind=kind)
82
82
General Comments 0
You need to be logged in to leave comments. Login now