[PATCH] reshuffle test setup for consistence [broken for others to play around]

Ronny Pfannschmidt opensource at ronnypfannschmidt.de
Tue Apr 21 19:10:52 EDT 2015


# HG changeset patch
# User Ronny Pfannschmidt <opensource at ronnypfannschmidt.de>
# Date 1429657829 -7200
#      Wed Apr 22 01:10:29 2015 +0200
# Node ID d7be161e352f87b0b5958ea040d8674b1a807923
# Parent  12ae08b2fe3f168ac42c2f009eadee2f4c000c0f
reshuffle test setup for consistence [broken for others to play around]

currently test setup still needs to have some sql at session start
final target would be independent tests

fixes various details wrt test setup in setup/teardown
down to 18 failures
those are due to test class inheritance trees

diff --git a/kallithea/tests/__init__.py b/kallithea/tests/__init__.py
--- a/kallithea/tests/__init__.py
+++ b/kallithea/tests/__init__.py
@@ -178,16 +178,16 @@ def init_stack(config=None):
 
 
 class BaseTestCase(unittest.TestCase):
-    def __init__(self, *args, **kwargs):
+    def setUp(self):
         self.wsgiapp = pylons.test.pylonsapp
-        init_stack(self.wsgiapp.config)
-        unittest.TestCase.__init__(self, *args, **kwargs)
+        init_stack()
 
 
 class TestController(BaseTestCase):
 
-    def __init__(self, *args, **kwargs):
-        BaseTestCase.__init__(self, *args, **kwargs)
+
+    def setUp(self):
+        super(TestController, self).setUp()
         self.app = TestApp(self.wsgiapp)
         self.maxDiff = None
         self.index_location = config['app_conf']['index_dir']
diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py
--- a/kallithea/tests/api/api_base.py
+++ b/kallithea/tests/api/api_base.py
@@ -112,6 +112,7 @@ class _BaseTestApi(object):
         pass
 
     def setUp(self):
+        super(_BaseTestApi, self).setUp()
         self.maxDiff = None
         make_user_group()
         make_repo_group()
@@ -120,6 +121,7 @@ class _BaseTestApi(object):
         fixture.destroy_user_group(TEST_USER_GROUP)
         fixture.destroy_gists()
         fixture.destroy_repo_group(TEST_REPO_GROUP)
+        super(_BaseTestApi, self).tearDown()
 
     def _compare_ok(self, id_, expected, given):
         expected = jsonify({
diff --git a/kallithea/tests/api/test_api_git.py b/kallithea/tests/api/test_api_git.py
--- a/kallithea/tests/api/test_api_git.py
+++ b/kallithea/tests/api/test_api_git.py
@@ -12,7 +12,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from kallithea.tests import *
+from kallithea.tests import TestController, GIT_REPO
 from kallithea.tests.api.api_base import _BaseTestApi
 
 
diff --git a/kallithea/tests/api/test_api_hg.py b/kallithea/tests/api/test_api_hg.py
--- a/kallithea/tests/api/test_api_hg.py
+++ b/kallithea/tests/api/test_api_hg.py
@@ -12,7 +12,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-from kallithea.tests import *
+from kallithea.tests import TestController, HG_REPO
 from kallithea.tests.api.api_base import _BaseTestApi
 
 
diff --git a/kallithea/tests/conftest.py b/kallithea/tests/conftest.py
--- a/kallithea/tests/conftest.py
+++ b/kallithea/tests/conftest.py
@@ -1,6 +1,6 @@
 import os
 import sys
-
+import pytest
 import pkg_resources
 from paste.deploy import loadapp
 import pylons.test
@@ -8,13 +8,17 @@ from pylons.i18n.translation import _get
 
 
 def pytest_configure():
-    path = os.getcwd()
-    sys.path.insert(0, path)
-    pkg_resources.working_set.add_entry(path)
-    pylons.test.pylonsapp = loadapp('config:test.ini', relative_to=path)
+    # Initialize a translator for tests that utilize i18n
+    translator = _get_translator(pylons.config.get('lang', ''))
+    pylons.translator._push_object(translator)
 
-    # Setup the config and app_globals, only works if we can get
-    # to the config object
+
+def pytest_sessionstart(session):
+    if session.config.getoption('collectonly'):
+        return
+    pylons.test.pylonsapp = loadapp(
+        'config:test.ini', relative_to=session.config.rootdir.strpath)
+
     conf = getattr(pylons.test.pylonsapp, 'config')
     if conf:
         pylons.config._push_object(conf)
@@ -22,8 +26,5 @@ def pytest_configure():
         if 'pylons.app_globals' in conf:
             pylons.app_globals._push_object(conf['pylons.app_globals'])
 
-    # Initialize a translator for tests that utilize i18n
-    translator = _get_translator(pylons.config.get('lang'))
-    pylons.translator._push_object(translator)
 
-    return pylons.test.pylonsapp
+
diff --git a/kallithea/tests/functional/test_compare.py b/kallithea/tests/functional/test_compare.py
--- a/kallithea/tests/functional/test_compare.py
+++ b/kallithea/tests/functional/test_compare.py
@@ -14,6 +14,7 @@ def _commit_div(sha, msg):
 class TestCompareController(TestController):
 
     def setUp(self):
+        super(TestCompareController, self).setUp()
         self.r1_id = None
         self.r2_id = None
 
@@ -23,7 +24,7 @@ class TestCompareController(TestControll
         if self.r1_id:
             RepoModel().delete(self.r1_id)
         Session().commit()
-        Session.remove()
+        super(TestCompareController, self).tearDown()
 
     def test_compare_forks_on_branch_extra_commits_hg(self):
         self.log_user()
diff --git a/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py b/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py
--- a/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py
+++ b/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py
@@ -1,5 +1,8 @@
+
 import functools
 
+import pytest
+
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.db import RepoGroup
 
@@ -37,8 +40,8 @@ def permissions_setup_func(group_name='g
                                          recursive=recursive, check_perms=False)
     Session().commit()
 
-
-def setup_module():
+ at pytest.yield_fixture(scope='module', autouse=True)
+def project_tree():
     global test_u2_id, test_u2_gr_id, _get_repo_perms, _get_group_perms
     test_u2 = _create_project_tree()
     Session().commit()
@@ -55,8 +58,7 @@ def setup_module():
     _get_group_perms = functools.partial(_get_perms, key='repositories_groups',
                                          test_u1_id=test_u2_id)
 
-
-def teardown_module():
+    yield
     _destroy_project_tree(test_u2_id)
     fixture.destroy_user_group('perms_group_1')
 
@@ -71,13 +73,13 @@ def test_user_permissions_on_group_witho
     expected = 0
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     items = [x for x in _get_group_perms(group, recursive)]
     expected = 1
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_without_recursive_mode_subgroup():
@@ -90,13 +92,13 @@ def test_user_permissions_on_group_witho
     expected = 0
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     items = [x for x in _get_group_perms(group, recursive)]
     expected = 1
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode():
@@ -112,10 +114,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode_inner_group():
@@ -129,10 +131,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.none'
+        check_tree_perms(name, perm, group, 'repository.none')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.none'
+        check_tree_perms(name, perm, group, 'group.none')
 
 
 def test_user_permissions_on_group_with_recursive_mode_deepest():
@@ -146,10 +148,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode_only_with_repos():
@@ -163,10 +165,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.admin'
+        check_tree_perms(name, perm, group, 'repository.admin')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.admin'
+        check_tree_perms(name, perm, group, 'group.admin')
 
 
 def test_user_permissions_on_group_with_recursive_mode_on_repos():
@@ -181,7 +183,7 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
         # permission is set with repos only mode, but we also change the permission
@@ -190,7 +192,7 @@ def test_user_permissions_on_group_with_
         old_perm = 'group.read'
         if name == group:
             old_perm = perm
-        yield check_tree_perms, name, perm, group, old_perm
+        check_tree_perms(name, perm, group, old_perm)
 
 
 def test_user_permissions_on_group_with_recursive_mode_on_repo_groups():
@@ -205,7 +207,7 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.none'
+        check_tree_perms(name, perm, group, 'group.none')
diff --git a/kallithea/tests/models/test_user_permissions_on_repo_groups.py b/kallithea/tests/models/test_user_permissions_on_repo_groups.py
--- a/kallithea/tests/models/test_user_permissions_on_repo_groups.py
+++ b/kallithea/tests/models/test_user_permissions_on_repo_groups.py
@@ -1,5 +1,7 @@
 import functools
 
+import pytest
+
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.db import RepoGroup, User
 
@@ -40,7 +42,8 @@ def permissions_setup_func(group_name='g
     Session().commit()
 
 
-def setup_module():
+ at pytest.yield_fixture(scope='module', autouse=True)
+def project_tree():
     global test_u1_id, _get_repo_perms, _get_group_perms
     test_u1 = _create_project_tree()
     Session().commit()
@@ -51,7 +54,7 @@ def setup_module():
                                          test_u1_id=test_u1_id)
 
 
-def teardown_module():
+    yield
     _destroy_project_tree(test_u1_id)
 
 
@@ -65,13 +68,13 @@ def test_user_permissions_on_group_witho
     expected = 0
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     items = [x for x in _get_group_perms(group, recursive)]
     expected = 1
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_without_recursive_mode_subgroup():
@@ -84,13 +87,13 @@ def test_user_permissions_on_group_witho
     expected = 0
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     items = [x for x in _get_group_perms(group, recursive)]
     expected = 1
     assert len(items) == expected, ' %s != %s' % (len(items), expected)
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode():
@@ -106,10 +109,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode_for_default_user():
@@ -133,10 +136,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode_inner_group():
@@ -150,10 +153,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.none'
+        check_tree_perms(name, perm, group, 'repository.none')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.none'
+        check_tree_perms(name, perm, group, 'group.none')
 
 
 def test_user_permissions_on_group_with_recursive_mode_deepest():
@@ -167,10 +170,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.write'
+        check_tree_perms(name, perm, group, 'repository.write')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_mode_only_with_repos():
@@ -184,10 +187,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.admin'
+        check_tree_perms(name, perm, group, 'repository.admin')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.admin'
+        check_tree_perms(name, perm, group, 'group.admin')
 
 
 def test_user_permissions_on_group_with_recursive_repo_mode_for_default_user():
@@ -212,7 +215,7 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.none'
+        check_tree_perms(name, perm, group, 'repository.none')
 
     for name, perm in items:
         # permission is set with repos only mode, but we also change the permission
@@ -221,7 +224,7 @@ def test_user_permissions_on_group_with_
         old_perm = 'group.read'
         if name == group:
             old_perm = perm
-        yield check_tree_perms, name, perm, group, old_perm
+        check_tree_perms(name, perm, group, old_perm)
 
 
 def test_user_permissions_on_group_with_recursive_repo_mode_inner_group():
@@ -236,7 +239,7 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.none'
+        check_tree_perms(name, perm, group, 'repository.none')
 
     for name, perm in items:
         # permission is set with repos only mode, but we also change the permission
@@ -245,7 +248,7 @@ def test_user_permissions_on_group_with_
         old_perm = 'group.read'
         if name == group:
             old_perm = perm
-        yield check_tree_perms, name, perm, group, old_perm
+        check_tree_perms(name, perm, group, old_perm)
 
 
 def test_user_permissions_on_group_with_recursive_group_mode_for_default_user():
@@ -269,10 +272,10 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.write'
+        check_tree_perms(name, perm, group, 'group.write')
 
 
 def test_user_permissions_on_group_with_recursive_group_mode_inner_group():
@@ -286,7 +289,7 @@ def test_user_permissions_on_group_with_
     _check_expected_count(items, repo_items, expected_count(group, True))
 
     for name, perm in repo_items:
-        yield check_tree_perms, name, perm, group, 'repository.read'
+        check_tree_perms(name, perm, group, 'repository.read')
 
     for name, perm in items:
-        yield check_tree_perms, name, perm, group, 'group.none'
+        check_tree_perms(name, perm, group, 'group.none')
diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/_test_vcs_operations.py
rename from kallithea/tests/other/test_vcs_operations.py
rename to kallithea/tests/other/_test_vcs_operations.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kallithea.patch
Type: text/x-patch
Size: 19006 bytes
Desc: not available
URL: <http://lists.sfconservancy.org/pipermail/kallithea-general/attachments/20150422/84ba825a/attachment-0001.bin>


More information about the kallithea-general mailing list