~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: 2015-10-05 13:45:00 UTC
  • mfrom: (6603.3.1 bts794146)
  • Revision ID: pqm@pqm.ubuntu.com-20151005134500-v244rho557tv0ukd
(vila) Resolve Bug #1480015: Test failure: hexify removed from paramiko
 (Andrew Starr-Bochicchio) (Andrew Starr-Bochicchio)

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
448
448
        output = outfile.getvalue()
449
449
        # now we're trying to read it back
450
450
        co2 = config.ConfigObj(StringIO(output))
451
 
        self.assertEqual(triple_quotes_value, co2['test'])
 
451
        self.assertEquals(triple_quotes_value, co2['test'])
452
452
 
453
453
 
454
454
erroneous_config = """[section] # line 1
649
649
        self.path = self.uid = self.gid = None
650
650
        conf = config.IniBasedConfig(file_name='./foo.conf')
651
651
        conf._write_config_file()
652
 
        self.assertEqual(self.path, './foo.conf')
 
652
        self.assertEquals(self.path, './foo.conf')
653
653
        self.assertTrue(isinstance(self.uid, int))
654
654
        self.assertTrue(isinstance(self.gid, int))
655
655
 
699
699
        return c
700
700
 
701
701
    def assertExpansion(self, expected, conf, string, env=None):
702
 
        self.assertEqual(expected, conf.expand_options(string, env))
 
702
        self.assertEquals(expected, conf.expand_options(string, env))
703
703
 
704
704
    def test_no_expansion(self):
705
705
        c = self.get_config('')
747
747
baz={foo}''')
748
748
        e = self.assertRaises(errors.OptionExpansionLoop,
749
749
                              c.expand_options, '{foo}')
750
 
        self.assertEqual('foo->bar->baz', e.refs)
751
 
        self.assertEqual('{foo}', e.string)
 
750
        self.assertEquals('foo->bar->baz', e.refs)
 
751
        self.assertEquals('{foo}', e.string)
752
752
 
753
753
    def test_list(self):
754
754
        conf = self.get_config('''
757
757
baz=end
758
758
list={foo},{bar},{baz}
759
759
''')
760
 
        self.assertEqual(['start', 'middle', 'end'],
 
760
        self.assertEquals(['start', 'middle', 'end'],
761
761
                           conf.get_user_option('list', expand=True))
762
762
 
763
763
    def test_cascading_list(self):
767
767
baz=end
768
768
list={foo}
769
769
''')
770
 
        self.assertEqual(['start', 'middle', 'end'],
 
770
        self.assertEquals(['start', 'middle', 'end'],
771
771
                           conf.get_user_option('list', expand=True))
772
772
 
773
773
    def test_pathological_hidden_list(self):
781
781
''')
782
782
        # Nope, it's either a string or a list, and the list wins as soon as a
783
783
        # ',' appears, so the string concatenation never occur.
784
 
        self.assertEqual(['{foo', '}', '{', 'bar}'],
 
784
        self.assertEquals(['{foo', '}', '{', 'bar}'],
785
785
                          conf.get_user_option('hidden', expand=True))
786
786
 
787
787
 
815
815
[/project/branch/path]
816
816
bar = {foo}ux
817
817
''')
818
 
        self.assertEqual('quux', c.get_user_option('bar', expand=True))
 
818
        self.assertEquals('quux', c.get_user_option('bar', expand=True))
819
819
 
820
820
 
821
821
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
861
861
        return c
862
862
 
863
863
    def test_simple_read_access(self):
864
 
        self.assertEqual('1', self.config.get_user_option('one'))
 
864
        self.assertEquals('1', self.config.get_user_option('one'))
865
865
 
866
866
    def test_simple_write_access(self):
867
867
        self.config.set_user_option('one', 'one')
868
 
        self.assertEqual('one', self.config.get_user_option('one'))
 
868
        self.assertEquals('one', self.config.get_user_option('one'))
869
869
 
870
870
    def test_listen_to_the_last_speaker(self):
871
871
        c1 = self.config
872
872
        c2 = self.get_existing_config()
873
873
        c1.set_user_option('one', 'ONE')
874
874
        c2.set_user_option('two', 'TWO')
875
 
        self.assertEqual('ONE', c1.get_user_option('one'))
876
 
        self.assertEqual('TWO', c2.get_user_option('two'))
 
875
        self.assertEquals('ONE', c1.get_user_option('one'))
 
876
        self.assertEquals('TWO', c2.get_user_option('two'))
877
877
        # The second update respect the first one
878
 
        self.assertEqual('ONE', c2.get_user_option('one'))
 
878
        self.assertEquals('ONE', c2.get_user_option('one'))
879
879
 
880
880
    def test_last_speaker_wins(self):
881
881
        # If the same config is not shared, the same variable modified twice
884
884
        c2 = self.get_existing_config()
885
885
        c1.set_user_option('one', 'c1')
886
886
        c2.set_user_option('one', 'c2')
887
 
        self.assertEqual('c2', c2._get_user_option('one'))
 
887
        self.assertEquals('c2', c2._get_user_option('one'))
888
888
        # The first modification is still available until another refresh
889
889
        # occur
890
 
        self.assertEqual('c1', c1._get_user_option('one'))
 
890
        self.assertEquals('c1', c1._get_user_option('one'))
891
891
        c1.set_user_option('two', 'done')
892
 
        self.assertEqual('c2', c1._get_user_option('one'))
 
892
        self.assertEquals('c2', c1._get_user_option('one'))
893
893
 
894
894
    def test_writes_are_serialized(self):
895
895
        c1 = self.config
920
920
        self.assertTrue(c1._lock.is_held)
921
921
        self.assertRaises(errors.LockContention,
922
922
                          c2.set_user_option, 'one', 'c2')
923
 
        self.assertEqual('c1', c1.get_user_option('one'))
 
923
        self.assertEquals('c1', c1.get_user_option('one'))
924
924
        # Let the lock be released
925
925
        after_writing.set()
926
926
        writing_done.wait()
927
927
        c2.set_user_option('one', 'c2')
928
 
        self.assertEqual('c2', c2.get_user_option('one'))
 
928
        self.assertEquals('c2', c2.get_user_option('one'))
929
929
 
930
930
    def test_read_while_writing(self):
931
931
       c1 = self.config
953
953
       # Ensure the thread is ready to write
954
954
       ready_to_write.wait()
955
955
       self.assertTrue(c1._lock.is_held)
956
 
       self.assertEqual('c1', c1.get_user_option('one'))
 
956
       self.assertEquals('c1', c1.get_user_option('one'))
957
957
       # If we read during the write, we get the old value
958
958
       c2 = self.get_existing_config()
959
 
       self.assertEqual('1', c2.get_user_option('one'))
 
959
       self.assertEquals('1', c2.get_user_option('one'))
960
960
       # Let the writing occur and ensure it occurred
961
961
       do_writing.set()
962
962
       writing_done.wait()
963
963
       # Now we get the updated value
964
964
       c3 = self.get_existing_config()
965
 
       self.assertEqual('c1', c3.get_user_option('one'))
 
965
       self.assertEquals('c1', c3.get_user_option('one'))
966
966
 
967
967
 
968
968
class TestGetUserOptionAs(TestIniConfig):
983
983
        self.overrideAttr(trace, 'warning', warning)
984
984
        msg = 'Value "%s" is not a boolean for "%s"'
985
985
        self.assertIs(None, get_bool('an_invalid_bool'))
986
 
        self.assertEqual(msg % ('maybe', 'an_invalid_bool'), warnings[0])
 
986
        self.assertEquals(msg % ('maybe', 'an_invalid_bool'), warnings[0])
987
987
        warnings = []
988
988
        self.assertIs(None, get_bool('not_defined_in_this_config'))
989
 
        self.assertEqual([], warnings)
 
989
        self.assertEquals([], warnings)
990
990
 
991
991
    def test_get_user_option_as_list(self):
992
992
        conf, parser = self.make_config_parser("""
1340
1340
    def test_find_merge_tool_known(self):
1341
1341
        conf = self._get_empty_config()
1342
1342
        cmdline = conf.find_merge_tool('kdiff3')
1343
 
        self.assertEqual('kdiff3 {base} {this} {other} -o {result}', cmdline)
 
1343
        self.assertEquals('kdiff3 {base} {this} {other} -o {result}', cmdline)
1344
1344
 
1345
1345
    def test_find_merge_tool_override_known(self):
1346
1346
        conf = self._get_empty_config()
1906
1906
        # Store the raw content in the config file
1907
1907
        t.put_bytes('foo.conf', utf8_content)
1908
1908
        conf = config.TransportConfig(t, 'foo.conf')
1909
 
        self.assertEqual(unicode_user, conf.get_option('user'))
 
1909
        self.assertEquals(unicode_user, conf.get_option('user'))
1910
1910
 
1911
1911
    def test_load_non_ascii(self):
1912
1912
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
1940
1940
        cfg = config.TransportConfig(
1941
1941
            DenyingTransport("nonexisting://"), 'control.conf')
1942
1942
        self.assertIs(None, cfg.get_option('non-existant', 'SECTION'))
1943
 
        self.assertEqual(
 
1943
        self.assertEquals(
1944
1944
            warnings,
1945
1945
            [u'Permission denied while trying to open configuration file '
1946
1946
             u'nonexisting:///control.conf.'])
1998
1998
            config.OldConfigHooks.uninstall_named_hook, 'get', None)
1999
1999
        self.assertLength(0, calls)
2000
2000
        actual_value = conf.get_user_option(name)
2001
 
        self.assertEqual(value, actual_value)
 
2001
        self.assertEquals(value, actual_value)
2002
2002
        self.assertLength(1, calls)
2003
 
        self.assertEqual((conf, name, value), calls[0])
 
2003
        self.assertEquals((conf, name, value), calls[0])
2004
2004
 
2005
2005
    def test_get_hook_bazaar(self):
2006
2006
        self.assertGetHook(self.bazaar_config, 'file', 'bazaar')
2026
2026
        # We can't assert the conf object below as different configs use
2027
2027
        # different means to implement set_user_option and we care only about
2028
2028
        # coverage here.
2029
 
        self.assertEqual((name, value), calls[0][1:])
 
2029
        self.assertEquals((name, value), calls[0][1:])
2030
2030
 
2031
2031
    def test_set_hook_bazaar(self):
2032
2032
        self.assertSetHook(self.bazaar_config, 'foo', 'bazaar')
2050
2050
        # We can't assert the conf object below as different configs use
2051
2051
        # different means to implement remove_user_option and we care only about
2052
2052
        # coverage here.
2053
 
        self.assertEqual((name,), calls[0][1:])
 
2053
        self.assertEquals((name,), calls[0][1:])
2054
2054
 
2055
2055
    def test_remove_hook_bazaar(self):
2056
2056
        self.assertRemoveHook(self.bazaar_config, 'file')
2129
2129
            config.OldConfigHooks.uninstall_named_hook, 'get', None)
2130
2130
        self.assertLength(0, calls)
2131
2131
        actual_value = conf.get_option(name)
2132
 
        self.assertEqual(value, actual_value)
 
2132
        self.assertEquals(value, actual_value)
2133
2133
        self.assertLength(1, calls)
2134
 
        self.assertEqual((conf, name, value), calls[0])
 
2134
        self.assertEquals((conf, name, value), calls[0])
2135
2135
 
2136
2136
    def test_get_hook_remote_branch(self):
2137
2137
        remote_branch = branch.Branch.open(self.get_url('tree'))
2156
2156
        # We can't assert the conf object below as different configs use
2157
2157
        # different means to implement set_user_option and we care only about
2158
2158
        # coverage here.
2159
 
        self.assertEqual((name, value), calls[0][1:])
 
2159
        self.assertEquals((name, value), calls[0][1:])
2160
2160
 
2161
2161
    def test_set_hook_remote_branch(self):
2162
2162
        remote_branch = branch.Branch.open(self.get_url('tree'))
2237
2237
        self.assertTrue(self.is_valid('__bar__'))
2238
2238
        self.assertTrue(self.is_valid('a_'))
2239
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
2240
 
2243
2241
    def test_invalid_names(self):
2244
2242
        self.assertFalse(self.is_valid(' foo'))
2252
2250
        self.assertFalse(self.is_valid('{}'))
2253
2251
        self.assertFalse(self.is_valid('{a}'))
2254
2252
        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
2253
 
2260
2254
    def assertSingleGroup(self, reference):
2261
2255
        # the regexp is used with split and as such should match the reference
2272
2266
 
2273
2267
    def test_default_value(self):
2274
2268
        opt = config.Option('foo', default='bar')
2275
 
        self.assertEqual('bar', opt.get_default())
 
2269
        self.assertEquals('bar', opt.get_default())
2276
2270
 
2277
2271
    def test_callable_default_value(self):
2278
2272
        def bar_as_unicode():
2279
2273
            return u'bar'
2280
2274
        opt = config.Option('foo', default=bar_as_unicode)
2281
 
        self.assertEqual('bar', opt.get_default())
 
2275
        self.assertEquals('bar', opt.get_default())
2282
2276
 
2283
2277
    def test_default_value_from_env(self):
2284
2278
        opt = config.Option('foo', default='bar', default_from_env=['FOO'])
2285
2279
        self.overrideEnv('FOO', 'quux')
2286
2280
        # Env variable provides a default taking over the option one
2287
 
        self.assertEqual('quux', opt.get_default())
 
2281
        self.assertEquals('quux', opt.get_default())
2288
2282
 
2289
2283
    def test_first_default_value_from_env_wins(self):
2290
2284
        opt = config.Option('foo', default='bar',
2292
2286
        self.overrideEnv('FOO', 'foo')
2293
2287
        self.overrideEnv('BAZ', 'baz')
2294
2288
        # The first env var set wins
2295
 
        self.assertEqual('foo', opt.get_default())
 
2289
        self.assertEquals('foo', opt.get_default())
2296
2290
 
2297
2291
    def test_not_supported_list_default_value(self):
2298
2292
        self.assertRaises(AssertionError, config.Option, 'foo', default=[1])
2309
2303
 
2310
2304
    def test_get_help_topic(self):
2311
2305
        opt = config.Option('foo')
2312
 
        self.assertEqual('foo', opt.get_help_topic())
2313
 
 
2314
 
 
2315
 
class TestOptionConverter(tests.TestCase):
 
2306
        self.assertEquals('foo', opt.get_help_topic())
 
2307
 
 
2308
 
 
2309
class TestOptionConverterMixin(object):
2316
2310
 
2317
2311
    def assertConverted(self, expected, opt, value):
2318
 
        self.assertEqual(expected, opt.convert_from_unicode(None, value))
 
2312
        self.assertEquals(expected, opt.convert_from_unicode(None, value))
2319
2313
 
2320
 
    def assertCallsWarning(self, opt, value):
 
2314
    def assertWarns(self, opt, value):
2321
2315
        warnings = []
2322
 
 
2323
2316
        def warning(*args):
2324
2317
            warnings.append(args[0] % args[1:])
2325
2318
        self.overrideAttr(trace, 'warning', warning)
2326
 
        self.assertEqual(None, opt.convert_from_unicode(None, value))
 
2319
        self.assertEquals(None, opt.convert_from_unicode(None, value))
2327
2320
        self.assertLength(1, warnings)
2328
 
        self.assertEqual(
 
2321
        self.assertEquals(
2329
2322
            'Value "%s" is not valid for "%s"' % (value, opt.name),
2330
2323
            warnings[0])
2331
2324
 
2332
 
    def assertCallsError(self, opt, value):
 
2325
    def assertErrors(self, opt, value):
2333
2326
        self.assertRaises(errors.ConfigOptionValueError,
2334
2327
                          opt.convert_from_unicode, None, value)
2335
2328
 
2336
2329
    def assertConvertInvalid(self, opt, invalid_value):
2337
2330
        opt.invalid = None
2338
 
        self.assertEqual(None, opt.convert_from_unicode(None, invalid_value))
 
2331
        self.assertEquals(None, opt.convert_from_unicode(None, invalid_value))
2339
2332
        opt.invalid = 'warning'
2340
 
        self.assertCallsWarning(opt, invalid_value)
 
2333
        self.assertWarns(opt, invalid_value)
2341
2334
        opt.invalid = 'error'
2342
 
        self.assertCallsError(opt, invalid_value)
2343
 
 
2344
 
 
2345
 
class TestOptionWithBooleanConverter(TestOptionConverter):
 
2335
        self.assertErrors(opt, invalid_value)
 
2336
 
 
2337
 
 
2338
class TestOptionWithBooleanConverter(tests.TestCase, TestOptionConverterMixin):
2346
2339
 
2347
2340
    def get_option(self):
2348
2341
        return config.Option('foo', help='A boolean.',
2362
2355
        self.assertConverted(False, opt, u'False')
2363
2356
 
2364
2357
 
2365
 
class TestOptionWithIntegerConverter(TestOptionConverter):
 
2358
class TestOptionWithIntegerConverter(tests.TestCase, TestOptionConverterMixin):
2366
2359
 
2367
2360
    def get_option(self):
2368
2361
        return config.Option('foo', help='An integer.',
2380
2373
        self.assertConverted(16, opt, u'16')
2381
2374
 
2382
2375
 
2383
 
class TestOptionWithSIUnitConverter(TestOptionConverter):
 
2376
class TestOptionWithSIUnitConverter(tests.TestCase, TestOptionConverterMixin):
2384
2377
 
2385
2378
    def get_option(self):
2386
2379
        return config.Option('foo', help='An integer in SI units.',
2389
2382
    def test_convert_invalid(self):
2390
2383
        opt = self.get_option()
2391
2384
        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
 
2385
        self.assertConvertInvalid(opt, u'Gb') # Forgot the int
 
2386
        self.assertConvertInvalid(opt, u'1b') # Forgot the unit
2394
2387
        self.assertConvertInvalid(opt, u'1GG')
2395
2388
        self.assertConvertInvalid(opt, u'1Mbb')
2396
2389
        self.assertConvertInvalid(opt, u'1MM')
2405
2398
        self.assertConverted(100, opt, u'100')
2406
2399
 
2407
2400
 
2408
 
class TestListOption(TestOptionConverter):
 
2401
class TestListOption(tests.TestCase, TestOptionConverterMixin):
2409
2402
 
2410
2403
    def get_option(self):
2411
2404
        return config.ListOption('foo', help='A list.')
2420
2413
    def test_convert_valid(self):
2421
2414
        opt = self.get_option()
2422
2415
        # An empty string is an empty list
2423
 
        self.assertConverted([], opt, '')  # Using a bare str() just in case
 
2416
        self.assertConverted([], opt, '') # Using a bare str() just in case
2424
2417
        self.assertConverted([], opt, u'')
2425
2418
        # A boolean
2426
2419
        self.assertConverted([u'True'], opt, u'True')
2430
2423
        self.assertConverted([u'bar'], opt, u'bar')
2431
2424
 
2432
2425
 
2433
 
class TestRegistryOption(TestOptionConverter):
 
2426
class TestRegistryOption(tests.TestCase, TestOptionConverterMixin):
2434
2427
 
2435
2428
    def get_option(self, registry):
2436
2429
        return config.RegistryOption('foo', registry,
2437
 
                                     help='A registry option.')
 
2430
                help='A registry option.')
2438
2431
 
2439
2432
    def test_convert_invalid(self):
2440
2433
        registry = _mod_registry.Registry()
2456
2449
        registry.register("someval", 1234, help="some option")
2457
2450
        registry.register("dunno", 1234, help="some other option")
2458
2451
        opt = self.get_option(registry)
2459
 
        self.assertEqual(
 
2452
        self.assertEquals(
2460
2453
            'A registry option.\n'
2461
2454
            '\n'
2462
2455
            'The following values are supported:\n'
2469
2462
        registry.register("someval", 1234, help="some option")
2470
2463
        registry.register("dunno", 1234, help="some other option")
2471
2464
        opt = self.get_option(registry)
2472
 
        self.assertEqual(
 
2465
        self.assertEquals(
2473
2466
            'A registry option.\n'
2474
2467
            '\n'
2475
2468
            'The following values are supported:\n'
2494
2487
    def test_registered_help(self):
2495
2488
        opt = config.Option('foo', help='A simple option')
2496
2489
        self.registry.register(opt)
2497
 
        self.assertEqual('A simple option', self.registry.get_help('foo'))
 
2490
        self.assertEquals('A simple option', self.registry.get_help('foo'))
2498
2491
 
2499
2492
    def test_dont_register_illegal_name(self):
2500
2493
        self.assertRaises(errors.IllegalOptionName,
2512
2505
    def test_registered_lazy_help(self):
2513
2506
        self.registry.register_lazy('lazy_foo', self.__module__,
2514
2507
                                    'TestOptionRegistry.lazy_option')
2515
 
        self.assertEqual('Lazy help', self.registry.get_help('lazy_foo'))
 
2508
        self.assertEquals('Lazy help', self.registry.get_help('lazy_foo'))
2516
2509
 
2517
2510
    def test_dont_lazy_register_illegal_name(self):
2518
2511
        # This is where the root cause of http://pad.lv/1235099 is better
2541
2534
    def test_proper_name(self):
2542
2535
        # An option should be registered under its own name, this can't be
2543
2536
        # checked at registration time for the lazy ones.
2544
 
        self.assertEqual(self.option_name, self.option.name)
 
2537
        self.assertEquals(self.option_name, self.option.name)
2545
2538
 
2546
2539
    def test_help_is_set(self):
2547
2540
        option_help = self.registry.get_help(self.option_name)
2548
2541
        # Come on, think about the user, he really wants to know what the
2549
2542
        # option is about
2550
2543
        self.assertIsNot(None, option_help)
2551
 
        self.assertNotEqual('', option_help)
 
2544
        self.assertNotEquals('', option_help)
2552
2545
 
2553
2546
 
2554
2547
class TestSection(tests.TestCase):
2559
2552
    def test_get_a_value(self):
2560
2553
        a_dict = dict(foo='bar')
2561
2554
        section = config.Section('myID', a_dict)
2562
 
        self.assertEqual('bar', section.get('foo'))
 
2555
        self.assertEquals('bar', section.get('foo'))
2563
2556
 
2564
2557
    def test_get_unknown_option(self):
2565
2558
        a_dict = dict()
2566
2559
        section = config.Section(None, a_dict)
2567
 
        self.assertEqual('out of thin air',
 
2560
        self.assertEquals('out of thin air',
2568
2561
                          section.get('foo', 'out of thin air'))
2569
2562
 
2570
2563
    def test_options_is_shared(self):
2584
2577
        a_dict = dict(foo='bar')
2585
2578
        section = self.get_section(a_dict)
2586
2579
        section.set('foo', 'new_value')
2587
 
        self.assertEqual('new_value', section.get('foo'))
 
2580
        self.assertEquals('new_value', section.get('foo'))
2588
2581
        # The change appears in the shared section
2589
 
        self.assertEqual('new_value', a_dict.get('foo'))
 
2582
        self.assertEquals('new_value', a_dict.get('foo'))
2590
2583
        # We keep track of the change
2591
2584
        self.assertTrue('foo' in section.orig)
2592
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2585
        self.assertEquals('bar', section.orig.get('foo'))
2593
2586
 
2594
2587
    def test_set_preserve_original_once(self):
2595
2588
        a_dict = dict(foo='bar')
2598
2591
        section.set('foo', 'second_value')
2599
2592
        # We keep track of the original value
2600
2593
        self.assertTrue('foo' in section.orig)
2601
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2594
        self.assertEquals('bar', section.orig.get('foo'))
2602
2595
 
2603
2596
    def test_remove(self):
2604
2597
        a_dict = dict(foo='bar')
2605
2598
        section = self.get_section(a_dict)
2606
2599
        section.remove('foo')
2607
2600
        # We get None for unknown options via the default value
2608
 
        self.assertEqual(None, section.get('foo'))
 
2601
        self.assertEquals(None, section.get('foo'))
2609
2602
        # Or we just get the default value
2610
 
        self.assertEqual('unknown', section.get('foo', 'unknown'))
 
2603
        self.assertEquals('unknown', section.get('foo', 'unknown'))
2611
2604
        self.assertFalse('foo' in section.options)
2612
2605
        # We keep track of the deletion
2613
2606
        self.assertTrue('foo' in section.orig)
2614
 
        self.assertEqual('bar', section.orig.get('foo'))
 
2607
        self.assertEquals('bar', section.orig.get('foo'))
2615
2608
 
2616
2609
    def test_remove_new_option(self):
2617
2610
        a_dict = dict()
2622
2615
        # The option didn't exist initially so it we need to keep track of it
2623
2616
        # with a special value
2624
2617
        self.assertTrue('foo' in section.orig)
2625
 
        self.assertEqual(config._NewlyCreatedOption, section.orig['foo'])
 
2618
        self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2626
2619
 
2627
2620
 
2628
2621
class TestCommandLineStore(tests.TestCase):
2637
2630
        sections = list(self.store.get_sections())
2638
2631
        self.assertLength(1, sections)
2639
2632
        store, section = sections[0]
2640
 
        self.assertEqual(self.store, store)
 
2633
        self.assertEquals(self.store, store)
2641
2634
        return section
2642
2635
 
2643
2636
    def test_no_override(self):
2664
2657
    def test_multiple_overrides(self):
2665
2658
        self.store._from_cmdline(['a=b', 'x=y'])
2666
2659
        section = self.get_section()
2667
 
        self.assertEqual('b', section.get('a'))
2668
 
        self.assertEqual('y', section.get('x'))
 
2660
        self.assertEquals('b', section.get('a'))
 
2661
        self.assertEquals('y', section.get('x'))
2669
2662
 
2670
2663
    def test_wrong_syntax(self):
2671
2664
        self.assertRaises(errors.BzrCommandError,
2691
2684
    def assertSectionContent(self, expected, (store, section)):
2692
2685
        """Assert that some options have the proper values in a section."""
2693
2686
        expected_name, expected_options = expected
2694
 
        self.assertEqual(expected_name, section.id)
2695
 
        self.assertEqual(
 
2687
        self.assertEquals(expected_name, section.id)
 
2688
        self.assertEquals(
2696
2689
            expected_options,
2697
2690
            dict([(k, section.get(k)) for k in expected_options.keys()]))
2698
2691
 
2704
2697
 
2705
2698
    def test_building_delays_load(self):
2706
2699
        store = self.get_store(self)
2707
 
        self.assertEqual(False, store.is_loaded())
 
2700
        self.assertEquals(False, store.is_loaded())
2708
2701
        store._load_from_string('')
2709
 
        self.assertEqual(True, store.is_loaded())
 
2702
        self.assertEquals(True, store.is_loaded())
2710
2703
 
2711
2704
    def test_get_no_sections_for_empty(self):
2712
2705
        store = self.get_store(self)
2713
2706
        store._load_from_string('')
2714
 
        self.assertEqual([], list(store.get_sections()))
 
2707
        self.assertEquals([], list(store.get_sections()))
2715
2708
 
2716
2709
    def test_get_default_section(self):
2717
2710
        store = self.get_store(self)
2752
2745
 
2753
2746
        :param s: A string, quoted if required.
2754
2747
        """
2755
 
        self.assertEqual(s, self.store.quote(self.store.unquote(s)))
2756
 
        self.assertEqual(s, self.store.unquote(self.store.quote(s)))
 
2748
        self.assertEquals(s, self.store.quote(self.store.unquote(s)))
 
2749
        self.assertEquals(s, self.store.unquote(self.store.quote(s)))
2757
2750
 
2758
2751
    def test_empty_string(self):
2759
2752
        if isinstance(self.store, config.IniFileStore):
2797
2790
        value = conf.get('a_section')
2798
2791
        # Urgh, despite 'conf' asking for the no-name section, we get the
2799
2792
        # content of another section as a dict o_O
2800
 
        self.assertEqual({'a': '1'}, value)
 
2793
        self.assertEquals({'a': '1'}, value)
2801
2794
        unquoted = conf.store.unquote(value)
2802
2795
        # Which cannot be unquoted but shouldn't crash either (the use cases
2803
2796
        # are getting the value or displaying it. In the later case, '%s' will
2804
2797
        # do).
2805
 
        self.assertEqual({'a': '1'}, unquoted)
2806
 
        self.assertEqual("{u'a': u'1'}", '%s' % (unquoted,))
 
2798
        self.assertEquals({'a': '1'}, unquoted)
 
2799
        self.assertEquals("{u'a': u'1'}", '%s' % (unquoted,))
2807
2800
 
2808
2801
 
2809
2802
class TestIniFileStoreContent(tests.TestCaseWithTransport):
2829
2822
        store = config.TransportIniFileStore(t, 'foo.conf')
2830
2823
        store.load()
2831
2824
        stack = config.Stack([store.get_sections], store)
2832
 
        self.assertEqual(unicode_user, stack.get('user'))
 
2825
        self.assertEquals(unicode_user, stack.get('user'))
2833
2826
 
2834
2827
    def test_load_non_ascii(self):
2835
2828
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2859
2852
        t.get_bytes = get_bytes
2860
2853
        store = config.TransportIniFileStore(t, 'foo.conf')
2861
2854
        self.assertRaises(errors.PermissionDenied, store.load)
2862
 
        self.assertEqual(
 
2855
        self.assertEquals(
2863
2856
            warnings,
2864
2857
            [u'Permission denied while trying to load configuration store %s.'
2865
2858
             % store.external_url()])
2886
2879
        with open('foo.conf', 'wb') as f:
2887
2880
            f.write(utf8_content)
2888
2881
        conf = config.IniBasedConfig(file_name='foo.conf')
2889
 
        self.assertEqual(unicode_user, conf.get_user_option('user'))
 
2882
        self.assertEquals(unicode_user, conf.get_user_option('user'))
2890
2883
 
2891
2884
    def test_load_badly_encoded_content(self):
2892
2885
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2925
2918
                'branch.conf is *always* created when a branch is initialized')
2926
2919
        store = self.get_store(self)
2927
2920
        store.save()
2928
 
        self.assertEqual(False, self.has_store(store))
 
2921
        self.assertEquals(False, self.has_store(store))
2929
2922
 
2930
2923
    def test_mutable_section_shared(self):
2931
2924
        store = self.get_store(self)
2952
2945
        section = store.get_mutable_section(None)
2953
2946
        section.remove('foo')
2954
2947
        store.save()
2955
 
        self.assertEqual(True, self.has_store(store))
 
2948
        self.assertEquals(True, self.has_store(store))
2956
2949
        modified_store = self.get_store(self)
2957
2950
        sections = list(modified_store.get_sections())
2958
2951
        self.assertLength(0, sections)
2965
2958
                'branch.conf is *always* created when a branch is initialized')
2966
2959
        store = self.get_store(self)
2967
2960
        store._load_from_string('foo=bar\n')
2968
 
        self.assertEqual(False, self.has_store(store))
 
2961
        self.assertEquals(False, self.has_store(store))
2969
2962
        store.save()
2970
 
        self.assertEqual(True, self.has_store(store))
 
2963
        self.assertEquals(True, self.has_store(store))
2971
2964
        modified_store = self.get_store(self)
2972
2965
        sections = list(modified_store.get_sections())
2973
2966
        self.assertLength(1, sections)
3040
3033
        self.assertLength(0, calls)
3041
3034
        store.load()
3042
3035
        self.assertLength(1, calls)
3043
 
        self.assertEqual((store,), calls[0])
 
3036
        self.assertEquals((store,), calls[0])
3044
3037
 
3045
3038
    def test_save_hook(self):
3046
3039
        calls = []
3058
3051
        section.set('foo', 'bar')
3059
3052
        store.save()
3060
3053
        self.assertLength(1, calls)
3061
 
        self.assertEqual((store,), calls[0])
 
3054
        self.assertEquals((store,), calls[0])
3062
3055
 
3063
3056
    def test_set_mark_dirty(self):
3064
3057
        stack = config.MemoryStack('')
3103
3096
    def test_no_changes_no_save(self):
3104
3097
        s = self.get_stack(self.st1)
3105
3098
        s.store.save_changes()
3106
 
        self.assertEqual(False, self.has_store(self.st1))
 
3099
        self.assertEquals(False, self.has_store(self.st1))
3107
3100
 
3108
3101
    def test_unrelated_concurrent_update(self):
3109
3102
        s1 = self.get_stack(self.st1)
3112
3105
        s2.set('baz', 'quux')
3113
3106
        s1.store.save()
3114
3107
        # Changes don't propagate magically
3115
 
        self.assertEqual(None, s1.get('baz'))
 
3108
        self.assertEquals(None, s1.get('baz'))
3116
3109
        s2.store.save_changes()
3117
 
        self.assertEqual('quux', s2.get('baz'))
 
3110
        self.assertEquals('quux', s2.get('baz'))
3118
3111
        # Changes are acquired when saving
3119
 
        self.assertEqual('bar', s2.get('foo'))
 
3112
        self.assertEquals('bar', s2.get('foo'))
3120
3113
        # Since there is no overlap, no warnings are emitted
3121
3114
        self.assertLength(0, self.warnings)
3122
3115
 
3128
3121
        s1.store.save()
3129
3122
        # Last speaker wins
3130
3123
        s2.store.save_changes()
3131
 
        self.assertEqual('baz', s2.get('foo'))
 
3124
        self.assertEquals('baz', s2.get('foo'))
3132
3125
        # But the user get a warning
3133
3126
        self.assertLength(1, self.warnings)
3134
3127
        warning = self.warnings[0]
3164
3157
        store = self.get_store()
3165
3158
        store._load_from_string('foo= " abc "')
3166
3159
        stack = config.Stack([store.get_sections])
3167
 
        self.assertEqual(' abc ', stack.get('foo'))
 
3160
        self.assertEquals(' abc ', stack.get('foo'))
3168
3161
 
3169
3162
    def test_set_quoted_string(self):
3170
3163
        store = self.get_store()
3183
3176
 
3184
3177
    def test_invalid_content(self):
3185
3178
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
3186
 
        self.assertEqual(False, store.is_loaded())
 
3179
        self.assertEquals(False, store.is_loaded())
3187
3180
        exc = self.assertRaises(
3188
3181
            errors.ParseConfigError, store._load_from_string,
3189
3182
            'this is invalid !')
3190
3183
        self.assertEndsWith(exc.filename, 'foo.conf')
3191
3184
        # And the load failed
3192
 
        self.assertEqual(False, store.is_loaded())
 
3185
        self.assertEquals(False, store.is_loaded())
3193
3186
 
3194
3187
    def test_get_embedded_sections(self):
3195
3188
        # A more complicated example (which also shows that section names and
3262
3255
        self.stack.store.save()
3263
3256
 
3264
3257
    def test_simple_read_access(self):
3265
 
        self.assertEqual('1', self.stack.get('one'))
 
3258
        self.assertEquals('1', self.stack.get('one'))
3266
3259
 
3267
3260
    def test_simple_write_access(self):
3268
3261
        self.stack.set('one', 'one')
3269
 
        self.assertEqual('one', self.stack.get('one'))
 
3262
        self.assertEquals('one', self.stack.get('one'))
3270
3263
 
3271
3264
    def test_listen_to_the_last_speaker(self):
3272
3265
        c1 = self.stack
3273
3266
        c2 = self.get_stack(self)
3274
3267
        c1.set('one', 'ONE')
3275
3268
        c2.set('two', 'TWO')
3276
 
        self.assertEqual('ONE', c1.get('one'))
3277
 
        self.assertEqual('TWO', c2.get('two'))
 
3269
        self.assertEquals('ONE', c1.get('one'))
 
3270
        self.assertEquals('TWO', c2.get('two'))
3278
3271
        # The second update respect the first one
3279
 
        self.assertEqual('ONE', c2.get('one'))
 
3272
        self.assertEquals('ONE', c2.get('one'))
3280
3273
 
3281
3274
    def test_last_speaker_wins(self):
3282
3275
        # If the same config is not shared, the same variable modified twice
3285
3278
        c2 = self.get_stack(self)
3286
3279
        c1.set('one', 'c1')
3287
3280
        c2.set('one', 'c2')
3288
 
        self.assertEqual('c2', c2.get('one'))
 
3281
        self.assertEquals('c2', c2.get('one'))
3289
3282
        # The first modification is still available until another refresh
3290
3283
        # occur
3291
 
        self.assertEqual('c1', c1.get('one'))
 
3284
        self.assertEquals('c1', c1.get('one'))
3292
3285
        c1.set('two', 'done')
3293
 
        self.assertEqual('c2', c1.get('one'))
 
3286
        self.assertEquals('c2', c1.get('one'))
3294
3287
 
3295
3288
    def test_writes_are_serialized(self):
3296
3289
        c1 = self.stack
3320
3313
        before_writing.wait()
3321
3314
        self.assertRaises(errors.LockContention,
3322
3315
                          c2.set, 'one', 'c2')
3323
 
        self.assertEqual('c1', c1.get('one'))
 
3316
        self.assertEquals('c1', c1.get('one'))
3324
3317
        # Let the lock be released
3325
3318
        after_writing.set()
3326
3319
        writing_done.wait()
3327
3320
        c2.set('one', 'c2')
3328
 
        self.assertEqual('c2', c2.get('one'))
 
3321
        self.assertEquals('c2', c2.get('one'))
3329
3322
 
3330
3323
    def test_read_while_writing(self):
3331
3324
       c1 = self.stack
3353
3346
       t1.start()
3354
3347
       # Ensure the thread is ready to write
3355
3348
       ready_to_write.wait()
3356
 
       self.assertEqual('c1', c1.get('one'))
 
3349
       self.assertEquals('c1', c1.get('one'))
3357
3350
       # If we read during the write, we get the old value
3358
3351
       c2 = self.get_stack(self)
3359
 
       self.assertEqual('1', c2.get('one'))
 
3352
       self.assertEquals('1', c2.get('one'))
3360
3353
       # Let the writing occur and ensure it occurred
3361
3354
       do_writing.set()
3362
3355
       writing_done.wait()
3363
3356
       # Now we get the updated value
3364
3357
       c3 = self.get_stack(self)
3365
 
       self.assertEqual('c1', c3.get('one'))
 
3358
       self.assertEquals('c1', c3.get('one'))
3366
3359
 
3367
3360
    # FIXME: It may be worth looking into removing the lock dir when it's not
3368
3361
    # needed anymore and look at possible fallouts for concurrent lockers. This
3384
3377
        store = self.get_store(self)
3385
3378
        store._load_from_string('')
3386
3379
        matcher = self.matcher(store, '/bar')
3387
 
        self.assertEqual([], list(matcher.get_sections()))
 
3380
        self.assertEquals([], list(matcher.get_sections()))
3388
3381
 
3389
3382
    def test_build_doesnt_load_store(self):
3390
3383
        store = self.get_store(self)
3400
3393
 
3401
3394
    def test_simple_option(self):
3402
3395
        section = self.get_section({'foo': 'bar'}, '')
3403
 
        self.assertEqual('bar', section.get('foo'))
 
3396
        self.assertEquals('bar', section.get('foo'))
3404
3397
 
3405
3398
    def test_option_with_extra_path(self):
3406
3399
        section = self.get_section({'foo': 'bar', 'foo:policy': 'appendpath'},
3407
3400
                                   'baz')
3408
 
        self.assertEqual('bar/baz', section.get('foo'))
 
3401
        self.assertEquals('bar/baz', section.get('foo'))
3409
3402
 
3410
3403
    def test_invalid_policy(self):
3411
3404
        section = self.get_section({'foo': 'bar', 'foo:policy': 'die'},
3412
3405
                                   'baz')
3413
3406
        # invalid policies are ignored
3414
 
        self.assertEqual('bar', section.get('foo'))
 
3407
        self.assertEquals('bar', section.get('foo'))
3415
3408
 
3416
3409
 
3417
3410
class TestLocationMatcher(TestStore):
3435
3428
[/quux/quux]
3436
3429
section=/quux/quux
3437
3430
''')
3438
 
        self.assertEqual(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
 
3431
        self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
3439
3432
                           '/quux/quux'],
3440
3433
                          [section.id for _, section in store.get_sections()])
3441
3434
        matcher = config.LocationMatcher(store, '/foo/bar/quux')
3442
3435
        sections = [section for _, section in matcher.get_sections()]
3443
 
        self.assertEqual(['/foo/bar', '/foo'],
 
3436
        self.assertEquals(['/foo/bar', '/foo'],
3444
3437
                          [section.id for section in sections])
3445
 
        self.assertEqual(['quux', 'bar/quux'],
 
3438
        self.assertEquals(['quux', 'bar/quux'],
3446
3439
                          [section.extra_path for section in sections])
3447
3440
 
3448
3441
    def test_more_specific_sections_first(self):
3453
3446
[/foo/bar]
3454
3447
section=/foo/bar
3455
3448
''')
3456
 
        self.assertEqual(['/foo', '/foo/bar'],
 
3449
        self.assertEquals(['/foo', '/foo/bar'],
3457
3450
                          [section.id for _, section in store.get_sections()])
3458
3451
        matcher = config.LocationMatcher(store, '/foo/bar/baz')
3459
3452
        sections = [section for _, section in matcher.get_sections()]
3460
 
        self.assertEqual(['/foo/bar', '/foo'],
 
3453
        self.assertEquals(['/foo/bar', '/foo'],
3461
3454
                          [section.id for section in sections])
3462
 
        self.assertEqual(['baz', 'bar/baz'],
 
3455
        self.assertEquals(['baz', 'bar/baz'],
3463
3456
                          [section.extra_path for section in sections])
3464
3457
 
3465
3458
    def test_appendpath_in_no_name_section(self):
3473
3466
        matcher = config.LocationMatcher(store, 'dir/subdir')
3474
3467
        sections = list(matcher.get_sections())
3475
3468
        self.assertLength(1, sections)
3476
 
        self.assertEqual('bar/dir/subdir', sections[0][1].get('foo'))
 
3469
        self.assertEquals('bar/dir/subdir', sections[0][1].get('foo'))
3477
3470
 
3478
3471
    def test_file_urls_are_normalized(self):
3479
3472
        store = self.get_store(self)
3484
3477
            expected_url = 'file:///dir/subdir'
3485
3478
            expected_location = '/dir/subdir'
3486
3479
        matcher = config.LocationMatcher(store, expected_url)
3487
 
        self.assertEqual(expected_location, matcher.location)
 
3480
        self.assertEquals(expected_location, matcher.location)
3488
3481
 
3489
3482
    def test_branch_name_colo(self):
3490
3483
        store = self.get_store(self)
3553
3546
[/foo]
3554
3547
[/foo/bar]
3555
3548
''')
3556
 
        self.assertEqual(['baz', 'bar/baz', '/foo/bar/baz'],
 
3549
        self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
3557
3550
                          [s.locals['relpath'] for _, s in sections])
3558
3551
 
3559
3552
    def test_order_reversed(self):
3580
3573
        # Note that 'baz' as a relpath for /foo/b* is not fully correct, but
3581
3574
        # nothing really is... as far using {relpath} to append it to something
3582
3575
        # else, this seems good enough though.
3583
 
        self.assertEqual(['', 'baz', 'bar/baz'],
 
3576
        self.assertEquals(['', 'baz', 'bar/baz'],
3584
3577
                          [s.locals['relpath'] for _, s in sections])
3585
3578
 
3586
3579
    def test_respect_order(self):
3636
3629
        store2 = config.IniFileStore()
3637
3630
        store2._load_from_string('foo=baz')
3638
3631
        conf = config.Stack([store1.get_sections, store2.get_sections])
3639
 
        self.assertEqual('bar', conf.get('foo'))
 
3632
        self.assertEquals('bar', conf.get('foo'))
3640
3633
 
3641
3634
    def test_get_with_registered_default_value(self):
3642
3635
        config.option_registry.register(config.Option('foo', default='bar'))
3643
3636
        conf_stack = config.Stack([])
3644
 
        self.assertEqual('bar', conf_stack.get('foo'))
 
3637
        self.assertEquals('bar', conf_stack.get('foo'))
3645
3638
 
3646
3639
    def test_get_without_registered_default_value(self):
3647
3640
        config.option_registry.register(config.Option('foo'))
3648
3641
        conf_stack = config.Stack([])
3649
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3642
        self.assertEquals(None, conf_stack.get('foo'))
3650
3643
 
3651
3644
    def test_get_without_default_value_for_not_registered(self):
3652
3645
        conf_stack = config.Stack([])
3653
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3646
        self.assertEquals(None, conf_stack.get('foo'))
3654
3647
 
3655
3648
    def test_get_for_empty_section_callable(self):
3656
3649
        conf_stack = config.Stack([lambda : []])
3657
 
        self.assertEqual(None, conf_stack.get('foo'))
 
3650
        self.assertEquals(None, conf_stack.get('foo'))
3658
3651
 
3659
3652
    def test_get_for_broken_callable(self):
3660
3653
        # Trying to use and invalid callable raises an exception on first use
3679
3672
        self.overrideEnv('FOO', 'quux')
3680
3673
        # Env variable provides a default taking over the option one
3681
3674
        conf = self.get_conf('foo=store')
3682
 
        self.assertEqual('quux', conf.get('foo'))
 
3675
        self.assertEquals('quux', conf.get('foo'))
3683
3676
 
3684
3677
    def test_first_override_value_from_env_wins(self):
3685
3678
        self.overrideEnv('NO_VALUE', None)
3692
3685
        self.overrideEnv('BAZ', 'baz')
3693
3686
        # The first env var set wins
3694
3687
        conf = self.get_conf('foo=store')
3695
 
        self.assertEqual('foo', conf.get('foo'))
 
3688
        self.assertEquals('foo', conf.get('foo'))
3696
3689
 
3697
3690
 
3698
3691
class TestMemoryStack(tests.TestCase):
3699
3692
 
3700
3693
    def test_get(self):
3701
3694
        conf = config.MemoryStack('foo=bar')
3702
 
        self.assertEqual('bar', conf.get('foo'))
 
3695
        self.assertEquals('bar', conf.get('foo'))
3703
3696
 
3704
3697
    def test_set(self):
3705
3698
        conf = config.MemoryStack('foo=bar')
3706
3699
        conf.set('foo', 'baz')
3707
 
        self.assertEqual('baz', conf.get('foo'))
 
3700
        self.assertEquals('baz', conf.get('foo'))
3708
3701
 
3709
3702
    def test_no_content(self):
3710
3703
        conf = config.MemoryStack()
3713
3706
        self.assertRaises(NotImplementedError, conf.get, 'foo')
3714
3707
        # But a content can still be provided
3715
3708
        conf.store._load_from_string('foo=bar')
3716
 
        self.assertEqual('bar', conf.get('foo'))
 
3709
        self.assertEquals('bar', conf.get('foo'))
3717
3710
 
3718
3711
 
3719
3712
class TestStackIterSections(tests.TestCase):
3771
3764
        self.conf = self.get_stack(self)
3772
3765
 
3773
3766
    def test_get_for_empty_stack(self):
3774
 
        self.assertEqual(None, self.conf.get('foo'))
 
3767
        self.assertEquals(None, self.conf.get('foo'))
3775
3768
 
3776
3769
    def test_get_hook(self):
3777
3770
        self.conf.set('foo', 'bar')
3781
3774
        config.ConfigHooks.install_named_hook('get', hook, None)
3782
3775
        self.assertLength(0, calls)
3783
3776
        value = self.conf.get('foo')
3784
 
        self.assertEqual('bar', value)
 
3777
        self.assertEquals('bar', value)
3785
3778
        self.assertLength(1, calls)
3786
 
        self.assertEqual((self.conf, 'foo', 'bar'), calls[0])
 
3779
        self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
3787
3780
 
3788
3781
 
3789
3782
class TestStackGetWithConverter(tests.TestCase):
3805
3798
    def test_get_default_bool_None(self):
3806
3799
        self.register_bool_option('foo')
3807
3800
        conf = self.get_conf('')
3808
 
        self.assertEqual(None, conf.get('foo'))
 
3801
        self.assertEquals(None, conf.get('foo'))
3809
3802
 
3810
3803
    def test_get_default_bool_True(self):
3811
3804
        self.register_bool_option('foo', u'True')
3812
3805
        conf = self.get_conf('')
3813
 
        self.assertEqual(True, conf.get('foo'))
 
3806
        self.assertEquals(True, conf.get('foo'))
3814
3807
 
3815
3808
    def test_get_default_bool_False(self):
3816
3809
        self.register_bool_option('foo', False)
3817
3810
        conf = self.get_conf('')
3818
 
        self.assertEqual(False, conf.get('foo'))
 
3811
        self.assertEquals(False, conf.get('foo'))
3819
3812
 
3820
3813
    def test_get_default_bool_False_as_string(self):
3821
3814
        self.register_bool_option('foo', u'False')
3822
3815
        conf = self.get_conf('')
3823
 
        self.assertEqual(False, conf.get('foo'))
 
3816
        self.assertEquals(False, conf.get('foo'))
3824
3817
 
3825
3818
    def test_get_default_bool_from_env_converted(self):
3826
3819
        self.register_bool_option('foo', u'True', default_from_env=['FOO'])
3827
3820
        self.overrideEnv('FOO', 'False')
3828
3821
        conf = self.get_conf('')
3829
 
        self.assertEqual(False, conf.get('foo'))
 
3822
        self.assertEquals(False, conf.get('foo'))
3830
3823
 
3831
3824
    def test_get_default_bool_when_conversion_fails(self):
3832
3825
        self.register_bool_option('foo', default='True')
3833
3826
        conf = self.get_conf('foo=invalid boolean')
3834
 
        self.assertEqual(True, conf.get('foo'))
 
3827
        self.assertEquals(True, conf.get('foo'))
3835
3828
 
3836
3829
    def register_integer_option(self, name,
3837
3830
                                default=None, default_from_env=None):
3843
3836
    def test_get_default_integer_None(self):
3844
3837
        self.register_integer_option('foo')
3845
3838
        conf = self.get_conf('')
3846
 
        self.assertEqual(None, conf.get('foo'))
 
3839
        self.assertEquals(None, conf.get('foo'))
3847
3840
 
3848
3841
    def test_get_default_integer(self):
3849
3842
        self.register_integer_option('foo', 42)
3850
3843
        conf = self.get_conf('')
3851
 
        self.assertEqual(42, conf.get('foo'))
 
3844
        self.assertEquals(42, conf.get('foo'))
3852
3845
 
3853
3846
    def test_get_default_integer_as_string(self):
3854
3847
        self.register_integer_option('foo', u'42')
3855
3848
        conf = self.get_conf('')
3856
 
        self.assertEqual(42, conf.get('foo'))
 
3849
        self.assertEquals(42, conf.get('foo'))
3857
3850
 
3858
3851
    def test_get_default_integer_from_env(self):
3859
3852
        self.register_integer_option('foo', default_from_env=['FOO'])
3860
3853
        self.overrideEnv('FOO', '18')
3861
3854
        conf = self.get_conf('')
3862
 
        self.assertEqual(18, conf.get('foo'))
 
3855
        self.assertEquals(18, conf.get('foo'))
3863
3856
 
3864
3857
    def test_get_default_integer_when_conversion_fails(self):
3865
3858
        self.register_integer_option('foo', default='12')
3866
3859
        conf = self.get_conf('foo=invalid integer')
3867
 
        self.assertEqual(12, conf.get('foo'))
 
3860
        self.assertEquals(12, conf.get('foo'))
3868
3861
 
3869
3862
    def register_list_option(self, name, default=None, default_from_env=None):
3870
3863
        l = config.ListOption(name, help='A list.', default=default,
3874
3867
    def test_get_default_list_None(self):
3875
3868
        self.register_list_option('foo')
3876
3869
        conf = self.get_conf('')
3877
 
        self.assertEqual(None, conf.get('foo'))
 
3870
        self.assertEquals(None, conf.get('foo'))
3878
3871
 
3879
3872
    def test_get_default_list_empty(self):
3880
3873
        self.register_list_option('foo', '')
3881
3874
        conf = self.get_conf('')
3882
 
        self.assertEqual([], conf.get('foo'))
 
3875
        self.assertEquals([], conf.get('foo'))
3883
3876
 
3884
3877
    def test_get_default_list_from_env(self):
3885
3878
        self.register_list_option('foo', default_from_env=['FOO'])
3886
3879
        self.overrideEnv('FOO', '')
3887
3880
        conf = self.get_conf('')
3888
 
        self.assertEqual([], conf.get('foo'))
 
3881
        self.assertEquals([], conf.get('foo'))
3889
3882
 
3890
3883
    def test_get_with_list_converter_no_item(self):
3891
3884
        self.register_list_option('foo', None)
3892
3885
        conf = self.get_conf('foo=,')
3893
 
        self.assertEqual([], conf.get('foo'))
 
3886
        self.assertEquals([], conf.get('foo'))
3894
3887
 
3895
3888
    def test_get_with_list_converter_many_items(self):
3896
3889
        self.register_list_option('foo', None)
3897
3890
        conf = self.get_conf('foo=m,o,r,e')
3898
 
        self.assertEqual(['m', 'o', 'r', 'e'], conf.get('foo'))
 
3891
        self.assertEquals(['m', 'o', 'r', 'e'], conf.get('foo'))
3899
3892
 
3900
3893
    def test_get_with_list_converter_embedded_spaces_many_items(self):
3901
3894
        self.register_list_option('foo', None)
3902
3895
        conf = self.get_conf('foo=" bar", "baz "')
3903
 
        self.assertEqual([' bar', 'baz '], conf.get('foo'))
 
3896
        self.assertEquals([' bar', 'baz '], conf.get('foo'))
3904
3897
 
3905
3898
    def test_get_with_list_converter_stripped_spaces_many_items(self):
3906
3899
        self.register_list_option('foo', None)
3907
3900
        conf = self.get_conf('foo= bar ,  baz ')
3908
 
        self.assertEqual(['bar', 'baz'], conf.get('foo'))
 
3901
        self.assertEquals(['bar', 'baz'], conf.get('foo'))
3909
3902
 
3910
3903
 
3911
3904
class TestIterOptionRefs(tests.TestCase):
3912
3905
    """iter_option_refs is a bit unusual, document some cases."""
3913
3906
 
3914
3907
    def assertRefs(self, expected, string):
3915
 
        self.assertEqual(expected, list(config.iter_option_refs(string)))
 
3908
        self.assertEquals(expected, list(config.iter_option_refs(string)))
3916
3909
 
3917
3910
    def test_empty(self):
3918
3911
        self.assertRefs([(False, '')], '')
3950
3943
        self.conf = config.Stack([store.get_sections], store)
3951
3944
 
3952
3945
    def assertExpansion(self, expected, string, env=None):
3953
 
        self.assertEqual(expected, self.conf.expand_options(string, env))
 
3946
        self.assertEquals(expected, self.conf.expand_options(string, env))
3954
3947
 
3955
3948
    def test_no_expansion(self):
3956
3949
        self.assertExpansion('foo', 'foo')
3958
3951
    def test_expand_default_value(self):
3959
3952
        self.conf.store._load_from_string('bar=baz')
3960
3953
        self.registry.register(config.Option('foo', default=u'{bar}'))
3961
 
        self.assertEqual('baz', self.conf.get('foo', expand=True))
 
3954
        self.assertEquals('baz', self.conf.get('foo', expand=True))
3962
3955
 
3963
3956
    def test_expand_default_from_env(self):
3964
3957
        self.conf.store._load_from_string('bar=baz')
3965
3958
        self.registry.register(config.Option('foo', default_from_env=['FOO']))
3966
3959
        self.overrideEnv('FOO', '{bar}')
3967
 
        self.assertEqual('baz', self.conf.get('foo', expand=True))
 
3960
        self.assertEquals('baz', self.conf.get('foo', expand=True))
3968
3961
 
3969
3962
    def test_expand_default_on_failed_conversion(self):
3970
3963
        self.conf.store._load_from_string('baz=bogus\nbar=42\nfoo={baz}')
3971
3964
        self.registry.register(
3972
3965
            config.Option('foo', default=u'{bar}',
3973
3966
                          from_unicode=config.int_from_store))
3974
 
        self.assertEqual(42, self.conf.get('foo', expand=True))
 
3967
        self.assertEquals(42, self.conf.get('foo', expand=True))
3975
3968
 
3976
3969
    def test_env_adding_options(self):
3977
3970
        self.assertExpansion('bar', '{foo}', {'foo': 'bar'})
4019
4012
baz={foo}''')
4020
4013
        e = self.assertRaises(errors.OptionExpansionLoop,
4021
4014
                              self.conf.expand_options, '{foo}')
4022
 
        self.assertEqual('foo->bar->baz', e.refs)
4023
 
        self.assertEqual('{foo}', e.string)
 
4015
        self.assertEquals('foo->bar->baz', e.refs)
 
4016
        self.assertEquals('{foo}', e.string)
4024
4017
 
4025
4018
    def test_list(self):
4026
4019
        self.conf.store._load_from_string('''
4031
4024
''')
4032
4025
        self.registry.register(
4033
4026
            config.ListOption('list'))
4034
 
        self.assertEqual(['start', 'middle', 'end'],
 
4027
        self.assertEquals(['start', 'middle', 'end'],
4035
4028
                           self.conf.get('list', expand=True))
4036
4029
 
4037
4030
    def test_cascading_list(self):
4046
4039
        # happen while expanding. Conversion should only occur for the original
4047
4040
        # option ('list' here).
4048
4041
        self.registry.register(config.ListOption('baz'))
4049
 
        self.assertEqual(['start', 'middle', 'end'],
 
4042
        self.assertEquals(['start', 'middle', 'end'],
4050
4043
                           self.conf.get('list', expand=True))
4051
4044
 
4052
4045
    def test_pathologically_hidden_list(self):
4061
4054
        # What matters is what the registration says, the conversion happens
4062
4055
        # only after all expansions have been performed
4063
4056
        self.registry.register(config.ListOption('hidden'))
4064
 
        self.assertEqual(['bin', 'go'],
 
4057
        self.assertEquals(['bin', 'go'],
4065
4058
                          self.conf.get('hidden', expand=True))
4066
4059
 
4067
4060
 
4099
4092
[/project/branch/path]
4100
4093
bar = {foo}ux
4101
4094
''')
4102
 
        self.assertEqual('quux', c.get('bar', expand=True))
 
4095
        self.assertEquals('quux', c.get('bar', expand=True))
4103
4096
 
4104
4097
 
4105
4098
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
4120
4113
''')
4121
4114
        g_store.save()
4122
4115
        stack = config.LocationStack('/branch')
4123
 
        self.assertEqual('glob-bar', stack.get('lbar', expand=True))
4124
 
        self.assertEqual('loc-foo', stack.get('gfoo', expand=True))
 
4116
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
 
4117
        self.assertEquals('loc-foo', stack.get('gfoo', expand=True))
4125
4118
 
4126
4119
 
4127
4120
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
4135
4128
''')
4136
4129
        l_store.save()
4137
4130
        stack = config.LocationStack('/home/user/project/')
4138
 
        self.assertEqual('', stack.get('base', expand=True))
4139
 
        self.assertEqual('', stack.get('rel', expand=True))
 
4131
        self.assertEquals('', stack.get('base', expand=True))
 
4132
        self.assertEquals('', stack.get('rel', expand=True))
4140
4133
 
4141
4134
    def test_expand_basename_locally(self):
4142
4135
        l_store = config.LocationStore()
4146
4139
''')
4147
4140
        l_store.save()
4148
4141
        stack = config.LocationStack('/home/user/project/branch')
4149
 
        self.assertEqual('branch', stack.get('bfoo', expand=True))
 
4142
        self.assertEquals('branch', stack.get('bfoo', expand=True))
4150
4143
 
4151
4144
    def test_expand_basename_locally_longer_path(self):
4152
4145
        l_store = config.LocationStore()
4156
4149
''')
4157
4150
        l_store.save()
4158
4151
        stack = config.LocationStack('/home/user/project/dir/branch')
4159
 
        self.assertEqual('branch', stack.get('bfoo', expand=True))
 
4152
        self.assertEquals('branch', stack.get('bfoo', expand=True))
4160
4153
 
4161
4154
    def test_expand_relpath_locally(self):
4162
4155
        l_store = config.LocationStore()
4166
4159
''')
4167
4160
        l_store.save()
4168
4161
        stack = config.LocationStack('/home/user/project/branch')
4169
 
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
 
4162
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
4170
4163
 
4171
4164
    def test_expand_relpath_unknonw_in_global(self):
4172
4165
        g_store = config.GlobalStore()
4195
4188
''')
4196
4189
        g_store.save()
4197
4190
        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))
 
4191
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
 
4192
        self.assertEquals('loc-foo/branch', stack.get('gfoo', expand=True))
4200
4193
 
4201
4194
    def test_locals_dont_leak(self):
4202
4195
        """Make sure we chose the right local in presence of several sections.
4210
4203
''')
4211
4204
        l_store.save()
4212
4205
        stack = config.LocationStack('/home/user/project/branch')
4213
 
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
 
4206
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
4214
4207
        stack = config.LocationStack('/home/user/bar/baz')
4215
 
        self.assertEqual('loc-foo/bar/baz', stack.get('lfoo', expand=True))
 
4208
        self.assertEquals('loc-foo/bar/baz', stack.get('lfoo', expand=True))
4216
4209
 
4217
4210
 
4218
4211
 
4220
4213
 
4221
4214
    def test_simple_set(self):
4222
4215
        conf = self.get_stack(self)
4223
 
        self.assertEqual(None, conf.get('foo'))
 
4216
        self.assertEquals(None, conf.get('foo'))
4224
4217
        conf.set('foo', 'baz')
4225
4218
        # Did we get it back ?
4226
 
        self.assertEqual('baz', conf.get('foo'))
 
4219
        self.assertEquals('baz', conf.get('foo'))
4227
4220
 
4228
4221
    def test_set_creates_a_new_section(self):
4229
4222
        conf = self.get_stack(self)
4230
4223
        conf.set('foo', 'baz')
4231
 
        self.assertEqual, 'baz', conf.get('foo')
 
4224
        self.assertEquals, 'baz', conf.get('foo')
4232
4225
 
4233
4226
    def test_set_hook(self):
4234
4227
        calls = []
4239
4232
        conf = self.get_stack(self)
4240
4233
        conf.set('foo', 'bar')
4241
4234
        self.assertLength(1, calls)
4242
 
        self.assertEqual((conf, 'foo', 'bar'), calls[0])
 
4235
        self.assertEquals((conf, 'foo', 'bar'), calls[0])
4243
4236
 
4244
4237
 
4245
4238
class TestStackRemove(TestStackWithTransport):
4247
4240
    def test_remove_existing(self):
4248
4241
        conf = self.get_stack(self)
4249
4242
        conf.set('foo', 'bar')
4250
 
        self.assertEqual('bar', conf.get('foo'))
 
4243
        self.assertEquals('bar', conf.get('foo'))
4251
4244
        conf.remove('foo')
4252
4245
        # Did we get it back ?
4253
 
        self.assertEqual(None, conf.get('foo'))
 
4246
        self.assertEquals(None, conf.get('foo'))
4254
4247
 
4255
4248
    def test_remove_unknown(self):
4256
4249
        conf = self.get_stack(self)
4266
4259
        conf.set('foo', 'bar')
4267
4260
        conf.remove('foo')
4268
4261
        self.assertLength(1, calls)
4269
 
        self.assertEqual((conf, 'foo'), calls[0])
 
4262
        self.assertEquals((conf, 'foo'), calls[0])
4270
4263
 
4271
4264
 
4272
4265
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
4441
4434
        else:
4442
4435
            user = credentials['user']
4443
4436
            password = credentials['password']
4444
 
        self.assertEqual(expected_user, user)
4445
 
        self.assertEqual(expected_password, password)
 
4437
        self.assertEquals(expected_user, user)
 
4438
        self.assertEquals(expected_password, password)
4446
4439
 
4447
4440
    def test_empty_config(self):
4448
4441
        conf = config.AuthenticationConfig(_file=StringIO())
4449
 
        self.assertEqual({}, conf._get_config())
 
4442
        self.assertEquals({}, conf._get_config())
4450
4443
        self._got_user_passwd(None, None, conf, 'http', 'foo.net')
4451
4444
 
4452
4445
    def test_non_utf8_config(self):
4634
4627
password=bendover
4635
4628
"""))
4636
4629
        credentials = conf.get_credentials('https', 'bar.org')
4637
 
        self.assertEqual(False, credentials.get('verify_certificates'))
 
4630
        self.assertEquals(False, credentials.get('verify_certificates'))
4638
4631
        credentials = conf.get_credentials('https', 'foo.net')
4639
 
        self.assertEqual(True, credentials.get('verify_certificates'))
 
4632
        self.assertEquals(True, credentials.get('verify_certificates'))
4640
4633
 
4641
4634
 
4642
4635
class TestAuthenticationStorage(tests.TestCaseInTempDir):
4689
4682
                                            stdout=stdout, stderr=stderr)
4690
4683
        # We use an empty conf so that the user is always prompted
4691
4684
        conf = config.AuthenticationConfig()
4692
 
        self.assertEqual(password,
 
4685
        self.assertEquals(password,
4693
4686
                          conf.get_password(scheme, host, user, port=port,
4694
4687
                                            realm=realm, path=path))
4695
 
        self.assertEqual(expected_prompt, stderr.getvalue())
4696
 
        self.assertEqual('', stdout.getvalue())
 
4688
        self.assertEquals(expected_prompt, stderr.getvalue())
 
4689
        self.assertEquals('', stdout.getvalue())
4697
4690
 
4698
4691
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
4699
4692
                                       host=None, port=None, realm=None,
4710
4703
                                            stdout=stdout, stderr=stderr)
4711
4704
        # We use an empty conf so that the user is always prompted
4712
4705
        conf = config.AuthenticationConfig()
4713
 
        self.assertEqual(username, conf.get_user(scheme, host, port=port,
 
4706
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
4714
4707
                          realm=realm, path=path, ask=True))
4715
 
        self.assertEqual(expected_prompt, stderr.getvalue())
4716
 
        self.assertEqual('', stdout.getvalue())
 
4708
        self.assertEquals(expected_prompt, stderr.getvalue())
 
4709
        self.assertEquals('', stdout.getvalue())
4717
4710
 
4718
4711
    def test_username_defaults_prompts(self):
4719
4712
        # HTTP prompts can't be tested here, see test_http.py
4725
4718
 
4726
4719
    def test_username_default_no_prompt(self):
4727
4720
        conf = config.AuthenticationConfig()
4728
 
        self.assertEqual(None,
 
4721
        self.assertEquals(None,
4729
4722
            conf.get_user('ftp', 'example.com'))
4730
 
        self.assertEqual("explicitdefault",
 
4723
        self.assertEquals("explicitdefault",
4731
4724
            conf.get_user('ftp', 'example.com', default="explicitdefault"))
4732
4725
 
4733
4726
    def test_password_default_prompts(self):
4766
4759
 
4767
4760
        # Since the password defined in the authentication config is ignored,
4768
4761
        # the user is prompted
4769
 
        self.assertEqual(entered_password,
 
4762
        self.assertEquals(entered_password,
4770
4763
                          conf.get_password('ssh', 'bar.org', user='jim'))
4771
4764
        self.assertContainsRe(
4772
4765
            self.get_log(),
4789
4782
 
4790
4783
        # Since the password defined in the authentication config is ignored,
4791
4784
        # the user is prompted
4792
 
        self.assertEqual(entered_password,
 
4785
        self.assertEquals(entered_password,
4793
4786
                          conf.get_password('ssh', 'bar.org', user='jim'))
4794
4787
        # No warning shoud be emitted since there is no password. We are only
4795
4788
        # providing "user".
4805
4798
        config.credential_store_registry.register("stub", store, fallback=True)
4806
4799
        conf = config.AuthenticationConfig(_file=StringIO())
4807
4800
        creds = conf.get_credentials("http", "example.com")
4808
 
        self.assertEqual("joe", creds["user"])
4809
 
        self.assertEqual("secret", creds["password"])
 
4801
        self.assertEquals("joe", creds["user"])
 
4802
        self.assertEquals("secret", creds["password"])
4810
4803
 
4811
4804
 
4812
4805
class StubCredentialStore(config.CredentialStore):
4857
4850
 
4858
4851
    def test_fallback_none_registered(self):
4859
4852
        r = config.CredentialStoreRegistry()
4860
 
        self.assertEqual(None,
 
4853
        self.assertEquals(None,
4861
4854
                          r.get_fallback_credentials("http", "example.com"))
4862
4855
 
4863
4856
    def test_register(self):
4864
4857
        r = config.CredentialStoreRegistry()
4865
4858
        r.register("stub", StubCredentialStore(), fallback=False)
4866
4859
        r.register("another", StubCredentialStore(), fallback=True)
4867
 
        self.assertEqual(["another", "stub"], r.keys())
 
4860
        self.assertEquals(["another", "stub"], r.keys())
4868
4861
 
4869
4862
    def test_register_lazy(self):
4870
4863
        r = config.CredentialStoreRegistry()
4871
4864
        r.register_lazy("stub", "bzrlib.tests.test_config",
4872
4865
                        "StubCredentialStore", fallback=False)
4873
 
        self.assertEqual(["stub"], r.keys())
 
4866
        self.assertEquals(["stub"], r.keys())
4874
4867
        self.assertIsInstance(r.get_credential_store("stub"),
4875
4868
                              StubCredentialStore)
4876
4869
 
4878
4871
        r = config.CredentialStoreRegistry()
4879
4872
        r.register("stub1", None, fallback=False)
4880
4873
        r.register("stub2", None, fallback=True)
4881
 
        self.assertEqual(False, r.is_fallback("stub1"))
4882
 
        self.assertEqual(True, r.is_fallback("stub2"))
 
4874
        self.assertEquals(False, r.is_fallback("stub1"))
 
4875
        self.assertEquals(True, r.is_fallback("stub2"))
4883
4876
 
4884
4877
    def test_no_fallback(self):
4885
4878
        r = config.CredentialStoreRegistry()
4886
4879
        store = CountingCredentialStore()
4887
4880
        r.register("count", store, fallback=False)
4888
 
        self.assertEqual(None,
 
4881
        self.assertEquals(None,
4889
4882
                          r.get_fallback_credentials("http", "example.com"))
4890
 
        self.assertEqual(0, store._calls)
 
4883
        self.assertEquals(0, store._calls)
4891
4884
 
4892
4885
    def test_fallback_credentials(self):
4893
4886
        r = config.CredentialStoreRegistry()
4896
4889
                              "somebody", "geheim")
4897
4890
        r.register("stub", store, fallback=True)
4898
4891
        creds = r.get_fallback_credentials("http", "example.com")
4899
 
        self.assertEqual("somebody", creds["user"])
4900
 
        self.assertEqual("geheim", creds["password"])
 
4892
        self.assertEquals("somebody", creds["user"])
 
4893
        self.assertEquals("geheim", creds["password"])
4901
4894
 
4902
4895
    def test_fallback_first_wins(self):
4903
4896
        r = config.CredentialStoreRegistry()
4910
4903
                              "somebody", "stub2")
4911
4904
        r.register("stub2", stub1, fallback=True)
4912
4905
        creds = r.get_fallback_credentials("http", "example.com")
4913
 
        self.assertEqual("somebody", creds["user"])
4914
 
        self.assertEqual("stub1", creds["password"])
 
4906
        self.assertEquals("somebody", creds["user"])
 
4907
        self.assertEquals("stub1", creds["password"])
4915
4908
 
4916
4909
 
4917
4910
class TestPlainTextCredentialStore(tests.TestCase):
4920
4913
        r = config.credential_store_registry
4921
4914
        plain_text = r.get_credential_store()
4922
4915
        decoded = plain_text.decode_password(dict(password='secret'))
4923
 
        self.assertEqual('secret', decoded)
 
4916
        self.assertEquals('secret', decoded)
4924
4917
 
4925
4918
 
4926
4919
class TestBase64CredentialStore(tests.TestCase):
4929
4922
        r = config.credential_store_registry
4930
4923
        plain_text = r.get_credential_store('base64')
4931
4924
        decoded = plain_text.decode_password(dict(password='c2VjcmV0'))
4932
 
        self.assertEqual('secret', decoded)
 
4925
        self.assertEquals('secret', decoded)
4933
4926
 
4934
4927
 
4935
4928
# FIXME: Once we have a way to declare authentication to all test servers, we
4963
4956
            self.assertIsNot(None, realname)
4964
4957
            self.assertIsNot(None, address)
4965
4958
        else:
4966
 
            self.assertEqual((None, None), (realname, address))
 
4959
            self.assertEquals((None, None), (realname, address))
4967
4960
 
4968
4961
 
4969
4962
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4976
4969
        finally:
4977
4970
            f.close()
4978
4971
        r = config._get_default_mail_domain('simple')
4979
 
        self.assertEqual('domainname.com', r)
 
4972
        self.assertEquals('domainname.com', r)
4980
4973
 
4981
4974
    def test_default_mail_domain_no_eol(self):
4982
4975
        f = file('no_eol', 'w')
4985
4978
        finally:
4986
4979
            f.close()
4987
4980
        r = config._get_default_mail_domain('no_eol')
4988
 
        self.assertEqual('domainname.com', r)
 
4981
        self.assertEquals('domainname.com', r)
4989
4982
 
4990
4983
    def test_default_mail_domain_multiple_lines(self):
4991
4984
        f = file('multiple_lines', 'w')
4994
4987
        finally:
4995
4988
            f.close()
4996
4989
        r = config._get_default_mail_domain('multiple_lines')
4997
 
        self.assertEqual('domainname.com', r)
 
4990
        self.assertEquals('domainname.com', r)
4998
4991
 
4999
4992
 
5000
4993
class EmailOptionTests(tests.TestCase):
5004
4997
        # BZR_EMAIL takes precedence over EMAIL
5005
4998
        self.overrideEnv('BZR_EMAIL', 'jelmer@samba.org')
5006
4999
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5007
 
        self.assertEqual('jelmer@samba.org', conf.get('email'))
 
5000
        self.assertEquals('jelmer@samba.org', conf.get('email'))
5008
5001
 
5009
5002
    def test_default_email_uses_EMAIL(self):
5010
5003
        conf = config.MemoryStack('')
5011
5004
        self.overrideEnv('BZR_EMAIL', None)
5012
5005
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5013
 
        self.assertEqual('jelmer@apache.org', conf.get('email'))
 
5006
        self.assertEquals('jelmer@apache.org', conf.get('email'))
5014
5007
 
5015
5008
    def test_BZR_EMAIL_overrides(self):
5016
5009
        conf = config.MemoryStack('email=jelmer@debian.org')
5017
5010
        self.overrideEnv('BZR_EMAIL', 'jelmer@apache.org')
5018
 
        self.assertEqual('jelmer@apache.org', conf.get('email'))
 
5011
        self.assertEquals('jelmer@apache.org', conf.get('email'))
5019
5012
        self.overrideEnv('BZR_EMAIL', None)
5020
5013
        self.overrideEnv('EMAIL', 'jelmer@samba.org')
5021
 
        self.assertEqual('jelmer@debian.org', conf.get('email'))
 
5014
        self.assertEquals('jelmer@debian.org', conf.get('email'))
5022
5015
 
5023
5016
 
5024
5017
class MailClientOptionTests(tests.TestCase):