# HG changeset patch # User Branko Majic # Date 1519388943 -3600 # Node ID 45a281a0f36ff59ffaa4aa0107fabfc1a6310251 # Parent 18a19c7d5145797a3b537021cdd73d9dfb94496b tests: Remove metaprogramming constructs for vcs test classes (issue #309): - Removed use of the globals() and type() constructs to programatically instantiate Git/Mercurial-specific test classes. This should make it a bit clearer what tests are being run at the expense of possible future VCS additions. - Removed the SCM_TESTS VCS test configuration variable, since it got removed. Previously it was used for instantiating test classes. - Updated small snippet of inline documentation that described the use of SCM_TESTS variable. New text points to inheriting from generic test classes instead. - base.py had a dead snippet - kill it. diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/base.py --- a/kallithea/tests/base.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/base.py Fri Feb 23 13:29:03 2018 +0100 @@ -48,7 +48,7 @@ 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO', 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO', 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO', - 'GIT_REMOTE_REPO', 'SCM_TESTS', 'HG_TEST_REVISION', 'GIT_TEST_REVISION', + 'GIT_REMOTE_REPO', 'HG_TEST_REVISION', 'GIT_TEST_REVISION', ] # Invoke websetup with the current config file @@ -84,7 +84,6 @@ ## VCS -SCM_TESTS = ['hg', 'git'] uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple()))) GIT_REMOTE_REPO = os.path.join(TESTS_TMP_PATH, GIT_REPO) diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/__init__.py --- a/kallithea/tests/vcs/__init__.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/__init__.py Fri Feb 23 13:29:03 2018 +0100 @@ -1,9 +1,14 @@ """ Unit tests for vcs_ library. -In order to run tests we need to prepare our environment first. Tests would be -run for each engine listed at ``conf.SCM_TESTS`` - keys are aliases from -``vcs.backends.BACKENDS``. +While some tests are implemented for a specific backend, a huge number +is completely independent of the underlying backend. + +For such independent tests a base testing class is implemented, and +backend-specific test classes are defined. These sub-classes simply +need to set the correct backend to use by setting the +``backend_alias`` property, which should correspond to one of the keys +from ``vcs.backends.BACKENDS``. For each SCM we run tests for, we need some repository. We would use repositories location provided in test suite defaults - see ``conf`` diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/base.py --- a/kallithea/tests/vcs/base.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/base.py Fri Feb 23 13:29:03 2018 +0100 @@ -9,7 +9,7 @@ from kallithea.lib import vcs from kallithea.lib.vcs.nodes import FileNode -from kallithea.tests.vcs.conf import SCM_TESTS, get_new_dir +from kallithea.tests.vcs.conf import get_new_dir class _BackendTestMixin(object): @@ -83,12 +83,3 @@ def setup_method(self, method): if getattr(self, 'recreate_repo_per_test', False): self.__class__.setup_class() - - -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('%s base backend test' % alias).title().split()) - globals()[cls_name] = type(cls_name, (_BackendTestMixin,), attrs) diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/conf.py --- a/kallithea/tests/vcs/conf.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/conf.py Fri Feb 23 13:29:03 2018 +0100 @@ -8,7 +8,7 @@ # module. Some of these configuration options are subsequently # consumed by the VCS test module. from kallithea.tests.base import ( - TESTS_TMP_PATH, SCM_TESTS, + TESTS_TMP_PATH, TEST_HG_REPO, HG_REMOTE_REPO, TEST_HG_REPO_CLONE, TEST_HG_REPO_PULL, TEST_GIT_REPO, GIT_REMOTE_REPO, @@ -18,7 +18,6 @@ __all__ = ( 'TEST_HG_REPO', 'TEST_GIT_REPO', 'HG_REMOTE_REPO', 'GIT_REMOTE_REPO', 'TEST_HG_REPO_CLONE', 'TEST_GIT_REPO_CLONE', 'TEST_HG_REPO_PULL', - 'SCM_TESTS', ) diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_archives.py --- a/kallithea/tests/vcs/test_archives.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_archives.py Fri Feb 23 13:29:03 2018 +0100 @@ -11,7 +11,7 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS, TESTS_TMP_PATH +from kallithea.tests.vcs.conf import TESTS_TMP_PATH class ArchivesTestCaseMixin(_BackendTestMixin): @@ -97,10 +97,9 @@ self.tip.fill_archive(prefix='/any') -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s archive' % alias).title().split()) - globals()[cls_name] = type(cls_name, (ArchivesTestCaseMixin,), attrs) +class TestGitArchive(ArchivesTestCaseMixin): + backend_alias = 'git' + + +class TestHgArchive(ArchivesTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_branches.py --- a/kallithea/tests/vcs/test_branches.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_branches.py Fri Feb 23 13:29:03 2018 +0100 @@ -3,7 +3,6 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS class BranchesTestCaseMixin(_BackendTestMixin): @@ -101,10 +100,9 @@ assert '123' in self.repo.branches -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s branches' % alias).title().split()) - globals()[cls_name] = type(cls_name, (BranchesTestCaseMixin,), attrs) +class TestGitBranches(BranchesTestCaseMixin): + backend_alias = 'git' + + +class TestHgBranches(BranchesTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_changesets.py --- a/kallithea/tests/vcs/test_changesets.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_changesets.py Fri Feb 23 13:29:03 2018 +0100 @@ -18,7 +18,7 @@ ) from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS, get_new_dir +from kallithea.tests.vcs.conf import get_new_dir class TestBaseChangeset(object): @@ -374,19 +374,25 @@ assert 33188 == changeset.get_file_mode(u'foo/bał') -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - # tests with additional commits - cls_name = 'Test' + alias.title() + 'ChangesetsWithCommits' - globals()[cls_name] = type(cls_name, (_ChangesetsWithCommitsTestCaseixin,), attrs) +class TestGitChangesetsWithCommits(_ChangesetsWithCommitsTestCaseixin): + backend_alias = 'git' + + +class TestGitChangesets(_ChangesetsTestCaseMixin): + backend_alias = 'git' + + +class TestGitChangesetsChanges(_ChangesetsChangesTestCaseMixin): + backend_alias = 'git' - # tests without additional commits - cls_name = 'Test' + alias.title() + 'Changesets' - globals()[cls_name] = type(cls_name, (_ChangesetsTestCaseMixin,), attrs) + +class TestHgChangesetsWithCommits(_ChangesetsWithCommitsTestCaseixin): + backend_alias = 'hg' + - # tests changes - cls_name = 'Test' + alias.title() + 'ChangesetsChanges' - globals()[cls_name] = type(cls_name, (_ChangesetsChangesTestCaseMixin,), attrs) +class TestHgChangesets(_ChangesetsTestCaseMixin): + backend_alias = 'hg' + + +class TestHgChangesetsChanges(_ChangesetsChangesTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_filenodes_unicode_path.py --- a/kallithea/tests/vcs/test_filenodes_unicode_path.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_filenodes_unicode_path.py Fri Feb 23 13:29:03 2018 +0100 @@ -4,7 +4,6 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.tests.vcs.test_inmemchangesets import BackendBaseTestCase -from kallithea.tests.vcs.conf import SCM_TESTS class FileNodeUnicodePathTestsMixin(object): @@ -33,11 +32,9 @@ assert node == unode -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s file node unicode path' % alias).title() - .split()) - bases = (FileNodeUnicodePathTestsMixin, BackendBaseTestCase) - globals()[cls_name] = type(cls_name, bases, attrs) +class TestGitFileNodeUnicodePath(FileNodeUnicodePathTestsMixin, BackendBaseTestCase): + backend_alias = 'git' + + +class TestHgFileNodeUnicodePath(FileNodeUnicodePathTestsMixin, BackendBaseTestCase): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_getitem.py --- a/kallithea/tests/vcs/test_getitem.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_getitem.py Fri Feb 23 13:29:03 2018 +0100 @@ -1,7 +1,6 @@ import datetime from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.nodes import FileNode @@ -28,10 +27,9 @@ assert changesets == list(self.repo.get_changesets()) -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s getitem' % alias).title().split()) - globals()[cls_name] = type(cls_name, (GetitemTestCaseMixin,), attrs) +class TestGitGetitem(GetitemTestCaseMixin): + backend_alias = 'git' + + +class TestHgGetitem(GetitemTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_getslice.py --- a/kallithea/tests/vcs/test_getslice.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_getslice.py Fri Feb 23 13:29:03 2018 +0100 @@ -3,7 +3,6 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS class GetsliceTestCaseMixin(_BackendTestMixin): @@ -37,10 +36,9 @@ assert list(self.repo[:-2]) == [self.repo.get_changeset(rev) for rev in self.repo.revisions[:-2]] -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s getslice' % alias).title().split()) - globals()[cls_name] = type(cls_name, (GetsliceTestCaseMixin,), attrs) +class TestGitGetslice(GetsliceTestCaseMixin): + backend_alias = 'git' + + +class TestHgGetslice(GetsliceTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_inmemchangesets.py --- a/kallithea/tests/vcs/test_inmemchangesets.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_inmemchangesets.py Fri Feb 23 13:29:03 2018 +0100 @@ -20,7 +20,7 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.lib.vcs.utils import safe_unicode -from kallithea.tests.vcs.conf import SCM_TESTS, get_new_dir +from kallithea.tests.vcs.conf import get_new_dir class InMemoryChangesetTestMixin(object): @@ -404,10 +404,9 @@ self.tip = self.repo.get_changeset() -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s in memory changeset' % alias).title().split()) - globals()[cls_name] = type(cls_name, (InMemoryChangesetTestMixin,), attrs) +class TestGitInMemoryChangeset(InMemoryChangesetTestMixin): + backend_alias = 'git' + + +class TestHgInMemoryChangeset(InMemoryChangesetTestMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_repository.py --- a/kallithea/tests/vcs/test_repository.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_repository.py Fri Feb 23 13:29:03 2018 +0100 @@ -6,7 +6,6 @@ from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.tests.vcs import TEST_USER_CONFIG_FILE @@ -44,6 +43,14 @@ assert self.repo != dummy() +class TestGitRepositoryBase(RepositoryBaseTest): + backend_alias = 'git' + + +class TestHgRepositoryBase(RepositoryBaseTest): + backend_alias = 'hg' + + class RepositoryGetDiffTest(_BackendTestMixin): @classmethod @@ -248,12 +255,3 @@ +Strangely-named README file \ No newline at end of file ''' - - -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = 'Test' + alias.capitalize() + RepositoryBaseTest.__name__ - globals()[cls_name] = type(cls_name, (RepositoryBaseTest,), attrs) diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_tags.py --- a/kallithea/tests/vcs/test_tags.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_tags.py Fri Feb 23 13:29:03 2018 +0100 @@ -4,7 +4,6 @@ from kallithea.lib.vcs.exceptions import TagDoesNotExistError from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS class TagsTestCaseMixin(_BackendTestMixin): @@ -46,10 +45,9 @@ assert '19/10/11' in self.repo.tags -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s tags' % alias).title().split()) - globals()[cls_name] = type(cls_name, (TagsTestCaseMixin,), attrs) +class TestGitTags(TagsTestCaseMixin): + backend_alias = 'git' + + +class TestHgTags(TagsTestCaseMixin): + backend_alias = 'hg' diff -r 18a19c7d5145 -r 45a281a0f36f kallithea/tests/vcs/test_workdirs.py --- a/kallithea/tests/vcs/test_workdirs.py Mon Jun 26 23:49:26 2017 +0200 +++ b/kallithea/tests/vcs/test_workdirs.py Fri Feb 23 13:29:03 2018 +0100 @@ -5,7 +5,6 @@ from kallithea.lib.vcs.nodes import FileNode from kallithea.tests.vcs.base import _BackendTestMixin -from kallithea.tests.vcs.conf import SCM_TESTS class WorkdirTestCaseMixin(_BackendTestMixin): @@ -84,10 +83,9 @@ assert self.repo.workdir.get_branch() == 'foobranch' -# For each backend create test case class -for alias in SCM_TESTS: - attrs = { - 'backend_alias': alias, - } - cls_name = ''.join(('test %s branch' % alias).title().split()) - globals()[cls_name] = type(cls_name, (WorkdirTestCaseMixin, ), attrs) +class TestGitBranch(WorkdirTestCaseMixin): + backend_alias = 'git' + + +class TestHgBranch(WorkdirTestCaseMixin): + backend_alias = 'hg'