~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testconfig.py

  • Committer: Robert Collins
  • Date: 2005-10-20 04:08:12 UTC
  • mfrom: (1185.12.68)
  • Revision ID: robertc@robertcollins.net-20051020040812-fecd1bc32aa3478e
Merge from Aaron Bentley.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
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
22
22
import os
23
23
import sys
70
70
                        "#testing explicit beats globs\n")
71
71
 
72
72
 
73
 
class InstrumentedConfigParser(object):
74
 
    """A config parser look-enough-alike to record calls made to it."""
75
 
 
76
 
    def __init__(self):
77
 
        self._calls = []
78
 
 
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."""
 
75
 
 
76
    def __init__(self, input):
 
77
        self._calls = [('__init__', input)]
81
78
 
82
79
 
83
80
class FakeBranch(object):
192
189
        my_config = config.IniBasedConfig(None)
193
190
        self.failUnless(
194
191
            isinstance(my_config._get_parser(file=config_file),
195
 
                        ConfigParser))
 
192
                        ConfigObj))
196
193
 
197
194
    def test_cached(self):
198
195
        config_file = StringIO(sample_config_text)
208
205
 
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()
214
211
        try:
215
212
            parser = my_config._get_parser()
216
213
        finally:
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())])
220
217
 
221
218
 
222
219
class TestBranchConfig(TestCaseInTempDir):
322
319
        self.assertRaises(TypeError, config.LocationConfig)
323
320
 
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.
 
324
        #
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')
329
329
        try:
330
330
            parser = my_config._get_parser()
331
331
        finally:
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())])
335
336
 
336
337
    def test_get_global_config(self):
337
338
        my_config = config.LocationConfig('http://example.com')