~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Patch Queue Manager
  • Date: 2012-08-28 21:17:31 UTC
  • mfrom: (6555.1.2 post-mortem)
  • Revision ID: pqm@pqm.ubuntu.com-20120828211731-5di1tveevpzcdtd9
(jelmer) Remove compatibility code for python 2.4 for post mortem. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2014, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for finding and reading the bzr config file[s]."""
18
18
 
 
19
import base64
19
20
from cStringIO import StringIO
20
21
from textwrap import dedent
21
22
import os
448
449
        output = outfile.getvalue()
449
450
        # now we're trying to read it back
450
451
        co2 = config.ConfigObj(StringIO(output))
451
 
        self.assertEqual(triple_quotes_value, co2['test'])
 
452
        self.assertEquals(triple_quotes_value, co2['test'])
452
453
 
453
454
 
454
455
erroneous_config = """[section] # line 1
558
559
    def setUp(self):
559
560
        super(TestConfigPath, self).setUp()
560
561
        self.overrideEnv('HOME', '/home/bogus')
561
 
        self.overrideEnv('XDG_CACHE_HOME', '')
 
562
        self.overrideEnv('XDG_CACHE_DIR', '')
562
563
        if sys.platform == 'win32':
563
564
            self.overrideEnv(
564
565
                'BZR_HOME', r'C:\Documents and Settings\bogus\Application Data')
595
596
    # subdirectory of $XDG_CONFIG_HOME
596
597
 
597
598
    def setUp(self):
598
 
        if sys.platform == 'win32':
 
599
        if sys.platform in ('darwin', 'win32'):
599
600
            raise tests.TestNotApplicable(
600
601
                'XDG config dir not used on this platform')
601
602
        super(TestXDGConfigDir, self).setUp()
628
629
class TestIniConfigBuilding(TestIniConfig):
629
630
 
630
631
    def test_contructs(self):
631
 
        config.IniBasedConfig()
 
632
        my_config = config.IniBasedConfig()
632
633
 
633
634
    def test_from_fp(self):
634
635
        my_config = config.IniBasedConfig.from_string(sample_config_text)
649
650
        self.path = self.uid = self.gid = None
650
651
        conf = config.IniBasedConfig(file_name='./foo.conf')
651
652
        conf._write_config_file()
652
 
        self.assertEqual(self.path, './foo.conf')
 
653
        self.assertEquals(self.path, './foo.conf')
653
654
        self.assertTrue(isinstance(self.uid, int))
654
655
        self.assertTrue(isinstance(self.gid, int))
655
656
 
677
678
 
678
679
    def test_saved_with_content(self):
679
680
        content = 'foo = bar\n'
680
 
        config.IniBasedConfig.from_string(content, file_name='./test.conf',
681
 
                                          save=True)
 
681
        conf = config.IniBasedConfig.from_string(
 
682
            content, file_name='./test.conf', save=True)
682
683
        self.assertFileEqual(content, 'test.conf')
683
684
 
684
685
 
699
700
        return c
700
701
 
701
702
    def assertExpansion(self, expected, conf, string, env=None):
702
 
        self.assertEqual(expected, conf.expand_options(string, env))
 
703
        self.assertEquals(expected, conf.expand_options(string, env))
703
704
 
704
705
    def test_no_expansion(self):
705
706
        c = self.get_config('')
747
748
baz={foo}''')
748
749
        e = self.assertRaises(errors.OptionExpansionLoop,
749
750
                              c.expand_options, '{foo}')
750
 
        self.assertEqual('foo->bar->baz', e.refs)
751
 
        self.assertEqual('{foo}', e.string)
 
751
        self.assertEquals('foo->bar->baz', e.refs)
 
752
        self.assertEquals('{foo}', e.string)
752
753
 
753
754
    def test_list(self):
754
755
        conf = self.get_config('''
757
758
baz=end
758
759
list={foo},{bar},{baz}
759
760
''')
760
 
        self.assertEqual(['start', 'middle', 'end'],
 
761
        self.assertEquals(['start', 'middle', 'end'],
761
762
                           conf.get_user_option('list', expand=True))
762
763
 
763
764
    def test_cascading_list(self):
767
768
baz=end
768
769
list={foo}
769
770
''')
770
 
        self.assertEqual(['start', 'middle', 'end'],
 
771
        self.assertEquals(['start', 'middle', 'end'],
771
772
                           conf.get_user_option('list', expand=True))
772
773
 
773
774
    def test_pathological_hidden_list(self):
781
782
''')
782
783
        # Nope, it's either a string or a list, and the list wins as soon as a
783
784
        # ',' appears, so the string concatenation never occur.
784
 
        self.assertEqual(['{foo', '}', '{', 'bar}'],
 
785
        self.assertEquals(['{foo', '}', '{', 'bar}'],
785
786
                          conf.get_user_option('hidden', expand=True))
786
787
 
787
788
 
815
816
[/project/branch/path]
816
817
bar = {foo}ux
817
818
''')
818
 
        self.assertEqual('quux', c.get_user_option('bar', expand=True))
 
819
        self.assertEquals('quux', c.get_user_option('bar', expand=True))
819
820
 
820
821
 
821
822
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
861
862
        return c
862
863
 
863
864
    def test_simple_read_access(self):
864
 
        self.assertEqual('1', self.config.get_user_option('one'))
 
865
        self.assertEquals('1', self.config.get_user_option('one'))
865
866
 
866
867
    def test_simple_write_access(self):
867
868
        self.config.set_user_option('one', 'one')
868
 
        self.assertEqual('one', self.config.get_user_option('one'))
 
869
        self.assertEquals('one', self.config.get_user_option('one'))
869
870
 
870
871
    def test_listen_to_the_last_speaker(self):
871
872
        c1 = self.config
872
873
        c2 = self.get_existing_config()
873
874
        c1.set_user_option('one', 'ONE')
874
875
        c2.set_user_option('two', 'TWO')
875
 
        self.assertEqual('ONE', c1.get_user_option('one'))
876
 
        self.assertEqual('TWO', c2.get_user_option('two'))
 
876
        self.assertEquals('ONE', c1.get_user_option('one'))
 
877
        self.assertEquals('TWO', c2.get_user_option('two'))
877
878
        # The second update respect the first one
878
 
        self.assertEqual('ONE', c2.get_user_option('one'))
 
879
        self.assertEquals('ONE', c2.get_user_option('one'))
879
880
 
880
881
    def test_last_speaker_wins(self):
881
882
        # If the same config is not shared, the same variable modified twice
884
885
        c2 = self.get_existing_config()
885
886
        c1.set_user_option('one', 'c1')
886
887
        c2.set_user_option('one', 'c2')
887
 
        self.assertEqual('c2', c2._get_user_option('one'))
 
888
        self.assertEquals('c2', c2._get_user_option('one'))
888
889
        # The first modification is still available until another refresh
889
890
        # occur
890
 
        self.assertEqual('c1', c1._get_user_option('one'))
 
891
        self.assertEquals('c1', c1._get_user_option('one'))
891
892
        c1.set_user_option('two', 'done')
892
 
        self.assertEqual('c2', c1._get_user_option('one'))
 
893
        self.assertEquals('c2', c1._get_user_option('one'))
893
894
 
894
895
    def test_writes_are_serialized(self):
895
896
        c1 = self.config
920
921
        self.assertTrue(c1._lock.is_held)
921
922
        self.assertRaises(errors.LockContention,
922
923
                          c2.set_user_option, 'one', 'c2')
923
 
        self.assertEqual('c1', c1.get_user_option('one'))
 
924
        self.assertEquals('c1', c1.get_user_option('one'))
924
925
        # Let the lock be released
925
926
        after_writing.set()
926
927
        writing_done.wait()
927
928
        c2.set_user_option('one', 'c2')
928
 
        self.assertEqual('c2', c2.get_user_option('one'))
 
929
        self.assertEquals('c2', c2.get_user_option('one'))
929
930
 
930
931
    def test_read_while_writing(self):
931
932
       c1 = self.config
953
954
       # Ensure the thread is ready to write
954
955
       ready_to_write.wait()
955
956
       self.assertTrue(c1._lock.is_held)
956
 
       self.assertEqual('c1', c1.get_user_option('one'))
 
957
       self.assertEquals('c1', c1.get_user_option('one'))
957
958
       # If we read during the write, we get the old value
958
959
       c2 = self.get_existing_config()
959
 
       self.assertEqual('1', c2.get_user_option('one'))
 
960
       self.assertEquals('1', c2.get_user_option('one'))
960
961
       # Let the writing occur and ensure it occurred
961
962
       do_writing.set()
962
963
       writing_done.wait()
963
964
       # Now we get the updated value
964
965
       c3 = self.get_existing_config()
965
 
       self.assertEqual('c1', c3.get_user_option('one'))
 
966
       self.assertEquals('c1', c3.get_user_option('one'))
966
967
 
967
968
 
968
969
class TestGetUserOptionAs(TestIniConfig):
983
984
        self.overrideAttr(trace, 'warning', warning)
984
985
        msg = 'Value "%s" is not a boolean for "%s"'
985
986
        self.assertIs(None, get_bool('an_invalid_bool'))
986
 
        self.assertEqual(msg % ('maybe', 'an_invalid_bool'), warnings[0])
 
987
        self.assertEquals(msg % ('maybe', 'an_invalid_bool'), warnings[0])
987
988
        warnings = []
988
989
        self.assertIs(None, get_bool('not_defined_in_this_config'))
989
 
        self.assertEqual([], warnings)
 
990
        self.assertEquals([], warnings)
990
991
 
991
992
    def test_get_user_option_as_list(self):
992
993
        conf, parser = self.make_config_parser("""
1046
1047
class TestGetConfig(tests.TestCase):
1047
1048
 
1048
1049
    def test_constructs(self):
1049
 
        config.GlobalConfig()
 
1050
        my_config = config.GlobalConfig()
1050
1051
 
1051
1052
    def test_calls_read_filenames(self):
1052
1053
        # replace the class that is constructed, to check its parameters
1064
1065
 
1065
1066
class TestBranchConfig(tests.TestCaseWithTransport):
1066
1067
 
1067
 
    def test_constructs_valid(self):
 
1068
    def test_constructs(self):
1068
1069
        branch = FakeBranch()
1069
1070
        my_config = config.BranchConfig(branch)
1070
 
        self.assertIsNot(None, my_config)
1071
 
 
1072
 
    def test_constructs_error(self):
1073
1071
        self.assertRaises(TypeError, config.BranchConfig)
1074
1072
 
1075
1073
    def test_get_location_config(self):
1107
1105
        conf = config.LocationConfig.from_string(
1108
1106
            '[%s]\nnickname = foobar' % (local_url,),
1109
1107
            local_url, save=True)
1110
 
        self.assertIsNot(None, conf)
1111
1108
        self.assertEqual('foobar', branch.nick)
1112
1109
 
1113
1110
    def test_config_local_path(self):
1116
1113
        self.assertEqual('branch', branch.nick)
1117
1114
 
1118
1115
        local_path = osutils.getcwd().encode('utf8')
1119
 
        config.LocationConfig.from_string(
 
1116
        conf = config.LocationConfig.from_string(
1120
1117
            '[%s/branch]\nnickname = barry' % (local_path,),
1121
1118
            'branch',  save=True)
1122
 
        # Now the branch will find its nick via the location config
1123
1119
        self.assertEqual('barry', branch.nick)
1124
1120
 
1125
1121
    def test_config_creates_local(self):
1340
1336
    def test_find_merge_tool_known(self):
1341
1337
        conf = self._get_empty_config()
1342
1338
        cmdline = conf.find_merge_tool('kdiff3')
1343
 
        self.assertEqual('kdiff3 {base} {this} {other} -o {result}', cmdline)
 
1339
        self.assertEquals('kdiff3 {base} {this} {other} -o {result}', cmdline)
1344
1340
 
1345
1341
    def test_find_merge_tool_override_known(self):
1346
1342
        conf = self._get_empty_config()
1373
1369
 
1374
1370
class TestLocationConfig(tests.TestCaseInTempDir, TestOptionsMixin):
1375
1371
 
1376
 
    def test_constructs_valid(self):
1377
 
        config.LocationConfig('http://example.com')
1378
 
 
1379
 
    def test_constructs_error(self):
 
1372
    def test_constructs(self):
 
1373
        my_config = config.LocationConfig('http://example.com')
1380
1374
        self.assertRaises(TypeError, config.LocationConfig)
1381
1375
 
1382
1376
    def test_branch_calls_read_filenames(self):
1668
1662
        if location_config is None:
1669
1663
            location_config = sample_branches_text
1670
1664
 
1671
 
        config.GlobalConfig.from_string(global_config, save=True)
1672
 
        config.LocationConfig.from_string(location_config, my_branch.base,
1673
 
                                          save=True)
 
1665
        my_global_config = config.GlobalConfig.from_string(global_config,
 
1666
                                                           save=True)
 
1667
        my_location_config = config.LocationConfig.from_string(
 
1668
            location_config, my_branch.base, save=True)
1674
1669
        my_config = config.BranchConfig(my_branch)
1675
1670
        self.my_config = my_config
1676
1671
        self.my_location_config = my_config._get_location_config()
1741
1736
                          location_config=None, branch_data_config=None):
1742
1737
        my_branch = FakeBranch(location)
1743
1738
        if global_config is not None:
1744
 
            config.GlobalConfig.from_string(global_config, save=True)
 
1739
            my_global_config = config.GlobalConfig.from_string(global_config,
 
1740
                                                               save=True)
1745
1741
        if location_config is not None:
1746
 
            config.LocationConfig.from_string(location_config, my_branch.base,
1747
 
                                              save=True)
 
1742
            my_location_config = config.LocationConfig.from_string(
 
1743
                location_config, my_branch.base, save=True)
1748
1744
        my_config = config.BranchConfig(my_branch)
1749
1745
        if branch_data_config is not None:
1750
1746
            my_config.branch.control_files.files['branch.conf'] = \
1906
1902
        # Store the raw content in the config file
1907
1903
        t.put_bytes('foo.conf', utf8_content)
1908
1904
        conf = config.TransportConfig(t, 'foo.conf')
1909
 
        self.assertEqual(unicode_user, conf.get_option('user'))
 
1905
        self.assertEquals(unicode_user, conf.get_option('user'))
1910
1906
 
1911
1907
    def test_load_non_ascii(self):
1912
1908
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
1940
1936
        cfg = config.TransportConfig(
1941
1937
            DenyingTransport("nonexisting://"), 'control.conf')
1942
1938
        self.assertIs(None, cfg.get_option('non-existant', 'SECTION'))
1943
 
        self.assertEqual(
 
1939
        self.assertEquals(
1944
1940
            warnings,
1945
1941
            [u'Permission denied while trying to open configuration file '
1946
1942
             u'nonexisting:///control.conf.'])
1998
1994
            config.OldConfigHooks.uninstall_named_hook, 'get', None)
1999
1995
        self.assertLength(0, calls)
2000
1996
        actual_value = conf.get_user_option(name)
2001
 
        self.assertEqual(value, actual_value)
 
1997
        self.assertEquals(value, actual_value)
2002
1998
        self.assertLength(1, calls)
2003
 
        self.assertEqual((conf, name, value), calls[0])
 
1999
        self.assertEquals((conf, name, value), calls[0])
2004
2000
 
2005
2001
    def test_get_hook_bazaar(self):
2006
2002
        self.assertGetHook(self.bazaar_config, 'file', 'bazaar')
2026
2022
        # We can't assert the conf object below as different configs use
2027
2023
        # different means to implement set_user_option and we care only about
2028
2024
        # coverage here.
2029
 
        self.assertEqual((name, value), calls[0][1:])
 
2025
        self.assertEquals((name, value), calls[0][1:])
2030
2026
 
2031
2027
    def test_set_hook_bazaar(self):
2032
2028
        self.assertSetHook(self.bazaar_config, 'foo', 'bazaar')
2050
2046
        # We can't assert the conf object below as different configs use
2051
2047
        # different means to implement remove_user_option and we care only about
2052
2048
        # coverage here.
2053
 
        self.assertEqual((name,), calls[0][1:])
 
2049
        self.assertEquals((name,), calls[0][1:])
2054
2050
 
2055
2051
    def test_remove_hook_bazaar(self):
2056
2052
        self.assertRemoveHook(self.bazaar_config, 'file')
2129
2125
            config.OldConfigHooks.uninstall_named_hook, 'get', None)
2130
2126
        self.assertLength(0, calls)
2131
2127
        actual_value = conf.get_option(name)
2132
 
        self.assertEqual(value, actual_value)
 
2128
        self.assertEquals(value, actual_value)
2133
2129
        self.assertLength(1, calls)
2134
 
        self.assertEqual((conf, name, value), calls[0])
 
2130
        self.assertEquals((conf, name, value), calls[0])
2135
2131
 
2136
2132
    def test_get_hook_remote_branch(self):
2137
2133
        remote_branch = branch.Branch.open(self.get_url('tree'))
2156
2152
        # We can't assert the conf object below as different configs use
2157
2153
        # different means to implement set_user_option and we care only about
2158
2154
        # coverage here.
2159
 
        self.assertEqual((name, value), calls[0][1:])
 
2155
        self.assertEquals((name, value), calls[0][1:])
2160
2156
 
2161
2157
    def test_set_hook_remote_branch(self):
2162
2158
        remote_branch = branch.Branch.open(self.get_url('tree'))
2224
2220
        self.assertSaveHook(remote_bzrdir._get_config())
2225
2221
 
2226
2222
 
2227
 
class TestOptionNames(tests.TestCase):
2228
 
 
2229
 
    def is_valid(self, name):
2230
 
        return config._option_ref_re.match('{%s}' % name) is not None
2231
 
 
2232
 
    def test_valid_names(self):
2233
 
        self.assertTrue(self.is_valid('foo'))
2234
 
        self.assertTrue(self.is_valid('foo.bar'))
2235
 
        self.assertTrue(self.is_valid('f1'))
2236
 
        self.assertTrue(self.is_valid('_'))
2237
 
        self.assertTrue(self.is_valid('__bar__'))
2238
 
        self.assertTrue(self.is_valid('a_'))
2239
 
        self.assertTrue(self.is_valid('a1'))
2240
 
        # Don't break bzr-svn for no good reason
2241
 
        self.assertTrue(self.is_valid('guessed-layout'))
2242
 
 
2243
 
    def test_invalid_names(self):
2244
 
        self.assertFalse(self.is_valid(' foo'))
2245
 
        self.assertFalse(self.is_valid('foo '))
2246
 
        self.assertFalse(self.is_valid('1'))
2247
 
        self.assertFalse(self.is_valid('1,2'))
2248
 
        self.assertFalse(self.is_valid('foo$'))
2249
 
        self.assertFalse(self.is_valid('!foo'))
2250
 
        self.assertFalse(self.is_valid('foo.'))
2251
 
        self.assertFalse(self.is_valid('foo..bar'))
2252
 
        self.assertFalse(self.is_valid('{}'))
2253
 
        self.assertFalse(self.is_valid('{a}'))
2254
 
        self.assertFalse(self.is_valid('a\n'))
2255
 
        self.assertFalse(self.is_valid('-'))
2256
 
        self.assertFalse(self.is_valid('-a'))
2257
 
        self.assertFalse(self.is_valid('a-'))
2258
 
        self.assertFalse(self.is_valid('a--a'))
2259
 
 
2260
 
    def assertSingleGroup(self, reference):
2261
 
        # the regexp is used with split and as such should match the reference
2262
 
        # *only*, if more groups needs to be defined, (?:...) should be used.
2263
 
        m = config._option_ref_re.match('{a}')
2264
 
        self.assertLength(1, m.groups())
2265
 
 
2266
 
    def test_valid_references(self):
2267
 
        self.assertSingleGroup('{a}')
2268
 
        self.assertSingleGroup('{{a}}')
2269
 
 
2270
 
 
2271
2223
class TestOption(tests.TestCase):
2272
2224
 
2273
2225
    def test_default_value(self):
2274
2226
        opt = config.Option('foo', default='bar')
2275
 
        self.assertEqual('bar', opt.get_default())
 
2227
        self.assertEquals('bar', opt.get_default())
2276
2228
 
2277
2229
    def test_callable_default_value(self):
2278
2230
        def bar_as_unicode():
2279
2231
            return u'bar'
2280
2232
        opt = config.Option('foo', default=bar_as_unicode)
2281
 
        self.assertEqual('bar', opt.get_default())
 
2233
        self.assertEquals('bar', opt.get_default())
2282
2234
 
2283
2235
    def test_default_value_from_env(self):
2284
2236
        opt = config.Option('foo', default='bar', default_from_env=['FOO'])
2285
2237
        self.overrideEnv('FOO', 'quux')
2286
2238
        # Env variable provides a default taking over the option one
2287
 
        self.assertEqual('quux', opt.get_default())
 
2239
        self.assertEquals('quux', opt.get_default())
2288
2240
 
2289
2241
    def test_first_default_value_from_env_wins(self):
2290
2242
        opt = config.Option('foo', default='bar',
2292
2244
        self.overrideEnv('FOO', 'foo')
2293
2245
        self.overrideEnv('BAZ', 'baz')
2294
2246
        # The first env var set wins
2295
 
        self.assertEqual('foo', opt.get_default())
 
2247
        self.assertEquals('foo', opt.get_default())
2296
2248
 
2297
2249
    def test_not_supported_list_default_value(self):
2298
2250
        self.assertRaises(AssertionError, config.Option, 'foo', default=[1])
2309
2261
 
2310
2262
    def test_get_help_topic(self):
2311
2263
        opt = config.Option('foo')
2312
 
        self.assertEqual('foo', opt.get_help_topic())
2313
 
 
2314
 
 
2315
 
class TestOptionConverter(tests.TestCase):
 
2264
        self.assertEquals('foo', opt.get_help_topic())
 
2265
 
 
2266
 
 
2267
class TestOptionConverterMixin(object):
2316
2268
 
2317
2269
    def assertConverted(self, expected, opt, value):
2318
 
        self.assertEqual(expected, opt.convert_from_unicode(None, value))
 
2270
        self.assertEquals(expected, opt.convert_from_unicode(None, value))
2319
2271
 
2320
 
    def assertCallsWarning(self, opt, value):
 
2272
    def assertWarns(self, opt, value):
2321
2273
        warnings = []
2322
 
 
2323
2274
        def warning(*args):
2324
2275
            warnings.append(args[0] % args[1:])
2325
2276
        self.overrideAttr(trace, 'warning', warning)
2326
 
        self.assertEqual(None, opt.convert_from_unicode(None, value))
 
2277
        self.assertEquals(None, opt.convert_from_unicode(None, value))
2327
2278
        self.assertLength(1, warnings)
2328
 
        self.assertEqual(
 
2279
        self.assertEquals(
2329
2280
            'Value "%s" is not valid for "%s"' % (value, opt.name),
2330
2281
            warnings[0])
2331
2282
 
2332
 
    def assertCallsError(self, opt, value):
 
2283
    def assertErrors(self, opt, value):
2333
2284
        self.assertRaises(errors.ConfigOptionValueError,
2334
2285
                          opt.convert_from_unicode, None, value)
2335
2286
 
2336
2287
    def assertConvertInvalid(self, opt, invalid_value):
2337
2288
        opt.invalid = None
2338
 
        self.assertEqual(None, opt.convert_from_unicode(None, invalid_value))
 
2289
        self.assertEquals(None, opt.convert_from_unicode(None, invalid_value))
2339
2290
        opt.invalid = 'warning'
2340
 
        self.assertCallsWarning(opt, invalid_value)
 
2291
        self.assertWarns(opt, invalid_value)
2341
2292
        opt.invalid = 'error'
2342
 
        self.assertCallsError(opt, invalid_value)
2343
 
 
2344
 
 
2345
 
class TestOptionWithBooleanConverter(TestOptionConverter):
 
2293
        self.assertErrors(opt, invalid_value)
 
2294
 
 
2295
 
 
2296
class TestOptionWithBooleanConverter(tests.TestCase, TestOptionConverterMixin):
2346
2297
 
2347
2298
    def get_option(self):
2348
2299
        return config.Option('foo', help='A boolean.',
2362
2313
        self.assertConverted(False, opt, u'False')
2363
2314
 
2364
2315
 
2365
 
class TestOptionWithIntegerConverter(TestOptionConverter):
 
2316
class TestOptionWithIntegerConverter(tests.TestCase, TestOptionConverterMixin):
2366
2317
 
2367
2318
    def get_option(self):
2368
2319
        return config.Option('foo', help='An integer.',
2380
2331
        self.assertConverted(16, opt, u'16')
2381
2332
 
2382
2333
 
2383
 
class TestOptionWithSIUnitConverter(TestOptionConverter):
 
2334
class TestOptionWithSIUnitConverter(tests.TestCase, TestOptionConverterMixin):
2384
2335
 
2385
2336
    def get_option(self):
2386
2337
        return config.Option('foo', help='An integer in SI units.',
2389
2340
    def test_convert_invalid(self):
2390
2341
        opt = self.get_option()
2391
2342
        self.assertConvertInvalid(opt, u'not-a-unit')
2392
 
        self.assertConvertInvalid(opt, u'Gb')  # Forgot the value
2393
 
        self.assertConvertInvalid(opt, u'1b')  # Forgot the unit
 
2343
        self.assertConvertInvalid(opt, u'Gb') # Forgot the int
 
2344
        self.assertConvertInvalid(opt, u'1b') # Forgot the unit
2394
2345
        self.assertConvertInvalid(opt, u'1GG')
2395
2346
        self.assertConvertInvalid(opt, u'1Mbb')
2396
2347
        self.assertConvertInvalid(opt, u'1MM')
2405
2356
        self.assertConverted(100, opt, u'100')
2406
2357
 
2407
2358
 
2408
 
class TestListOption(TestOptionConverter):
 
2359
class TestListOption(tests.TestCase, TestOptionConverterMixin):
2409
2360
 
2410
2361
    def get_option(self):
2411
2362
        return config.ListOption('foo', help='A list.')
2420
2371
    def test_convert_valid(self):
2421
2372
        opt = self.get_option()
2422
2373
        # An empty string is an empty list
2423
 
        self.assertConverted([], opt, '')  # Using a bare str() just in case
 
2374
        self.assertConverted([], opt, '') # Using a bare str() just in case
2424
2375
        self.assertConverted([], opt, u'')
2425
2376
        # A boolean
2426
2377
        self.assertConverted([u'True'], opt, u'True')
2430
2381
        self.assertConverted([u'bar'], opt, u'bar')
2431
2382
 
2432
2383
 
2433
 
class TestRegistryOption(TestOptionConverter):
 
2384
class TestRegistryOption(tests.TestCase, TestOptionConverterMixin):
2434
2385
 
2435
2386
    def get_option(self, registry):
2436
2387
        return config.RegistryOption('foo', registry,
2437
 
                                     help='A registry option.')
 
2388
                help='A registry option.')
2438
2389
 
2439
2390
    def test_convert_invalid(self):
2440
2391
        registry = _mod_registry.Registry()
2456
2407
        registry.register("someval", 1234, help="some option")
2457
2408
        registry.register("dunno", 1234, help="some other option")
2458
2409
        opt = self.get_option(registry)
2459
 
        self.assertEqual(
 
2410
        self.assertEquals(
2460
2411
            'A registry option.\n'
2461
2412
            '\n'
2462
2413
            'The following values are supported:\n'
2469
2420
        registry.register("someval", 1234, help="some option")
2470
2421
        registry.register("dunno", 1234, help="some other option")
2471
2422
        opt = self.get_option(registry)
2472
 
        self.assertEqual(
 
2423
        self.assertEquals(
2473
2424
            'A registry option.\n'
2474
2425
            '\n'
2475
2426
            'The following values are supported:\n'
2494
2445
    def test_registered_help(self):
2495
2446
        opt = config.Option('foo', help='A simple option')
2496
2447
        self.registry.register(opt)
2497
 
        self.assertEqual('A simple option', self.registry.get_help('foo'))
2498
 
 
2499
 
    def test_dont_register_illegal_name(self):
2500
 
        self.assertRaises(errors.IllegalOptionName,
2501
 
                          self.registry.register, config.Option(' foo'))
2502
 
        self.assertRaises(errors.IllegalOptionName,
2503
 
                          self.registry.register, config.Option('bar,'))
 
2448
        self.assertEquals('A simple option', self.registry.get_help('foo'))
2504
2449
 
2505
2450
    lazy_option = config.Option('lazy_foo', help='Lazy help')
2506
2451
 
2512
2457
    def test_registered_lazy_help(self):
2513
2458
        self.registry.register_lazy('lazy_foo', self.__module__,
2514
2459
                                    'TestOptionRegistry.lazy_option')
2515
 
        self.assertEqual('Lazy help', self.registry.get_help('lazy_foo'))
2516
 
 
2517
 
    def test_dont_lazy_register_illegal_name(self):
2518
 
        # This is where the root cause of http://pad.lv/1235099 is better
2519
 
        # understood: 'register_lazy' doc string mentions that key should match
2520
 
        # the option name which indirectly requires that the option name is a
2521
 
        # valid python identifier. We violate that rule here (using a key that
2522
 
        # doesn't match the option name) to test the option name checking.
2523
 
        self.assertRaises(errors.IllegalOptionName,
2524
 
                          self.registry.register_lazy, ' foo', self.__module__,
2525
 
                          'TestOptionRegistry.lazy_option')
2526
 
        self.assertRaises(errors.IllegalOptionName,
2527
 
                          self.registry.register_lazy, '1,2', self.__module__,
2528
 
                          'TestOptionRegistry.lazy_option')
 
2460
        self.assertEquals('Lazy help', self.registry.get_help('lazy_foo'))
2529
2461
 
2530
2462
 
2531
2463
class TestRegisteredOptions(tests.TestCase):
2541
2473
    def test_proper_name(self):
2542
2474
        # An option should be registered under its own name, this can't be
2543
2475
        # checked at registration time for the lazy ones.
2544
 
        self.assertEqual(self.option_name, self.option.name)
 
2476
        self.assertEquals(self.option_name, self.option.name)
2545
2477
 
2546
2478
    def test_help_is_set(self):
2547
2479
        option_help = self.registry.get_help(self.option_name)
2548
2480
        # Come on, think about the user, he really wants to know what the
2549
2481
        # option is about
2550
2482
        self.assertIsNot(None, option_help)
2551
 
        self.assertNotEqual('', option_help)
 
2483
        self.assertNotEquals('', option_help)
2552
2484
 
2553
2485
 
2554
2486
class TestSection(tests.TestCase):
2559
2491
    def test_get_a_value(self):
2560
2492
        a_dict = dict(foo='bar')
2561
2493
        section = config.Section('myID', a_dict)
2562
 
        self.assertEqual('bar', section.get('foo'))
 
2494
        self.assertEquals('bar', section.get('foo'))
2563
2495
 
2564
2496
    def test_get_unknown_option(self):
2565
2497
        a_dict = dict()
2566
2498
        section = config.Section(None, a_dict)
2567
 
        self.assertEqual('out of thin air',
 
2499
        self.assertEquals('out of thin air',
2568
2500
                          section.get('foo', 'out of thin air'))
2569
2501
 
2570
2502
    def test_options_is_shared(self):
2584
2516
        a_dict = dict(foo='bar')
2585
2517
        section = self.get_section(a_dict)
2586
2518
        section.set('foo', 'new_value')
2587
 
        self.assertEqual('new_value', section.get('foo'))
 
2519
        self.assertEquals('new_value', section.get('foo'))
2588
2520
        # The change appears in the shared section
2589
 
        self.assertEqual('new_value', a_dict.get('foo'))
 
2521
        self.assertEquals('new_value', a_dict.get('foo'))
2590
2522
        # We keep track of the change
2591
2523
        self.assertTrue('foo' in section.orig)
2592
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2524
        self.assertEquals('bar', section.orig.get('foo'))
2593
2525
 
2594
2526
    def test_set_preserve_original_once(self):
2595
2527
        a_dict = dict(foo='bar')
2598
2530
        section.set('foo', 'second_value')
2599
2531
        # We keep track of the original value
2600
2532
        self.assertTrue('foo' in section.orig)
2601
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2533
        self.assertEquals('bar', section.orig.get('foo'))
2602
2534
 
2603
2535
    def test_remove(self):
2604
2536
        a_dict = dict(foo='bar')
2605
2537
        section = self.get_section(a_dict)
2606
2538
        section.remove('foo')
2607
2539
        # We get None for unknown options via the default value
2608
 
        self.assertEqual(None, section.get('foo'))
 
2540
        self.assertEquals(None, section.get('foo'))
2609
2541
        # Or we just get the default value
2610
 
        self.assertEqual('unknown', section.get('foo', 'unknown'))
 
2542
        self.assertEquals('unknown', section.get('foo', 'unknown'))
2611
2543
        self.assertFalse('foo' in section.options)
2612
2544
        # We keep track of the deletion
2613
2545
        self.assertTrue('foo' in section.orig)
2614
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2546
        self.assertEquals('bar', section.orig.get('foo'))
2615
2547
 
2616
2548
    def test_remove_new_option(self):
2617
2549
        a_dict = dict()
2622
2554
        # The option didn't exist initially so it we need to keep track of it
2623
2555
        # with a special value
2624
2556
        self.assertTrue('foo' in section.orig)
2625
 
        self.assertEqual(config._NewlyCreatedOption, section.orig['foo'])
 
2557
        self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2626
2558
 
2627
2559
 
2628
2560
class TestCommandLineStore(tests.TestCase):
2637
2569
        sections = list(self.store.get_sections())
2638
2570
        self.assertLength(1, sections)
2639
2571
        store, section = sections[0]
2640
 
        self.assertEqual(self.store, store)
 
2572
        self.assertEquals(self.store, store)
2641
2573
        return section
2642
2574
 
2643
2575
    def test_no_override(self):
2664
2596
    def test_multiple_overrides(self):
2665
2597
        self.store._from_cmdline(['a=b', 'x=y'])
2666
2598
        section = self.get_section()
2667
 
        self.assertEqual('b', section.get('a'))
2668
 
        self.assertEqual('y', section.get('x'))
 
2599
        self.assertEquals('b', section.get('a'))
 
2600
        self.assertEquals('y', section.get('x'))
2669
2601
 
2670
2602
    def test_wrong_syntax(self):
2671
2603
        self.assertRaises(errors.BzrCommandError,
2691
2623
    def assertSectionContent(self, expected, (store, section)):
2692
2624
        """Assert that some options have the proper values in a section."""
2693
2625
        expected_name, expected_options = expected
2694
 
        self.assertEqual(expected_name, section.id)
2695
 
        self.assertEqual(
 
2626
        self.assertEquals(expected_name, section.id)
 
2627
        self.assertEquals(
2696
2628
            expected_options,
2697
2629
            dict([(k, section.get(k)) for k in expected_options.keys()]))
2698
2630
 
2704
2636
 
2705
2637
    def test_building_delays_load(self):
2706
2638
        store = self.get_store(self)
2707
 
        self.assertEqual(False, store.is_loaded())
 
2639
        self.assertEquals(False, store.is_loaded())
2708
2640
        store._load_from_string('')
2709
 
        self.assertEqual(True, store.is_loaded())
 
2641
        self.assertEquals(True, store.is_loaded())
2710
2642
 
2711
2643
    def test_get_no_sections_for_empty(self):
2712
2644
        store = self.get_store(self)
2713
2645
        store._load_from_string('')
2714
 
        self.assertEqual([], list(store.get_sections()))
 
2646
        self.assertEquals([], list(store.get_sections()))
2715
2647
 
2716
2648
    def test_get_default_section(self):
2717
2649
        store = self.get_store(self)
2752
2684
 
2753
2685
        :param s: A string, quoted if required.
2754
2686
        """
2755
 
        self.assertEqual(s, self.store.quote(self.store.unquote(s)))
2756
 
        self.assertEqual(s, self.store.unquote(self.store.quote(s)))
 
2687
        self.assertEquals(s, self.store.quote(self.store.unquote(s)))
 
2688
        self.assertEquals(s, self.store.unquote(self.store.quote(s)))
2757
2689
 
2758
2690
    def test_empty_string(self):
2759
2691
        if isinstance(self.store, config.IniFileStore):
2797
2729
        value = conf.get('a_section')
2798
2730
        # Urgh, despite 'conf' asking for the no-name section, we get the
2799
2731
        # content of another section as a dict o_O
2800
 
        self.assertEqual({'a': '1'}, value)
 
2732
        self.assertEquals({'a': '1'}, value)
2801
2733
        unquoted = conf.store.unquote(value)
2802
2734
        # Which cannot be unquoted but shouldn't crash either (the use cases
2803
2735
        # are getting the value or displaying it. In the later case, '%s' will
2804
2736
        # do).
2805
 
        self.assertEqual({'a': '1'}, unquoted)
2806
 
        self.assertEqual("{u'a': u'1'}", '%s' % (unquoted,))
 
2737
        self.assertEquals({'a': '1'}, unquoted)
 
2738
        self.assertEquals("{u'a': u'1'}", '%s' % (unquoted,))
2807
2739
 
2808
2740
 
2809
2741
class TestIniFileStoreContent(tests.TestCaseWithTransport):
2829
2761
        store = config.TransportIniFileStore(t, 'foo.conf')
2830
2762
        store.load()
2831
2763
        stack = config.Stack([store.get_sections], store)
2832
 
        self.assertEqual(unicode_user, stack.get('user'))
 
2764
        self.assertEquals(unicode_user, stack.get('user'))
2833
2765
 
2834
2766
    def test_load_non_ascii(self):
2835
2767
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2859
2791
        t.get_bytes = get_bytes
2860
2792
        store = config.TransportIniFileStore(t, 'foo.conf')
2861
2793
        self.assertRaises(errors.PermissionDenied, store.load)
2862
 
        self.assertEqual(
 
2794
        self.assertEquals(
2863
2795
            warnings,
2864
2796
            [u'Permission denied while trying to load configuration store %s.'
2865
2797
             % store.external_url()])
2886
2818
        with open('foo.conf', 'wb') as f:
2887
2819
            f.write(utf8_content)
2888
2820
        conf = config.IniBasedConfig(file_name='foo.conf')
2889
 
        self.assertEqual(unicode_user, conf.get_user_option('user'))
 
2821
        self.assertEquals(unicode_user, conf.get_user_option('user'))
2890
2822
 
2891
2823
    def test_load_badly_encoded_content(self):
2892
2824
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2925
2857
                'branch.conf is *always* created when a branch is initialized')
2926
2858
        store = self.get_store(self)
2927
2859
        store.save()
2928
 
        self.assertEqual(False, self.has_store(store))
 
2860
        self.assertEquals(False, self.has_store(store))
2929
2861
 
2930
2862
    def test_mutable_section_shared(self):
2931
2863
        store = self.get_store(self)
2952
2884
        section = store.get_mutable_section(None)
2953
2885
        section.remove('foo')
2954
2886
        store.save()
2955
 
        self.assertEqual(True, self.has_store(store))
 
2887
        self.assertEquals(True, self.has_store(store))
2956
2888
        modified_store = self.get_store(self)
2957
2889
        sections = list(modified_store.get_sections())
2958
2890
        self.assertLength(0, sections)
2965
2897
                'branch.conf is *always* created when a branch is initialized')
2966
2898
        store = self.get_store(self)
2967
2899
        store._load_from_string('foo=bar\n')
2968
 
        self.assertEqual(False, self.has_store(store))
 
2900
        self.assertEquals(False, self.has_store(store))
2969
2901
        store.save()
2970
 
        self.assertEqual(True, self.has_store(store))
 
2902
        self.assertEquals(True, self.has_store(store))
2971
2903
        modified_store = self.get_store(self)
2972
2904
        sections = list(modified_store.get_sections())
2973
2905
        self.assertLength(1, sections)
3040
2972
        self.assertLength(0, calls)
3041
2973
        store.load()
3042
2974
        self.assertLength(1, calls)
3043
 
        self.assertEqual((store,), calls[0])
 
2975
        self.assertEquals((store,), calls[0])
3044
2976
 
3045
2977
    def test_save_hook(self):
3046
2978
        calls = []
3058
2990
        section.set('foo', 'bar')
3059
2991
        store.save()
3060
2992
        self.assertLength(1, calls)
3061
 
        self.assertEqual((store,), calls[0])
 
2993
        self.assertEquals((store,), calls[0])
3062
2994
 
3063
2995
    def test_set_mark_dirty(self):
3064
2996
        stack = config.MemoryStack('')
3103
3035
    def test_no_changes_no_save(self):
3104
3036
        s = self.get_stack(self.st1)
3105
3037
        s.store.save_changes()
3106
 
        self.assertEqual(False, self.has_store(self.st1))
 
3038
        self.assertEquals(False, self.has_store(self.st1))
3107
3039
 
3108
3040
    def test_unrelated_concurrent_update(self):
3109
3041
        s1 = self.get_stack(self.st1)
3112
3044
        s2.set('baz', 'quux')
3113
3045
        s1.store.save()
3114
3046
        # Changes don't propagate magically
3115
 
        self.assertEqual(None, s1.get('baz'))
 
3047
        self.assertEquals(None, s1.get('baz'))
3116
3048
        s2.store.save_changes()
3117
 
        self.assertEqual('quux', s2.get('baz'))
 
3049
        self.assertEquals('quux', s2.get('baz'))
3118
3050
        # Changes are acquired when saving
3119
 
        self.assertEqual('bar', s2.get('foo'))
 
3051
        self.assertEquals('bar', s2.get('foo'))
3120
3052
        # Since there is no overlap, no warnings are emitted
3121
3053
        self.assertLength(0, self.warnings)
3122
3054
 
3128
3060
        s1.store.save()
3129
3061
        # Last speaker wins
3130
3062
        s2.store.save_changes()
3131
 
        self.assertEqual('baz', s2.get('foo'))
 
3063
        self.assertEquals('baz', s2.get('foo'))
3132
3064
        # But the user get a warning
3133
3065
        self.assertLength(1, self.warnings)
3134
3066
        warning = self.warnings[0]
3164
3096
        store = self.get_store()
3165
3097
        store._load_from_string('foo= " abc "')
3166
3098
        stack = config.Stack([store.get_sections])
3167
 
        self.assertEqual(' abc ', stack.get('foo'))
 
3099
        self.assertEquals(' abc ', stack.get('foo'))
3168
3100
 
3169
3101
    def test_set_quoted_string(self):
3170
3102
        store = self.get_store()
3183
3115
 
3184
3116
    def test_invalid_content(self):
3185
3117
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
3186
 
        self.assertEqual(False, store.is_loaded())
 
3118
        self.assertEquals(False, store.is_loaded())
3187
3119
        exc = self.assertRaises(
3188
3120
            errors.ParseConfigError, store._load_from_string,
3189
3121
            'this is invalid !')
3190
3122
        self.assertEndsWith(exc.filename, 'foo.conf')
3191
3123
        # And the load failed
3192
 
        self.assertEqual(False, store.is_loaded())
 
3124
        self.assertEquals(False, store.is_loaded())
3193
3125
 
3194
3126
    def test_get_embedded_sections(self):
3195
3127
        # A more complicated example (which also shows that section names and
3262
3194
        self.stack.store.save()
3263
3195
 
3264
3196
    def test_simple_read_access(self):
3265
 
        self.assertEqual('1', self.stack.get('one'))
 
3197
        self.assertEquals('1', self.stack.get('one'))
3266
3198
 
3267
3199
    def test_simple_write_access(self):
3268
3200
        self.stack.set('one', 'one')
3269
 
        self.assertEqual('one', self.stack.get('one'))
 
3201
        self.assertEquals('one', self.stack.get('one'))
3270
3202
 
3271
3203
    def test_listen_to_the_last_speaker(self):
3272
3204
        c1 = self.stack
3273
3205
        c2 = self.get_stack(self)
3274
3206
        c1.set('one', 'ONE')
3275
3207
        c2.set('two', 'TWO')
3276
 
        self.assertEqual('ONE', c1.get('one'))
3277
 
        self.assertEqual('TWO', c2.get('two'))
 
3208
        self.assertEquals('ONE', c1.get('one'))
 
3209
        self.assertEquals('TWO', c2.get('two'))
3278
3210
        # The second update respect the first one
3279
 
        self.assertEqual('ONE', c2.get('one'))
 
3211
        self.assertEquals('ONE', c2.get('one'))
3280
3212
 
3281
3213
    def test_last_speaker_wins(self):
3282
3214
        # If the same config is not shared, the same variable modified twice
3285
3217
        c2 = self.get_stack(self)
3286
3218
        c1.set('one', 'c1')
3287
3219
        c2.set('one', 'c2')
3288
 
        self.assertEqual('c2', c2.get('one'))
 
3220
        self.assertEquals('c2', c2.get('one'))
3289
3221
        # The first modification is still available until another refresh
3290
3222
        # occur
3291
 
        self.assertEqual('c1', c1.get('one'))
 
3223
        self.assertEquals('c1', c1.get('one'))
3292
3224
        c1.set('two', 'done')
3293
 
        self.assertEqual('c2', c1.get('one'))
 
3225
        self.assertEquals('c2', c1.get('one'))
3294
3226
 
3295
3227
    def test_writes_are_serialized(self):
3296
3228
        c1 = self.stack
3320
3252
        before_writing.wait()
3321
3253
        self.assertRaises(errors.LockContention,
3322
3254
                          c2.set, 'one', 'c2')
3323
 
        self.assertEqual('c1', c1.get('one'))
 
3255
        self.assertEquals('c1', c1.get('one'))
3324
3256
        # Let the lock be released
3325
3257
        after_writing.set()
3326
3258
        writing_done.wait()
3327
3259
        c2.set('one', 'c2')
3328
 
        self.assertEqual('c2', c2.get('one'))
 
3260
        self.assertEquals('c2', c2.get('one'))
3329
3261
 
3330
3262
    def test_read_while_writing(self):
3331
3263
       c1 = self.stack
3353
3285
       t1.start()
3354
3286
       # Ensure the thread is ready to write
3355
3287
       ready_to_write.wait()
3356
 
       self.assertEqual('c1', c1.get('one'))
 
3288
       self.assertEquals('c1', c1.get('one'))
3357
3289
       # If we read during the write, we get the old value
3358
3290
       c2 = self.get_stack(self)
3359
 
       self.assertEqual('1', c2.get('one'))
 
3291
       self.assertEquals('1', c2.get('one'))
3360
3292
       # Let the writing occur and ensure it occurred
3361
3293
       do_writing.set()
3362
3294
       writing_done.wait()
3363
3295
       # Now we get the updated value
3364
3296
       c3 = self.get_stack(self)
3365
 
       self.assertEqual('c1', c3.get('one'))
 
3297
       self.assertEquals('c1', c3.get('one'))
3366
3298
 
3367
3299
    # FIXME: It may be worth looking into removing the lock dir when it's not
3368
3300
    # needed anymore and look at possible fallouts for concurrent lockers. This
3384
3316
        store = self.get_store(self)
3385
3317
        store._load_from_string('')
3386
3318
        matcher = self.matcher(store, '/bar')
3387
 
        self.assertEqual([], list(matcher.get_sections()))
 
3319
        self.assertEquals([], list(matcher.get_sections()))
3388
3320
 
3389
3321
    def test_build_doesnt_load_store(self):
3390
3322
        store = self.get_store(self)
3391
 
        self.matcher(store, '/bar')
 
3323
        matcher = self.matcher(store, '/bar')
3392
3324
        self.assertFalse(store.is_loaded())
3393
3325
 
3394
3326
 
3400
3332
 
3401
3333
    def test_simple_option(self):
3402
3334
        section = self.get_section({'foo': 'bar'}, '')
3403
 
        self.assertEqual('bar', section.get('foo'))
 
3335
        self.assertEquals('bar', section.get('foo'))
3404
3336
 
3405
3337
    def test_option_with_extra_path(self):
3406
3338
        section = self.get_section({'foo': 'bar', 'foo:policy': 'appendpath'},
3407
3339
                                   'baz')
3408
 
        self.assertEqual('bar/baz', section.get('foo'))
 
3340
        self.assertEquals('bar/baz', section.get('foo'))
3409
3341
 
3410
3342
    def test_invalid_policy(self):
3411
3343
        section = self.get_section({'foo': 'bar', 'foo:policy': 'die'},
3412
3344
                                   'baz')
3413
3345
        # invalid policies are ignored
3414
 
        self.assertEqual('bar', section.get('foo'))
 
3346
        self.assertEquals('bar', section.get('foo'))
3415
3347
 
3416
3348
 
3417
3349
class TestLocationMatcher(TestStore):
3435
3367
[/quux/quux]
3436
3368
section=/quux/quux
3437
3369
''')
3438
 
        self.assertEqual(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
 
3370
        self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
3439
3371
                           '/quux/quux'],
3440
3372
                          [section.id for _, section in store.get_sections()])
3441
3373
        matcher = config.LocationMatcher(store, '/foo/bar/quux')
3442
3374
        sections = [section for _, section in matcher.get_sections()]
3443
 
        self.assertEqual(['/foo/bar', '/foo'],
 
3375
        self.assertEquals(['/foo/bar', '/foo'],
3444
3376
                          [section.id for section in sections])
3445
 
        self.assertEqual(['quux', 'bar/quux'],
 
3377
        self.assertEquals(['quux', 'bar/quux'],
3446
3378
                          [section.extra_path for section in sections])
3447
3379
 
3448
3380
    def test_more_specific_sections_first(self):
3453
3385
[/foo/bar]
3454
3386
section=/foo/bar
3455
3387
''')
3456
 
        self.assertEqual(['/foo', '/foo/bar'],
 
3388
        self.assertEquals(['/foo', '/foo/bar'],
3457
3389
                          [section.id for _, section in store.get_sections()])
3458
3390
        matcher = config.LocationMatcher(store, '/foo/bar/baz')
3459
3391
        sections = [section for _, section in matcher.get_sections()]
3460
 
        self.assertEqual(['/foo/bar', '/foo'],
 
3392
        self.assertEquals(['/foo/bar', '/foo'],
3461
3393
                          [section.id for section in sections])
3462
 
        self.assertEqual(['baz', 'bar/baz'],
 
3394
        self.assertEquals(['baz', 'bar/baz'],
3463
3395
                          [section.extra_path for section in sections])
3464
3396
 
3465
3397
    def test_appendpath_in_no_name_section(self):
3473
3405
        matcher = config.LocationMatcher(store, 'dir/subdir')
3474
3406
        sections = list(matcher.get_sections())
3475
3407
        self.assertLength(1, sections)
3476
 
        self.assertEqual('bar/dir/subdir', sections[0][1].get('foo'))
 
3408
        self.assertEquals('bar/dir/subdir', sections[0][1].get('foo'))
3477
3409
 
3478
3410
    def test_file_urls_are_normalized(self):
3479
3411
        store = self.get_store(self)
3484
3416
            expected_url = 'file:///dir/subdir'
3485
3417
            expected_location = '/dir/subdir'
3486
3418
        matcher = config.LocationMatcher(store, expected_url)
3487
 
        self.assertEqual(expected_location, matcher.location)
 
3419
        self.assertEquals(expected_location, matcher.location)
3488
3420
 
3489
3421
    def test_branch_name_colo(self):
3490
3422
        store = self.get_store(self)
3529
3461
 
3530
3462
    def test_url_vs_local_paths(self):
3531
3463
        # The matcher location is an url and the section names are local paths
3532
 
        self.assertSectionIDs(['/foo/bar', '/foo'],
3533
 
                              'file:///foo/bar/baz', '''\
 
3464
        sections = self.assertSectionIDs(['/foo/bar', '/foo'],
 
3465
                                         'file:///foo/bar/baz', '''\
3534
3466
[/foo]
3535
3467
[/foo/bar]
3536
3468
''')
3537
3469
 
3538
3470
    def test_local_path_vs_url(self):
3539
3471
        # The matcher location is a local path and the section names are urls
3540
 
        self.assertSectionIDs(['file:///foo/bar', 'file:///foo'],
3541
 
                              '/foo/bar/baz', '''\
 
3472
        sections = self.assertSectionIDs(['file:///foo/bar', 'file:///foo'],
 
3473
                                         '/foo/bar/baz', '''\
3542
3474
[file:///foo]
3543
3475
[file:///foo/bar]
3544
3476
''')
3553
3485
[/foo]
3554
3486
[/foo/bar]
3555
3487
''')
3556
 
        self.assertEqual(['baz', 'bar/baz', '/foo/bar/baz'],
 
3488
        self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
3557
3489
                          [s.locals['relpath'] for _, s in sections])
3558
3490
 
3559
3491
    def test_order_reversed(self):
3580
3512
        # Note that 'baz' as a relpath for /foo/b* is not fully correct, but
3581
3513
        # nothing really is... as far using {relpath} to append it to something
3582
3514
        # else, this seems good enough though.
3583
 
        self.assertEqual(['', 'baz', 'bar/baz'],
 
3515
        self.assertEquals(['', 'baz', 'bar/baz'],
3584
3516
                          [s.locals['relpath'] for _, s in sections])
3585
3517
 
3586
3518
    def test_respect_order(self):
3636
3568
        store2 = config.IniFileStore()
3637
3569
        store2._load_from_string('foo=baz')
3638
3570
        conf = config.Stack([store1.get_sections, store2.get_sections])
3639
 
        self.assertEqual('bar', conf.get('foo'))
 
3571
        self.assertEquals('bar', conf.get('foo'))
3640
3572
 
3641
3573
    def test_get_with_registered_default_value(self):
3642
3574
        config.option_registry.register(config.Option('foo', default='bar'))
3643
3575
        conf_stack = config.Stack([])
3644
 
        self.assertEqual('bar', conf_stack.get('foo'))
 
3576
        self.assertEquals('bar', conf_stack.get('foo'))
3645
3577
 
3646
3578
    def test_get_without_registered_default_value(self):
3647
3579
        config.option_registry.register(config.Option('foo'))
3648
3580
        conf_stack = config.Stack([])
3649
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3581
        self.assertEquals(None, conf_stack.get('foo'))
3650
3582
 
3651
3583
    def test_get_without_default_value_for_not_registered(self):
3652
3584
        conf_stack = config.Stack([])
3653
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3585
        self.assertEquals(None, conf_stack.get('foo'))
3654
3586
 
3655
3587
    def test_get_for_empty_section_callable(self):
3656
3588
        conf_stack = config.Stack([lambda : []])
3657
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3589
        self.assertEquals(None, conf_stack.get('foo'))
3658
3590
 
3659
3591
    def test_get_for_broken_callable(self):
3660
3592
        # Trying to use and invalid callable raises an exception on first use
3679
3611
        self.overrideEnv('FOO', 'quux')
3680
3612
        # Env variable provides a default taking over the option one
3681
3613
        conf = self.get_conf('foo=store')
3682
 
        self.assertEqual('quux', conf.get('foo'))
 
3614
        self.assertEquals('quux', conf.get('foo'))
3683
3615
 
3684
3616
    def test_first_override_value_from_env_wins(self):
3685
3617
        self.overrideEnv('NO_VALUE', None)
3692
3624
        self.overrideEnv('BAZ', 'baz')
3693
3625
        # The first env var set wins
3694
3626
        conf = self.get_conf('foo=store')
3695
 
        self.assertEqual('foo', conf.get('foo'))
 
3627
        self.assertEquals('foo', conf.get('foo'))
3696
3628
 
3697
3629
 
3698
3630
class TestMemoryStack(tests.TestCase):
3699
3631
 
3700
3632
    def test_get(self):
3701
3633
        conf = config.MemoryStack('foo=bar')
3702
 
        self.assertEqual('bar', conf.get('foo'))
 
3634
        self.assertEquals('bar', conf.get('foo'))
3703
3635
 
3704
3636
    def test_set(self):
3705
3637
        conf = config.MemoryStack('foo=bar')
3706
3638
        conf.set('foo', 'baz')
3707
 
        self.assertEqual('baz', conf.get('foo'))
 
3639
        self.assertEquals('baz', conf.get('foo'))
3708
3640
 
3709
3641
    def test_no_content(self):
3710
3642
        conf = config.MemoryStack()
3713
3645
        self.assertRaises(NotImplementedError, conf.get, 'foo')
3714
3646
        # But a content can still be provided
3715
3647
        conf.store._load_from_string('foo=bar')
3716
 
        self.assertEqual('bar', conf.get('foo'))
 
3648
        self.assertEquals('bar', conf.get('foo'))
3717
3649
 
3718
3650
 
3719
3651
class TestStackIterSections(tests.TestCase):
3761
3693
 
3762
3694
    def test_build_stack(self):
3763
3695
        # Just a smoke test to help debug builders
3764
 
        self.get_stack(self)
 
3696
        stack = self.get_stack(self)
3765
3697
 
3766
3698
 
3767
3699
class TestStackGet(TestStackWithTransport):
3771
3703
        self.conf = self.get_stack(self)
3772
3704
 
3773
3705
    def test_get_for_empty_stack(self):
3774
 
        self.assertEqual(None, self.conf.get('foo'))
 
3706
        self.assertEquals(None, self.conf.get('foo'))
3775
3707
 
3776
3708
    def test_get_hook(self):
3777
3709
        self.conf.set('foo', 'bar')
3781
3713
        config.ConfigHooks.install_named_hook('get', hook, None)
3782
3714
        self.assertLength(0, calls)
3783
3715
        value = self.conf.get('foo')
3784
 
        self.assertEqual('bar', value)
 
3716
        self.assertEquals('bar', value)
3785
3717
        self.assertLength(1, calls)
3786
 
        self.assertEqual((self.conf, 'foo', 'bar'), calls[0])
 
3718
        self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
3787
3719
 
3788
3720
 
3789
3721
class TestStackGetWithConverter(tests.TestCase):
3805
3737
    def test_get_default_bool_None(self):
3806
3738
        self.register_bool_option('foo')
3807
3739
        conf = self.get_conf('')
3808
 
        self.assertEqual(None, conf.get('foo'))
 
3740
        self.assertEquals(None, conf.get('foo'))
3809
3741
 
3810
3742
    def test_get_default_bool_True(self):
3811
3743
        self.register_bool_option('foo', u'True')
3812
3744
        conf = self.get_conf('')
3813
 
        self.assertEqual(True, conf.get('foo'))
 
3745
        self.assertEquals(True, conf.get('foo'))
3814
3746
 
3815
3747
    def test_get_default_bool_False(self):
3816
3748
        self.register_bool_option('foo', False)
3817
3749
        conf = self.get_conf('')
3818
 
        self.assertEqual(False, conf.get('foo'))
 
3750
        self.assertEquals(False, conf.get('foo'))
3819
3751
 
3820
3752
    def test_get_default_bool_False_as_string(self):
3821
3753
        self.register_bool_option('foo', u'False')
3822
3754
        conf = self.get_conf('')
3823
 
        self.assertEqual(False, conf.get('foo'))
 
3755
        self.assertEquals(False, conf.get('foo'))
3824
3756
 
3825
3757
    def test_get_default_bool_from_env_converted(self):
3826
3758
        self.register_bool_option('foo', u'True', default_from_env=['FOO'])
3827
3759
        self.overrideEnv('FOO', 'False')
3828
3760
        conf = self.get_conf('')
3829
 
        self.assertEqual(False, conf.get('foo'))
 
3761
        self.assertEquals(False, conf.get('foo'))
3830
3762
 
3831
3763
    def test_get_default_bool_when_conversion_fails(self):
3832
3764
        self.register_bool_option('foo', default='True')
3833
3765
        conf = self.get_conf('foo=invalid boolean')
3834
 
        self.assertEqual(True, conf.get('foo'))
 
3766
        self.assertEquals(True, conf.get('foo'))
3835
3767
 
3836
3768
    def register_integer_option(self, name,
3837
3769
                                default=None, default_from_env=None):
3843
3775
    def test_get_default_integer_None(self):
3844
3776
        self.register_integer_option('foo')
3845
3777
        conf = self.get_conf('')
3846
 
        self.assertEqual(None, conf.get('foo'))
 
3778
        self.assertEquals(None, conf.get('foo'))
3847
3779
 
3848
3780
    def test_get_default_integer(self):
3849
3781
        self.register_integer_option('foo', 42)
3850
3782
        conf = self.get_conf('')
3851
 
        self.assertEqual(42, conf.get('foo'))
 
3783
        self.assertEquals(42, conf.get('foo'))
3852
3784
 
3853
3785
    def test_get_default_integer_as_string(self):
3854
3786
        self.register_integer_option('foo', u'42')
3855
3787
        conf = self.get_conf('')
3856
 
        self.assertEqual(42, conf.get('foo'))
 
3788
        self.assertEquals(42, conf.get('foo'))
3857
3789
 
3858
3790
    def test_get_default_integer_from_env(self):
3859
3791
        self.register_integer_option('foo', default_from_env=['FOO'])
3860
3792
        self.overrideEnv('FOO', '18')
3861
3793
        conf = self.get_conf('')
3862
 
        self.assertEqual(18, conf.get('foo'))
 
3794
        self.assertEquals(18, conf.get('foo'))
3863
3795
 
3864
3796
    def test_get_default_integer_when_conversion_fails(self):
3865
3797
        self.register_integer_option('foo', default='12')
3866
3798
        conf = self.get_conf('foo=invalid integer')
3867
 
        self.assertEqual(12, conf.get('foo'))
 
3799
        self.assertEquals(12, conf.get('foo'))
3868
3800
 
3869
3801
    def register_list_option(self, name, default=None, default_from_env=None):
3870
3802
        l = config.ListOption(name, help='A list.', default=default,
3874
3806
    def test_get_default_list_None(self):
3875
3807
        self.register_list_option('foo')
3876
3808
        conf = self.get_conf('')
3877
 
        self.assertEqual(None, conf.get('foo'))
 
3809
        self.assertEquals(None, conf.get('foo'))
3878
3810
 
3879
3811
    def test_get_default_list_empty(self):
3880
3812
        self.register_list_option('foo', '')
3881
3813
        conf = self.get_conf('')
3882
 
        self.assertEqual([], conf.get('foo'))
 
3814
        self.assertEquals([], conf.get('foo'))
3883
3815
 
3884
3816
    def test_get_default_list_from_env(self):
3885
3817
        self.register_list_option('foo', default_from_env=['FOO'])
3886
3818
        self.overrideEnv('FOO', '')
3887
3819
        conf = self.get_conf('')
3888
 
        self.assertEqual([], conf.get('foo'))
 
3820
        self.assertEquals([], conf.get('foo'))
3889
3821
 
3890
3822
    def test_get_with_list_converter_no_item(self):
3891
3823
        self.register_list_option('foo', None)
3892
3824
        conf = self.get_conf('foo=,')
3893
 
        self.assertEqual([], conf.get('foo'))
 
3825
        self.assertEquals([], conf.get('foo'))
3894
3826
 
3895
3827
    def test_get_with_list_converter_many_items(self):
3896
3828
        self.register_list_option('foo', None)
3897
3829
        conf = self.get_conf('foo=m,o,r,e')
3898
 
        self.assertEqual(['m', 'o', 'r', 'e'], conf.get('foo'))
 
3830
        self.assertEquals(['m', 'o', 'r', 'e'], conf.get('foo'))
3899
3831
 
3900
3832
    def test_get_with_list_converter_embedded_spaces_many_items(self):
3901
3833
        self.register_list_option('foo', None)
3902
3834
        conf = self.get_conf('foo=" bar", "baz "')
3903
 
        self.assertEqual([' bar', 'baz '], conf.get('foo'))
 
3835
        self.assertEquals([' bar', 'baz '], conf.get('foo'))
3904
3836
 
3905
3837
    def test_get_with_list_converter_stripped_spaces_many_items(self):
3906
3838
        self.register_list_option('foo', None)
3907
3839
        conf = self.get_conf('foo= bar ,  baz ')
3908
 
        self.assertEqual(['bar', 'baz'], conf.get('foo'))
 
3840
        self.assertEquals(['bar', 'baz'], conf.get('foo'))
3909
3841
 
3910
3842
 
3911
3843
class TestIterOptionRefs(tests.TestCase):
3912
3844
    """iter_option_refs is a bit unusual, document some cases."""
3913
3845
 
3914
3846
    def assertRefs(self, expected, string):
3915
 
        self.assertEqual(expected, list(config.iter_option_refs(string)))
 
3847
        self.assertEquals(expected, list(config.iter_option_refs(string)))
3916
3848
 
3917
3849
    def test_empty(self):
3918
3850
        self.assertRefs([(False, '')], '')
3950
3882
        self.conf = config.Stack([store.get_sections], store)
3951
3883
 
3952
3884
    def assertExpansion(self, expected, string, env=None):
3953
 
        self.assertEqual(expected, self.conf.expand_options(string, env))
 
3885
        self.assertEquals(expected, self.conf.expand_options(string, env))
3954
3886
 
3955
3887
    def test_no_expansion(self):
3956
3888
        self.assertExpansion('foo', 'foo')
3958
3890
    def test_expand_default_value(self):
3959
3891
        self.conf.store._load_from_string('bar=baz')
3960
3892
        self.registry.register(config.Option('foo', default=u'{bar}'))
3961
 
        self.assertEqual('baz', self.conf.get('foo', expand=True))
 
3893
        self.assertEquals('baz', self.conf.get('foo', expand=True))
3962
3894
 
3963
3895
    def test_expand_default_from_env(self):
3964
3896
        self.conf.store._load_from_string('bar=baz')
3965
3897
        self.registry.register(config.Option('foo', default_from_env=['FOO']))
3966
3898
        self.overrideEnv('FOO', '{bar}')
3967
 
        self.assertEqual('baz', self.conf.get('foo', expand=True))
 
3899
        self.assertEquals('baz', self.conf.get('foo', expand=True))
3968
3900
 
3969
3901
    def test_expand_default_on_failed_conversion(self):
3970
3902
        self.conf.store._load_from_string('baz=bogus\nbar=42\nfoo={baz}')
3971
3903
        self.registry.register(
3972
3904
            config.Option('foo', default=u'{bar}',
3973
3905
                          from_unicode=config.int_from_store))
3974
 
        self.assertEqual(42, self.conf.get('foo', expand=True))
 
3906
        self.assertEquals(42, self.conf.get('foo', expand=True))
3975
3907
 
3976
3908
    def test_env_adding_options(self):
3977
3909
        self.assertExpansion('bar', '{foo}', {'foo': 'bar'})
3988
3920
        self.assertRaises(errors.ExpandingUnknownOption,
3989
3921
                          self.conf.expand_options, '{foo}')
3990
3922
 
3991
 
    def test_illegal_def_is_ignored(self):
3992
 
        self.assertExpansion('{1,2}', '{1,2}')
3993
 
        self.assertExpansion('{ }', '{ }')
3994
 
        self.assertExpansion('${Foo,f}', '${Foo,f}')
3995
 
 
3996
3923
    def test_indirect_ref(self):
3997
3924
        self.conf.store._load_from_string('''
3998
3925
foo=xxx
4019
3946
baz={foo}''')
4020
3947
        e = self.assertRaises(errors.OptionExpansionLoop,
4021
3948
                              self.conf.expand_options, '{foo}')
4022
 
        self.assertEqual('foo->bar->baz', e.refs)
4023
 
        self.assertEqual('{foo}', e.string)
 
3949
        self.assertEquals('foo->bar->baz', e.refs)
 
3950
        self.assertEquals('{foo}', e.string)
4024
3951
 
4025
3952
    def test_list(self):
4026
3953
        self.conf.store._load_from_string('''
4031
3958
''')
4032
3959
        self.registry.register(
4033
3960
            config.ListOption('list'))
4034
 
        self.assertEqual(['start', 'middle', 'end'],
 
3961
        self.assertEquals(['start', 'middle', 'end'],
4035
3962
                           self.conf.get('list', expand=True))
4036
3963
 
4037
3964
    def test_cascading_list(self):
4046
3973
        # happen while expanding. Conversion should only occur for the original
4047
3974
        # option ('list' here).
4048
3975
        self.registry.register(config.ListOption('baz'))
4049
 
        self.assertEqual(['start', 'middle', 'end'],
 
3976
        self.assertEquals(['start', 'middle', 'end'],
4050
3977
                           self.conf.get('list', expand=True))
4051
3978
 
4052
3979
    def test_pathologically_hidden_list(self):
4061
3988
        # What matters is what the registration says, the conversion happens
4062
3989
        # only after all expansions have been performed
4063
3990
        self.registry.register(config.ListOption('hidden'))
4064
 
        self.assertEqual(['bin', 'go'],
 
3991
        self.assertEquals(['bin', 'go'],
4065
3992
                          self.conf.get('hidden', expand=True))
4066
3993
 
4067
3994
 
4099
4026
[/project/branch/path]
4100
4027
bar = {foo}ux
4101
4028
''')
4102
 
        self.assertEqual('quux', c.get('bar', expand=True))
 
4029
        self.assertEquals('quux', c.get('bar', expand=True))
4103
4030
 
4104
4031
 
4105
4032
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
4120
4047
''')
4121
4048
        g_store.save()
4122
4049
        stack = config.LocationStack('/branch')
4123
 
        self.assertEqual('glob-bar', stack.get('lbar', expand=True))
4124
 
        self.assertEqual('loc-foo', stack.get('gfoo', expand=True))
 
4050
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
 
4051
        self.assertEquals('loc-foo', stack.get('gfoo', expand=True))
4125
4052
 
4126
4053
 
4127
4054
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
4135
4062
''')
4136
4063
        l_store.save()
4137
4064
        stack = config.LocationStack('/home/user/project/')
4138
 
        self.assertEqual('', stack.get('base', expand=True))
4139
 
        self.assertEqual('', stack.get('rel', expand=True))
 
4065
        self.assertEquals('', stack.get('base', expand=True))
 
4066
        self.assertEquals('', stack.get('rel', expand=True))
4140
4067
 
4141
4068
    def test_expand_basename_locally(self):
4142
4069
        l_store = config.LocationStore()
4146
4073
''')
4147
4074
        l_store.save()
4148
4075
        stack = config.LocationStack('/home/user/project/branch')
4149
 
        self.assertEqual('branch', stack.get('bfoo', expand=True))
 
4076
        self.assertEquals('branch', stack.get('bfoo', expand=True))
4150
4077
 
4151
4078
    def test_expand_basename_locally_longer_path(self):
4152
4079
        l_store = config.LocationStore()
4156
4083
''')
4157
4084
        l_store.save()
4158
4085
        stack = config.LocationStack('/home/user/project/dir/branch')
4159
 
        self.assertEqual('branch', stack.get('bfoo', expand=True))
 
4086
        self.assertEquals('branch', stack.get('bfoo', expand=True))
4160
4087
 
4161
4088
    def test_expand_relpath_locally(self):
4162
4089
        l_store = config.LocationStore()
4166
4093
''')
4167
4094
        l_store.save()
4168
4095
        stack = config.LocationStack('/home/user/project/branch')
4169
 
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
 
4096
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
4170
4097
 
4171
4098
    def test_expand_relpath_unknonw_in_global(self):
4172
4099
        g_store = config.GlobalStore()
4195
4122
''')
4196
4123
        g_store.save()
4197
4124
        stack = config.LocationStack('/home/user/project/branch')
4198
 
        self.assertEqual('glob-bar', stack.get('lbar', expand=True))
4199
 
        self.assertEqual('loc-foo/branch', stack.get('gfoo', expand=True))
 
4125
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
 
4126
        self.assertEquals('loc-foo/branch', stack.get('gfoo', expand=True))
4200
4127
 
4201
4128
    def test_locals_dont_leak(self):
4202
4129
        """Make sure we chose the right local in presence of several sections.
4210
4137
''')
4211
4138
        l_store.save()
4212
4139
        stack = config.LocationStack('/home/user/project/branch')
4213
 
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
 
4140
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
4214
4141
        stack = config.LocationStack('/home/user/bar/baz')
4215
 
        self.assertEqual('loc-foo/bar/baz', stack.get('lfoo', expand=True))
 
4142
        self.assertEquals('loc-foo/bar/baz', stack.get('lfoo', expand=True))
4216
4143
 
4217
4144
 
4218
4145
 
4220
4147
 
4221
4148
    def test_simple_set(self):
4222
4149
        conf = self.get_stack(self)
4223
 
        self.assertEqual(None, conf.get('foo'))
 
4150
        self.assertEquals(None, conf.get('foo'))
4224
4151
        conf.set('foo', 'baz')
4225
4152
        # Did we get it back ?
4226
 
        self.assertEqual('baz', conf.get('foo'))
 
4153
        self.assertEquals('baz', conf.get('foo'))
4227
4154
 
4228
4155
    def test_set_creates_a_new_section(self):
4229
4156
        conf = self.get_stack(self)
4230
4157
        conf.set('foo', 'baz')
4231
 
        self.assertEqual, 'baz', conf.get('foo')
 
4158
        self.assertEquals, 'baz', conf.get('foo')
4232
4159
 
4233
4160
    def test_set_hook(self):
4234
4161
        calls = []
4239
4166
        conf = self.get_stack(self)
4240
4167
        conf.set('foo', 'bar')
4241
4168
        self.assertLength(1, calls)
4242
 
        self.assertEqual((conf, 'foo', 'bar'), calls[0])
 
4169
        self.assertEquals((conf, 'foo', 'bar'), calls[0])
4243
4170
 
4244
4171
 
4245
4172
class TestStackRemove(TestStackWithTransport):
4247
4174
    def test_remove_existing(self):
4248
4175
        conf = self.get_stack(self)
4249
4176
        conf.set('foo', 'bar')
4250
 
        self.assertEqual('bar', conf.get('foo'))
 
4177
        self.assertEquals('bar', conf.get('foo'))
4251
4178
        conf.remove('foo')
4252
4179
        # Did we get it back ?
4253
 
        self.assertEqual(None, conf.get('foo'))
 
4180
        self.assertEquals(None, conf.get('foo'))
4254
4181
 
4255
4182
    def test_remove_unknown(self):
4256
4183
        conf = self.get_stack(self)
4266
4193
        conf.set('foo', 'bar')
4267
4194
        conf.remove('foo')
4268
4195
        self.assertLength(1, calls)
4269
 
        self.assertEqual((conf, 'foo'), calls[0])
 
4196
        self.assertEquals((conf, 'foo'), calls[0])
4270
4197
 
4271
4198
 
4272
4199
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
4370
4297
        """
4371
4298
        sections = list(conf._get_sections(name))
4372
4299
        self.assertLength(len(expected), sections)
4373
 
        self.assertEqual(expected, [n for n, _, _ in sections])
 
4300
        self.assertEqual(expected, [name for name, _, _ in sections])
4374
4301
 
4375
4302
    def test_bazaar_default_section(self):
4376
4303
        self.assertSectionNames(['DEFAULT'], self.bazaar_config)
4441
4368
        else:
4442
4369
            user = credentials['user']
4443
4370
            password = credentials['password']
4444
 
        self.assertEqual(expected_user, user)
4445
 
        self.assertEqual(expected_password, password)
 
4371
        self.assertEquals(expected_user, user)
 
4372
        self.assertEquals(expected_password, password)
4446
4373
 
4447
4374
    def test_empty_config(self):
4448
4375
        conf = config.AuthenticationConfig(_file=StringIO())
4449
 
        self.assertEqual({}, conf._get_config())
 
4376
        self.assertEquals({}, conf._get_config())
4450
4377
        self._got_user_passwd(None, None, conf, 'http', 'foo.net')
4451
4378
 
4452
4379
    def test_non_utf8_config(self):
4634
4561
password=bendover
4635
4562
"""))
4636
4563
        credentials = conf.get_credentials('https', 'bar.org')
4637
 
        self.assertEqual(False, credentials.get('verify_certificates'))
 
4564
        self.assertEquals(False, credentials.get('verify_certificates'))
4638
4565
        credentials = conf.get_credentials('https', 'foo.net')
4639
 
        self.assertEqual(True, credentials.get('verify_certificates'))
 
4566
        self.assertEquals(True, credentials.get('verify_certificates'))
4640
4567
 
4641
4568
 
4642
4569
class TestAuthenticationStorage(tests.TestCaseInTempDir):
4689
4616
                                            stdout=stdout, stderr=stderr)
4690
4617
        # We use an empty conf so that the user is always prompted
4691
4618
        conf = config.AuthenticationConfig()
4692
 
        self.assertEqual(password,
 
4619
        self.assertEquals(password,
4693
4620
                          conf.get_password(scheme, host, user, port=port,
4694
4621
                                            realm=realm, path=path))
4695
 
        self.assertEqual(expected_prompt, stderr.getvalue())
4696
 
        self.assertEqual('', stdout.getvalue())
 
4622
        self.assertEquals(expected_prompt, stderr.getvalue())
 
4623
        self.assertEquals('', stdout.getvalue())
4697
4624
 
4698
4625
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
4699
4626
                                       host=None, port=None, realm=None,
4710
4637
                                            stdout=stdout, stderr=stderr)
4711
4638
        # We use an empty conf so that the user is always prompted
4712
4639
        conf = config.AuthenticationConfig()
4713
 
        self.assertEqual(username, conf.get_user(scheme, host, port=port,
 
4640
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
4714
4641
                          realm=realm, path=path, ask=True))
4715
 
        self.assertEqual(expected_prompt, stderr.getvalue())
4716
 
        self.assertEqual('', stdout.getvalue())
 
4642
        self.assertEquals(expected_prompt, stderr.getvalue())
 
4643
        self.assertEquals('', stdout.getvalue())
4717
4644
 
4718
4645
    def test_username_defaults_prompts(self):
4719
4646
        # HTTP prompts can't be tested here, see test_http.py
4725
4652
 
4726
4653
    def test_username_default_no_prompt(self):
4727
4654
        conf = config.AuthenticationConfig()
4728
 
        self.assertEqual(None,
 
4655
        self.assertEquals(None,
4729
4656
            conf.get_user('ftp', 'example.com'))
4730
 
        self.assertEqual("explicitdefault",
 
4657
        self.assertEquals("explicitdefault",
4731
4658
            conf.get_user('ftp', 'example.com', default="explicitdefault"))
4732
4659
 
4733
4660
    def test_password_default_prompts(self):
4766
4693
 
4767
4694
        # Since the password defined in the authentication config is ignored,
4768
4695
        # the user is prompted
4769
 
        self.assertEqual(entered_password,
 
4696
        self.assertEquals(entered_password,
4770
4697
                          conf.get_password('ssh', 'bar.org', user='jim'))
4771
4698
        self.assertContainsRe(
4772
4699
            self.get_log(),
4789
4716
 
4790
4717
        # Since the password defined in the authentication config is ignored,
4791
4718
        # the user is prompted
4792
 
        self.assertEqual(entered_password,
 
4719
        self.assertEquals(entered_password,
4793
4720
                          conf.get_password('ssh', 'bar.org', user='jim'))
4794
4721
        # No warning shoud be emitted since there is no password. We are only
4795
4722
        # providing "user".
4805
4732
        config.credential_store_registry.register("stub", store, fallback=True)
4806
4733
        conf = config.AuthenticationConfig(_file=StringIO())
4807
4734
        creds = conf.get_credentials("http", "example.com")
4808
 
        self.assertEqual("joe", creds["user"])
4809
 
        self.assertEqual("secret", creds["password"])
 
4735
        self.assertEquals("joe", creds["user"])
 
4736
        self.assertEquals("secret", creds["password"])
4810
4737
 
4811
4738
 
4812
4739
class StubCredentialStore(config.CredentialStore):
4857
4784
 
4858
4785
    def test_fallback_none_registered(self):
4859
4786
        r = config.CredentialStoreRegistry()
4860
 
        self.assertEqual(None,
 
4787
        self.assertEquals(None,
4861
4788
                          r.get_fallback_credentials("http", "example.com"))
4862
4789
 
4863
4790
    def test_register(self):
4864
4791
        r = config.CredentialStoreRegistry()
4865
4792
        r.register("stub", StubCredentialStore(), fallback=False)
4866
4793
        r.register("another", StubCredentialStore(), fallback=True)
4867
 
        self.assertEqual(["another", "stub"], r.keys())
 
4794
        self.assertEquals(["another", "stub"], r.keys())
4868
4795
 
4869
4796
    def test_register_lazy(self):
4870
4797
        r = config.CredentialStoreRegistry()
4871
4798
        r.register_lazy("stub", "bzrlib.tests.test_config",
4872
4799
                        "StubCredentialStore", fallback=False)
4873
 
        self.assertEqual(["stub"], r.keys())
 
4800
        self.assertEquals(["stub"], r.keys())
4874
4801
        self.assertIsInstance(r.get_credential_store("stub"),
4875
4802
                              StubCredentialStore)
4876
4803
 
4878
4805
        r = config.CredentialStoreRegistry()
4879
4806
        r.register("stub1", None, fallback=False)
4880
4807
        r.register("stub2", None, fallback=True)
4881
 
        self.assertEqual(False, r.is_fallback("stub1"))
4882
 
        self.assertEqual(True, r.is_fallback("stub2"))
 
4808
        self.assertEquals(False, r.is_fallback("stub1"))
 
4809
        self.assertEquals(True, r.is_fallback("stub2"))
4883
4810
 
4884
4811
    def test_no_fallback(self):
4885
4812
        r = config.CredentialStoreRegistry()
4886
4813
        store = CountingCredentialStore()
4887
4814
        r.register("count", store, fallback=False)
4888
 
        self.assertEqual(None,
 
4815
        self.assertEquals(None,
4889
4816
                          r.get_fallback_credentials("http", "example.com"))
4890
 
        self.assertEqual(0, store._calls)
 
4817
        self.assertEquals(0, store._calls)
4891
4818
 
4892
4819
    def test_fallback_credentials(self):
4893
4820
        r = config.CredentialStoreRegistry()
4896
4823
                              "somebody", "geheim")
4897
4824
        r.register("stub", store, fallback=True)
4898
4825
        creds = r.get_fallback_credentials("http", "example.com")
4899
 
        self.assertEqual("somebody", creds["user"])
4900
 
        self.assertEqual("geheim", creds["password"])
 
4826
        self.assertEquals("somebody", creds["user"])
 
4827
        self.assertEquals("geheim", creds["password"])
4901
4828
 
4902
4829
    def test_fallback_first_wins(self):
4903
4830
        r = config.CredentialStoreRegistry()
4910
4837
                              "somebody", "stub2")
4911
4838
        r.register("stub2", stub1, fallback=True)
4912
4839
        creds = r.get_fallback_credentials("http", "example.com")
4913
 
        self.assertEqual("somebody", creds["user"])
4914
 
        self.assertEqual("stub1", creds["password"])
 
4840
        self.assertEquals("somebody", creds["user"])
 
4841
        self.assertEquals("stub1", creds["password"])
4915
4842
 
4916
4843
 
4917
4844
class TestPlainTextCredentialStore(tests.TestCase):
4920
4847
        r = config.credential_store_registry
4921
4848
        plain_text = r.get_credential_store()
4922
4849
        decoded = plain_text.decode_password(dict(password='secret'))
4923
 
        self.assertEqual('secret', decoded)
 
4850
        self.assertEquals('secret', decoded)
4924
4851
 
4925
4852
 
4926
4853
class TestBase64CredentialStore(tests.TestCase):
4929
4856
        r = config.credential_store_registry
4930
4857
        plain_text = r.get_credential_store('base64')
4931
4858
        decoded = plain_text.decode_password(dict(password='c2VjcmV0'))
4932
 
        self.assertEqual('secret', decoded)
 
4859
        self.assertEquals('secret', decoded)
4933
4860
 
4934
4861
 
4935
4862
# FIXME: Once we have a way to declare authentication to all test servers, we
4963
4890
            self.assertIsNot(None, realname)
4964
4891
            self.assertIsNot(None, address)
4965
4892
        else:
4966
 
            self.assertEqual((None, None), (realname, address))
 
4893
            self.assertEquals((None, None), (realname, address))
4967
4894
 
4968
4895
 
4969
4896
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4976
4903
        finally:
4977
4904
            f.close()
4978
4905
        r = config._get_default_mail_domain('simple')
4979
 
        self.assertEqual('domainname.com', r)
 
4906
        self.assertEquals('domainname.com', r)
4980
4907
 
4981
4908
    def test_default_mail_domain_no_eol(self):
4982
4909
        f = file('no_eol', 'w')
4985
4912
        finally:
4986
4913
            f.close()
4987
4914
        r = config._get_default_mail_domain('no_eol')
4988
 
        self.assertEqual('domainname.com', r)
 
4915
        self.assertEquals('domainname.com', r)
4989
4916
 
4990
4917
    def test_default_mail_domain_multiple_lines(self):
4991
4918
        f = file('multiple_lines', 'w')
4994
4921
        finally:
4995
4922
            f.close()
4996
4923
        r = config._get_default_mail_domain('multiple_lines')
4997
 
        self.assertEqual('domainname.com', r)
 
4924
        self.assertEquals('domainname.com', r)
4998
4925
 
4999
4926
 
5000
4927
class EmailOptionTests(tests.TestCase):
5004
4931
        # BZR_EMAIL takes precedence over EMAIL
5005
4932
        self.overrideEnv('BZR_EMAIL', 'jelmer@samba.org')
5006
4933
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5007
 
        self.assertEqual('jelmer@samba.org', conf.get('email'))
 
4934
        self.assertEquals('jelmer@samba.org', conf.get('email'))
5008
4935
 
5009
4936
    def test_default_email_uses_EMAIL(self):
5010
4937
        conf = config.MemoryStack('')
5011
4938
        self.overrideEnv('BZR_EMAIL', None)
5012
4939
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5013
 
        self.assertEqual('jelmer@apache.org', conf.get('email'))
 
4940
        self.assertEquals('jelmer@apache.org', conf.get('email'))
5014
4941
 
5015
4942
    def test_BZR_EMAIL_overrides(self):
5016
4943
        conf = config.MemoryStack('email=jelmer@debian.org')
5017
4944
        self.overrideEnv('BZR_EMAIL', 'jelmer@apache.org')
5018
 
        self.assertEqual('jelmer@apache.org', conf.get('email'))
 
4945
        self.assertEquals('jelmer@apache.org', conf.get('email'))
5019
4946
        self.overrideEnv('BZR_EMAIL', None)
5020
4947
        self.overrideEnv('EMAIL', 'jelmer@samba.org')
5021
 
        self.assertEqual('jelmer@debian.org', conf.get('email'))
 
4948
        self.assertEquals('jelmer@debian.org', conf.get('email'))
5022
4949
 
5023
4950
 
5024
4951
class MailClientOptionTests(tests.TestCase):