[PATCH] reshuffle test setup for consistence [broken for others to play around]
Ronny Pfannschmidt
opensource at ronnypfannschmidt.de
Tue Apr 21 01:26:53 EDT 2015
# HG changeset patch
# User Ronny Pfannschmidt <opensource at ronnypfannschmidt.de>
# Date 1429593925 -7200
# Tue Apr 21 07:25:25 2015 +0200
# Node ID 579235c71e206e2c54f0f2c565cb4c225d582153
# Parent b91b4caf0f35712a6c4f20cdb1afe3257284711c
reshuffle test setup for consistence [broken for others to play around]
currently test setup still needs to ave some sql at session start
fiinal target would be independent tests
fixes various details wrt test setup in setup/teardown
down to 200 failures
more investigation needed
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/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/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')
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kallithea.patch
Type: text/x-patch
Size: 16260 bytes
Desc: not available
URL: <http://lists.sfconservancy.org/pipermail/kallithea-general/attachments/20150421/b7bd3b0d/attachment-0001.bin>
More information about the kallithea-general
mailing list