18
18
"""Tests for finding and reading the bzr config file[s]."""
19
19
# import system imports here
20
from ConfigParser import ConfigParser
20
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError
21
21
from cStringIO import StringIO
70
70
"#testing explicit beats globs\n")
73
class InstrumentedConfigParser(object):
74
"""A config parser look-enough-alike to record calls made to it."""
79
def read(self, filenames):
80
self._calls.append(('read', filenames))
73
class InstrumentedConfigObj(object):
74
"""A config obj look-enough-alike to record calls made to it."""
76
def __init__(self, input):
77
self._calls = [('__init__', input)]
83
80
class FakeBranch(object):
209
206
def test_calls_read_filenames(self):
210
207
# replace the class that is constructured, to check its parameters
211
oldparserclass = config.ConfigParser
212
config.ConfigParser = InstrumentedConfigParser
208
oldparserclass = config.ConfigObj
209
config.ConfigObj = InstrumentedConfigObj
213
210
my_config = config.GlobalConfig()
215
212
parser = my_config._get_parser()
217
config.ConfigParser = oldparserclass
218
self.failUnless(isinstance(parser, InstrumentedConfigParser))
219
self.assertEqual(parser._calls, [('read', [config.config_filename()])])
214
config.ConfigObj = oldparserclass
215
self.failUnless(isinstance(parser, InstrumentedConfigObj))
216
self.assertEqual(parser._calls, [('__init__', config.config_filename())])
222
219
class TestBranchConfig(TestCaseInTempDir):
322
319
self.assertRaises(TypeError, config.LocationConfig)
324
321
def test_branch_calls_read_filenames(self):
322
# This is testing the correct file names are provided.
323
# TODO: consolidate with the test for GlobalConfigs filename checks.
325
325
# replace the class that is constructured, to check its parameters
326
oldparserclass = config.ConfigParser
327
config.ConfigParser = InstrumentedConfigParser
326
oldparserclass = config.ConfigObj
327
config.ConfigObj = InstrumentedConfigObj
328
328
my_config = config.LocationConfig('http://www.example.com')
330
330
parser = my_config._get_parser()
332
config.ConfigParser = oldparserclass
333
self.failUnless(isinstance(parser, InstrumentedConfigParser))
334
self.assertEqual(parser._calls, [('read', [config.branches_config_filename()])])
332
config.ConfigObj = oldparserclass
333
self.failUnless(isinstance(parser, InstrumentedConfigObj))
334
self.assertEqual(parser._calls,
335
[('__init__', config.branches_config_filename())])
336
337
def test_get_global_config(self):
337
338
my_config = config.LocationConfig('http://example.com')