changeset 5751:1883a4e4c390

tests: self.fail is better written as pytest.fail now
author domruf <dominikruf@gmail.com>
date Mon, 29 Feb 2016 22:06:40 +0100
parents b45fb7a3d03b
children 8568a1d4f100
files kallithea/tests/__init__.py kallithea/tests/functional/test_admin_repos.py kallithea/tests/vcs/test_git.py kallithea/tests/vcs/test_hg.py kallithea/tests/vcs/test_nodes.py
diffstat 5 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/__init__.py	Tue Mar 08 15:50:54 2016 +0100
+++ b/kallithea/tests/__init__.py	Mon Feb 29 22:06:40 2016 +0100
@@ -196,7 +196,7 @@
                                   'password': password})
 
         if 'Invalid username or password' in response.body:
-            self.fail('could not login using %s %s' % (username, password))
+            pytest.fail('could not login using %s %s' % (username, password))
 
         self.assertEqual(response.status, '302 Found')
         self.assert_authenticated_user(response, username)
@@ -219,14 +219,14 @@
 
     def checkSessionFlash(self, response, msg=None, skip=0, _matcher=lambda msg, m: msg in m):
         if 'flash' not in response.session:
-            self.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
+            pytest.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
         try:
             level, m = response.session['flash'][-1 - skip]
             if _matcher(msg, m):
                 return
         except IndexError:
             pass
-        self.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
+        pytest.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
                            (msg, skip,
                             ', '.join('`%s`' % m for level, m in response.session['flash']))))
 
--- a/kallithea/tests/functional/test_admin_repos.py	Tue Mar 08 15:50:54 2016 +0100
+++ b/kallithea/tests/functional/test_admin_repos.py	Mon Feb 29 22:06:40 2016 +0100
@@ -82,7 +82,7 @@
         try:
             vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
         except vcs.exceptions.VCSError:
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name)
         Session().commit()
@@ -136,7 +136,7 @@
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
             Session().commit()
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name_full)
         RepoGroupModel().delete(group_name)
@@ -228,7 +228,7 @@
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
             Session().commit()
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name_full)
         RepoGroupModel().delete(group_name)
@@ -285,7 +285,7 @@
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
             Session().commit()
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         #check if inherited permissiona are applied
         inherited_perms = UserRepoToPerm.query() \
@@ -360,7 +360,7 @@
         try:
             vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
         except vcs.exceptions.VCSError:
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         response = self.app.post(url('delete_repo', repo_name=repo_name),
             params={'_method': 'delete', '_authentication_token': self.authentication_token()})
@@ -413,7 +413,7 @@
         try:
             vcs.get_repo(safe_str(os.path.join(TESTS_TMP_PATH, repo_name)))
         except vcs.exceptions.VCSError:
-            self.fail('no repo %s in filesystem' % repo_name)
+            pytest.fail('no repo %s in filesystem' % repo_name)
 
         response = self.app.post(url('delete_repo', repo_name=repo_name),
             params={'_method': 'delete', '_authentication_token': self.authentication_token()})
--- a/kallithea/tests/vcs/test_git.py	Tue Mar 08 15:50:54 2016 +0100
+++ b/kallithea/tests/vcs/test_git.py	Mon Feb 29 22:06:40 2016 +0100
@@ -4,6 +4,9 @@
 import mock
 import datetime
 import urllib2
+
+import pytest
+
 from kallithea.lib.vcs.backends.git import GitRepository, GitChangeset
 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
 from kallithea.lib.vcs.nodes import NodeKind, FileNode, DirNode, NodeState
@@ -17,7 +20,7 @@
 
     def __check_for_existing_repo(self):
         if os.path.exists(TEST_GIT_REPO_CLONE):
-            self.fail('Cannot test git clone repo as location %s already '
+            pytest.fail('Cannot test git clone repo as location %s already '
                       'exists. You should manually remove it first.'
                       % TEST_GIT_REPO_CLONE)
 
@@ -339,7 +342,7 @@
             idx += 1
             rev_id = self.repo.revisions[rev]
             if idx > limit:
-                self.fail("Exceeded limit already (getting revision %s, "
+                pytest.fail("Exceeded limit already (getting revision %s, "
                     "there are %s total revisions, offset=%s, limit=%s)"
                     % (rev_id, count, offset, limit))
             self.assertEqual(changeset, self.repo.get_changeset(rev_id))
@@ -347,7 +350,7 @@
         start = offset
         end = limit and offset + limit or None
         sliced = list(self.repo[start:end])
-        self.failUnlessEqual(result, sliced,
+        pytest.failUnlessEqual(result, sliced,
             msg="Comparison failed for limit=%s, offset=%s"
             "(get_changeset returned: %s and sliced: %s"
             % (limit, offset, result, sliced))
--- a/kallithea/tests/vcs/test_hg.py	Tue Mar 08 15:50:54 2016 +0100
+++ b/kallithea/tests/vcs/test_hg.py	Mon Feb 29 22:06:40 2016 +0100
@@ -1,5 +1,8 @@
 
 import os
+
+import pytest
+
 from kallithea.lib.utils2 import safe_str
 from kallithea.lib.vcs.backends.hg import MercurialRepository, MercurialChangeset
 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError
@@ -20,7 +23,7 @@
 
     def __check_for_existing_repo(self):
         if os.path.exists(TEST_HG_REPO_CLONE):
-            self.fail('Cannot test mercurial clone repo as location %s already '
+            pytest.fail('Cannot test mercurial clone repo as location %s already '
                       'exists. You should manually remove it first.'
                       % TEST_HG_REPO_CLONE)
 
@@ -67,7 +70,7 @@
 
     def test_pull(self):
         if os.path.exists(TEST_HG_REPO_PULL):
-            self.fail('Cannot test mercurial pull command as location %s '
+            pytest.fail('Cannot test mercurial pull command as location %s '
                       'already exists. You should manually remove it first'
                       % TEST_HG_REPO_PULL)
         repo_new = MercurialRepository(TEST_HG_REPO_PULL, create=True)
--- a/kallithea/tests/vcs/test_nodes.py	Tue Mar 08 15:50:54 2016 +0100
+++ b/kallithea/tests/vcs/test_nodes.py	Mon Feb 29 22:06:40 2016 +0100
@@ -76,7 +76,7 @@
     '''
     def _test_trailing_slash(self, path):
         if not path.endswith('/'):
-            self.fail("Trailing slash tests needs paths to end with slash")
+            pytest.fail("Trailing slash tests needs paths to end with slash")
         for kind in NodeKind.FILE, NodeKind.DIR:
             self.assertRaises(NodeError, Node, path=path, kind=kind)