Rev 3228: Add add_inventory external reference interface tests and tweak broken test support function adapt_tests. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Wed Feb 20 03:00:33 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3228
revision-id:robertc at robertcollins.net-20080220030028-c3r2ue2nd4h3a1th
parent: robertc at robertcollins.net-20080220002317-5bdinlaczri004x2
committer: Robert Collins <robertc at robertcollins.net>
branch nick: external_reference_tests
timestamp: Wed 2008-02-20 14:00:28 +1100
message:
Add add_inventory external reference interface tests and tweak broken test support function adapt_tests.
added:
bzrlib/tests/repository_external_reference_implementations/ repository_external_-20080220025549-nnm2s80it1lvcwnc-1
bzrlib/tests/repository_external_reference_implementations/__init__.py __init__.py-20080220025549-nnm2s80it1lvcwnc-2
bzrlib/tests/repository_external_reference_implementations/test_add_inventory.py test_add_inventory.p-20080220025549-nnm2s80it1lvcwnc-3
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
=== modified file 'NEWS'
--- a/NEWS 2008-02-19 04:11:34 +0000
+++ b/NEWS 2008-02-20 03:00:28 +0000
@@ -27,6 +27,9 @@
TESTING:
+ * ``bzrlib.tests.adapt_tests`` was broken and unused - it has been fixed.
+ (Robert Collins)
+
INTERNALS:
* New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-02-06 00:41:04 +0000
+++ b/bzrlib/tests/__init__.py 2008-02-20 03:00:28 +0000
@@ -2705,6 +2705,7 @@
'bzrlib.tests.test_registry',
'bzrlib.tests.test_remote',
'bzrlib.tests.test_repository',
+ 'bzrlib.tests.repository_external_reference_implementations',
'bzrlib.tests.test_revert',
'bzrlib.tests.test_revision',
'bzrlib.tests.test_revisionnamespaces',
@@ -2897,16 +2898,16 @@
def adapt_modules(mods_list, adapter, loader, suite):
"""Adapt the modules in mods_list using adapter and add to suite."""
- for test in iter_suite_tests(loader.loadTestsFromModuleNames(mods_list)):
+ tests = loader.loadTestsFromModuleNames(mods_list)
+ adapt_tests(tests, adapter, suite)
+
+
+def adapt_tests(tests_list, adapter, suite):
+ """Adapt the tests in tests_list using adapter and add to suite."""
+ for test in iter_suite_tests(tests_list):
suite.addTests(adapter.adapt(test))
-def adapt_tests(tests_list, adapter, loader, suite):
- """Adapt the tests in tests_list using adapter and add to suite."""
- for test in tests_list:
- suite.addTests(adapter.adapt(loader.loadTestsFromName(test)))
-
-
def _rmtree_temp_dir(dirname):
# If LANG=C we probably have created some bogus paths
# which rmtree(unicode) will fail to delete
=== added directory 'bzrlib/tests/repository_external_reference_implementations'
=== added file 'bzrlib/tests/repository_external_reference_implementations/__init__.py'
--- a/bzrlib/tests/repository_external_reference_implementations/__init__.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/repository_external_reference_implementations/__init__.py 2008-02-20 03:00:28 +0000
@@ -0,0 +1,97 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+"""Repository implementation tests for external reference repositories.
+
+These test the conformance of repositories which refer to other repositories
+for some data.
+"""
+
+from bzrlib import (
+ repository,
+ remote,
+ )
+from bzrlib.bzrdir import BzrDir
+from bzrlib.tests import (
+ adapt_modules,
+ adapt_tests,
+ TestScenarioApplier,
+ TestSuite,
+ )
+from bzrlib.tests.repository_implementations import (
+ all_repository_format_scenarios,
+ TestCaseWithRepository,
+ )
+
+
+class TestCaseWithExternalReferenceRepository(TestCaseWithRepository):
+
+ def make_referring(self, relpath, target_path):
+ """Get a new repository that refers to a_repository.
+
+ :param relpath: The path to create the repository at.
+ :param a_repository: A repository to refer to.
+ """
+ repo = self.make_repository(relpath)
+ repo.add_fallback_repository(self.readonly_repository(target_path))
+ return repo
+
+ def readonly_repository(self, relpath):
+ return BzrDir.open_from_transport(
+ self.get_readonly_transport(relpath)).open_repository()
+
+
+class TestCorrectFormat(TestCaseWithExternalReferenceRepository):
+
+ def test_repository_format(self):
+ # make sure the repository on tree.branch is of the desired format,
+ # because developers use this api to setup the tree, branch and
+ # repository for their tests: having it not give the right repository
+ # type would invalidate the tests.
+ self.make_branch_and_tree('repo')
+ repo = self.make_referring('referring', 'repo')
+ self.assertIsInstance(repo._format,
+ self.repository_format.__class__)
+
+
+def load_tests(standard_tests, module, loader):
+ # format_scenarios is all the implementations of Repository; i.e. all disk
+ # formats plus RemoteRepository.
+ adapter = TestScenarioApplier()
+ scenarios = all_repository_format_scenarios()
+ adapter.scenarios = []
+ for scenario in scenarios:
+ format = scenario[1]['repository_format']
+ # For remote repositories, we need at least one external reference
+ # capable format to test it: defer this until landing such a format.
+ # if isinstance(format, remote.RemoteRepositoryFormat):
+ # scenario[1]['bzrdir_format'].repository_format =
+ if format.supports_external_lookups:
+ adapter.scenarios.append(scenario)
+
+ prefix = module.__name__ + '.test_'
+ test_repository_modules = [
+ 'add_inventory',
+ ]
+ module_name_list = [prefix + module_name
+ for module_name in test_repository_modules]
+
+ # Parameterize repository_implementations test modules by format.
+ result = TestSuite()
+ adapt_tests(standard_tests, adapter, result)
+ adapt_modules(module_name_list, adapter, loader, result)
+ return result
=== added file 'bzrlib/tests/repository_external_reference_implementations/test_add_inventory.py'
--- a/bzrlib/tests/repository_external_reference_implementations/test_add_inventory.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/repository_external_reference_implementations/test_add_inventory.py 2008-02-20 03:00:28 +0000
@@ -0,0 +1,49 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for add_inventory on a repository with external references."""
+
+from bzrlib import errors
+from bzrlib.tests.repository_external_reference_implementations import (
+ TestCaseWithExternalReferenceRepository,
+ )
+
+
+class TestAddInventory(TestCaseWithExternalReferenceRepository):
+
+ def test_add_inventory_goes_to_repo(self):
+ # adding an inventory only writes to the repository add_inventory is
+ # called on.
+ tree = self.make_branch_and_tree('sample')
+ revid = tree.commit('one')
+ inv = tree.branch.repository.get_inventory(revid)
+ base = self.make_repository('base')
+ repo = self.make_referring('referring', 'base')
+ repo.lock_write()
+ try:
+ repo.start_write_group()
+ try:
+ repo.add_inventory(revid, inv, [])
+ except:
+ repo.abort_write_group()
+ raise
+ else:
+ repo.commit_write_group()
+ finally:
+ repo.unlock()
+ inv2 = repo.get_inventory(revid)
+ self.assertEqual(inv._byid, inv2._byid)
+ self.assertRaises(errors.RevisionNotPresent, base.get_inventory, revid)
=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- a/bzrlib/tests/repository_implementations/__init__.py 2008-01-11 03:54:51 +0000
+++ b/bzrlib/tests/repository_implementations/__init__.py 2008-02-20 03:00:28 +0000
@@ -50,42 +50,47 @@
from bzrlib.transport.memory import MemoryServer
-class RepositoryTestProviderAdapter(TestScenarioApplier):
- """A tool to generate a suite testing multiple repository formats at once.
+def formats_to_scenarios(formats, transport_server, transport_readonly_server,
+ vfs_transport_factory=None):
+ """Transform the input formats to a list of scenarios.
- This is done by copying the test once for each transport and injecting
- the transport_server, transport_readonly_server, and bzrdir_format and
- repository_format classes into each copy. Each copy is also given a new id()
- to make it easy to identify.
+ :param formats: A list of (repository_format, bzrdir_format).
"""
-
- def __init__(self, transport_server, transport_readonly_server, formats,
- vfs_transport_factory=None):
- TestScenarioApplier.__init__(self)
- self._transport_server = transport_server
- self._transport_readonly_server = transport_readonly_server
- self._vfs_transport_factory = vfs_transport_factory
- self.scenarios = self.formats_to_scenarios(formats)
-
- def formats_to_scenarios(self, formats):
- """Transform the input formats to a list of scenarios.
-
- :param formats: A list of (repository_format, bzrdir_format).
- """
- result = []
- for repository_format, bzrdir_format in formats:
- scenario = (repository_format.__class__.__name__,
- {"transport_server":self._transport_server,
- "transport_readonly_server":self._transport_readonly_server,
- "bzrdir_format":bzrdir_format,
- "repository_format":repository_format,
- })
- # Only override the test's vfs_transport_factory if one was
- # specified, otherwise just leave the default in place.
- if self._vfs_transport_factory:
- scenario[1]['vfs_transport_factory'] = self._vfs_transport_factory
- result.append(scenario)
- return result
+ result = []
+ for repository_format, bzrdir_format in formats:
+ scenario = (repository_format.__class__.__name__,
+ {"transport_server":transport_server,
+ "transport_readonly_server":transport_readonly_server,
+ "bzrdir_format":bzrdir_format,
+ "repository_format":repository_format,
+ })
+ # Only override the test's vfs_transport_factory if one was
+ # specified, otherwise just leave the default in place.
+ if vfs_transport_factory:
+ scenario[1]['vfs_transport_factory'] = vfs_transport_factory
+ result.append(scenario)
+ return result
+
+
+def all_repository_format_scenarios():
+ """Return a list of test scenarios for parameterising repository tests."""
+ registry = repository.format_registry
+ all_formats = [registry.get(k) for k in registry.keys()]
+ all_formats.extend(weaverepo._legacy_formats)
+ # format_scenarios is all the implementations of Repository; i.e. all disk
+ # formats plus RemoteRepository.
+ format_scenarios = formats_to_scenarios(
+ [(format, format._matchingbzrdir) for format in all_formats],
+ default_transport,
+ # None here will cause a readonly decorator to be created
+ # by the TestCaseWithTransport.get_readonly_transport method.
+ None)
+ format_scenarios.extend(formats_to_scenarios(
+ [(RemoteRepositoryFormat(), RemoteBzrDirFormat())],
+ SmartTCPServer_for_testing,
+ ReadonlySmartTCPServer_for_testing,
+ MemoryServer))
+ return format_scenarios
class TestCaseWithRepository(TestCaseWithBzrDir):
@@ -832,31 +837,9 @@
IncorrectlyOrderedParentsScenario,
UnreferencedFileParentsFromNoOpMergeScenario,
]
-
+
def test_suite():
- registry = repository.format_registry
- all_formats = [registry.get(k) for k in registry.keys()]
- all_formats.extend(weaverepo._legacy_formats)
- disk_format_adapter = RepositoryTestProviderAdapter(
- default_transport,
- # None here will cause a readonly decorator to be created
- # by the TestCaseWithTransport.get_readonly_transport method.
- None,
- [(format, format._matchingbzrdir) for format in all_formats])
-
- remote_repo_adapter = RepositoryTestProviderAdapter(
- SmartTCPServer_for_testing,
- ReadonlySmartTCPServer_for_testing,
- [(RemoteRepositoryFormat(), RemoteBzrDirFormat())],
- MemoryServer
- )
-
- # format_scenarios is all the implementations of Repository; i.e. all disk
- # formats plus RemoteRepository.
- format_scenarios = (disk_format_adapter.scenarios +
- remote_repo_adapter.scenarios)
-
prefix = 'bzrlib.tests.repository_implementations.'
test_repository_modules = [
'test_break_lock',
@@ -882,6 +865,7 @@
for module_name in test_repository_modules]
# Parameterize repository_implementations test modules by format.
+ format_scenarios = all_repository_format_scenarios()
result = multiply_tests_from_modules(module_name_list, format_scenarios)
# test_check_reconcile needs to be parameterized by format *and* by broken
More information about the bazaar-commits
mailing list