Rev 5453: Start defining fixtures but we still have an unexpected sucessful test. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Oct 4 09:06:27 BST 2010
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5453
revision-id: v.ladeuil+lp at free.fr-20101004080627-dmx49vve2127gcgc
parent: v.ladeuil+lp at free.fr-20101003170118-3yhu3oguq1i9lqn6
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-modify
timestamp: Mon 2010-10-04 10:06:27 +0200
message:
Start defining fixtures but we still have an unexpected sucessful test.
* bzrlib/tests/test_config.py:
(create_configs, create_configs_with_file_option): Start defining
fixtures to avoid inheritance hell in test classes.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-10-03 17:01:18 +0000
+++ b/bzrlib/config.py 2010-10-04 08:06:27 +0000
@@ -1741,8 +1741,7 @@
self._set_config_option(matching[:pos], matching[pos+1:],
directory, force)
- def _show_config(self, matching, directory, force):
- # FIXME: force must be None
+ def _show_config(self, matching, directory, force_meaningless):
try:
(_, br, _) = bzrdir.BzrDir.open_containing_tree_or_branch(
directory)
=== modified file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py 2010-10-03 17:01:18 +0000
+++ b/bzrlib/tests/blackbox/test_config.py 2010-10-04 08:06:27 +0000
@@ -26,12 +26,10 @@
)
from bzrlib.tests import (
script,
- # FIXME: Importing the 'other' test_config to use TestWithConfigs hints
- # that we really need a fixture here -- vila 20101002
test_config as _t_config,
)
-class TestEmptyConfig(tests.TestCaseWithTransport):
+class TestWithoutConfig(tests.TestCaseWithTransport):
def test_no_config(self):
out, err = self.run_bzr(['config'])
@@ -44,10 +42,14 @@
self.assertEquals('', err)
-class TestConfigDisplay(_t_config.TestWithConfigs):
-
- def test_global_config(self):
- self.global_config.set_user_option('hello', 'world')
+class TestConfigDisplay(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigDisplay, self).setUp()
+ _t_config.create_configs(self)
+
+ def test_bazaar_config(self):
+ self.bazaar_config.set_user_option('hello', 'world')
script.run_script(self, '''
$ bzr config -d tree
bazaar:
@@ -66,7 +68,7 @@
''')
def test_locations_config_outside_branch(self):
- self.global_config.set_user_option('hello', 'world')
+ self.bazaar_config.set_user_option('hello', 'world')
self.locations_config.set_user_option('hello', 'world')
script.run_script(self, '''
$ bzr config
@@ -75,12 +77,16 @@
''')
-class TestConfigSet(_t_config.TestWithConfigs):
+class TestConfigSet(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigSet, self).setUp()
+ _t_config.create_configs(self)
def test_unknown_config(self):
self.run_bzr(['config', '--force', 'moon', 'hello=world'], retcode=3)
- def test_global_config_outside_branch(self):
+ def test_bazaar_config_outside_branch(self):
script.run_script(self, '''
$ bzr config --force bazaar hello=world
$ bzr config -d tree hello
@@ -88,7 +94,7 @@
hello = world
''')
- def test_global_config_inside_branch(self):
+ def test_bazaar_config_inside_branch(self):
script.run_script(self, '''
$ bzr config -d tree --force bazaar hello=world
$ bzr config -d tree hello
@@ -119,3 +125,13 @@
branch:
hello = world
''')
+
+
+class TestConfigRemove(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigRemove, self).setUp()
+ _t_config.create_configs_with_file_option(self)
+
+ def test_unknown_option(self):
+ self.run_bzr(['config', '--remove', 'file'], retcode=3)
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-10-03 17:01:18 +0000
+++ b/bzrlib/tests/test_config.py 2010-10-04 08:06:27 +0000
@@ -1471,17 +1471,45 @@
self.assertIs(None, bzrdir_config.get_default_stack_on())
-class TestWithConfigs(tests.TestCaseWithTransport):
+def create_configs(test):
+ """Create configuration files for a given test.
+
+ This requires creating a tree (and populate the ``test.tree`` attribute and
+ its associated branch and will populate the following attributes:
+
+ - branch_config: A BranchConfig for the associated branch.
+
+ - locations_config : A LocationConfig for the associated branch
+
+ - bazaar_config: A GlobalConfig.
+
+ The tree and branch are created in a 'tree' subdirectory so the tests can
+ still use the test directory to stay outside of the branch.
+ """
+ tree = test.make_branch_and_tree('tree')
+ test.tree = tree
+ test.branch_config = config.BranchConfig(tree.branch)
+ test.locations_config = config.LocationConfig(tree.basedir)
+ test.bazaar_config = config.GlobalConfig()
+
+
+def create_configs_with_file_option(test):
+ """Create configuration files with a ``file`` option set in each.
+
+ This builds on ``create_configs`` and add one ``file`` option in each
+ configuration with a value which allows identifying the configuration file.
+ """
+ create_configs(test)
+ test.bazaar_config.set_user_option('file', 'bazaar')
+ test.locations_config.set_user_option('file', 'locations')
+ test.branch_config.set_user_option('file', 'branch')
+
+
+class TestConfigGetOptions(tests.TestCaseWithTransport):
def setUp(self):
- super(TestWithConfigs, self).setUp()
- self.tree = self.make_branch_and_tree('tree')
- self.locations_config = config.LocationConfig(self.tree.basedir)
- self.branch_config = config.BranchConfig(self.tree.branch)
- self.global_config = config.GlobalConfig()
-
-
-class TestConfigGetOptions(TestWithConfigs):
+ super(TestConfigGetOptions, self).setUp()
+ create_configs(self)
def assertOptions(self, expected, conf):
actual = list(conf.get_options())
@@ -1493,9 +1521,9 @@
self.assertOptions([], self.branch_config)
def test_option_in_bazaar(self):
- self.global_config.set_user_option('file', 'bazaar')
+ self.bazaar_config.set_user_option('file', 'bazaar')
self.assertOptions([('file', 'bazaar', 'DEFAULT', 'bazaar')],
- self.global_config)
+ self.bazaar_config)
def test_option_in_locations(self):
self.locations_config.set_user_option('file', 'locations')
@@ -1509,7 +1537,7 @@
self.branch_config)
def test_option_in_bazaar_and_branch(self):
- self.global_config.set_user_option('file', 'bazaar')
+ self.bazaar_config.set_user_option('file', 'bazaar')
self.branch_config.set_user_option('file', 'branch')
self.assertOptions([('file', 'branch', 'DEFAULT', 'branch'),
('file', 'bazaar', 'DEFAULT', 'bazaar'),],
@@ -1525,7 +1553,7 @@
self.branch_config)
def test_option_in_bazaar_locations_and_branch(self):
- self.global_config.set_user_option('file', 'bazaar')
+ self.bazaar_config.set_user_option('file', 'bazaar')
self.locations_config.set_user_option('file', 'locations')
self.branch_config.set_user_option('file', 'branch')
self.assertOptions(
@@ -1535,7 +1563,17 @@
self.branch_config)
-class TestConfigGetSections(TestWithConfigs):
+class TestConfigRemoveOption(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigRemoveOption, self).setUp()
+ create_configs_with_file_option(self)
+
+class TestConfigGetSections(tests.TestCaseWithTransport):
+
+ def setUp(self):
+ super(TestConfigGetSections, self).setUp()
+ create_configs(self)
def assertSectionNames(self, expected, conf, name=None):
"""Check which sections are returned for a given config.
@@ -1553,8 +1591,8 @@
self.assertLength(len(expected), sections)
self.assertEqual(expected, [name for name, section in sections])
- def test_global_default_section(self):
- self.assertSectionNames(['DEFAULT'], self.global_config)
+ def test_bazaar_default_section(self):
+ self.assertSectionNames(['DEFAULT'], self.bazaar_config)
def test_locations_default_section(self):
# No sections are defined in an empty file
@@ -1594,11 +1632,11 @@
self.assertSectionNames([self.tree.basedir, None, 'DEFAULT'],
self.branch_config)
- def test_global_named_section(self):
+ def test_bazaar_named_section(self):
# We need to cheat as the API doesn't give direct access to sections
# other than DEFAULT.
- self.global_config.set_alias('bazaar', 'bzr')
- self.assertSectionNames(['ALIASES'], self.global_config, 'ALIASES')
+ self.bazaar_config.set_alias('bazaar', 'bzr')
+ self.assertSectionNames(['ALIASES'], self.bazaar_config, 'ALIASES')
class TestAuthenticationConfigFile(tests.TestCase):
More information about the bazaar-commits
mailing list