~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: 2016-02-01 19:13:13 UTC
  • mfrom: (6614.2.2 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201191313-wdfvmfff1djde6oq
(vila) Release 2.7.0 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
448
448
        output = outfile.getvalue()
449
449
        # now we're trying to read it back
450
450
        co2 = config.ConfigObj(StringIO(output))
451
 
        self.assertEquals(triple_quotes_value, co2['test'])
 
451
        self.assertEqual(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.assertEquals(self.path, './foo.conf')
 
652
        self.assertEqual(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.assertEquals(expected, conf.expand_options(string, env))
 
702
        self.assertEqual(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.assertEquals('foo->bar->baz', e.refs)
751
 
        self.assertEquals('{foo}', e.string)
 
750
        self.assertEqual('foo->bar->baz', e.refs)
 
751
        self.assertEqual('{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.assertEquals(['start', 'middle', 'end'],
 
760
        self.assertEqual(['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.assertEquals(['start', 'middle', 'end'],
 
770
        self.assertEqual(['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.assertEquals(['{foo', '}', '{', 'bar}'],
 
784
        self.assertEqual(['{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.assertEquals('quux', c.get_user_option('bar', expand=True))
 
818
        self.assertEqual('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.assertEquals('1', self.config.get_user_option('one'))
 
864
        self.assertEqual('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.assertEquals('one', self.config.get_user_option('one'))
 
868
        self.assertEqual('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.assertEquals('ONE', c1.get_user_option('one'))
876
 
        self.assertEquals('TWO', c2.get_user_option('two'))
 
875
        self.assertEqual('ONE', c1.get_user_option('one'))
 
876
        self.assertEqual('TWO', c2.get_user_option('two'))
877
877
        # The second update respect the first one
878
 
        self.assertEquals('ONE', c2.get_user_option('one'))
 
878
        self.assertEqual('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.assertEquals('c2', c2._get_user_option('one'))
 
887
        self.assertEqual('c2', c2._get_user_option('one'))
888
888
        # The first modification is still available until another refresh
889
889
        # occur
890
 
        self.assertEquals('c1', c1._get_user_option('one'))
 
890
        self.assertEqual('c1', c1._get_user_option('one'))
891
891
        c1.set_user_option('two', 'done')
892
 
        self.assertEquals('c2', c1._get_user_option('one'))
 
892
        self.assertEqual('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.assertEquals('c1', c1.get_user_option('one'))
 
923
        self.assertEqual('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.assertEquals('c2', c2.get_user_option('one'))
 
928
        self.assertEqual('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.assertEquals('c1', c1.get_user_option('one'))
 
956
       self.assertEqual('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.assertEquals('1', c2.get_user_option('one'))
 
959
       self.assertEqual('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.assertEquals('c1', c3.get_user_option('one'))
 
965
       self.assertEqual('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.assertEquals(msg % ('maybe', 'an_invalid_bool'), warnings[0])
 
986
        self.assertEqual(msg % ('maybe', 'an_invalid_bool'), warnings[0])
987
987
        warnings = []
988
988
        self.assertIs(None, get_bool('not_defined_in_this_config'))
989
 
        self.assertEquals([], warnings)
 
989
        self.assertEqual([], 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.assertEquals('kdiff3 {base} {this} {other} -o {result}', cmdline)
 
1343
        self.assertEqual('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.assertEquals(unicode_user, conf.get_option('user'))
 
1909
        self.assertEqual(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.assertEquals(
 
1943
        self.assertEqual(
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.assertEquals(value, actual_value)
 
2001
        self.assertEqual(value, actual_value)
2002
2002
        self.assertLength(1, calls)
2003
 
        self.assertEquals((conf, name, value), calls[0])
 
2003
        self.assertEqual((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.assertEquals((name, value), calls[0][1:])
 
2029
        self.assertEqual((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.assertEquals((name,), calls[0][1:])
 
2053
        self.assertEqual((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.assertEquals(value, actual_value)
 
2132
        self.assertEqual(value, actual_value)
2133
2133
        self.assertLength(1, calls)
2134
 
        self.assertEquals((conf, name, value), calls[0])
 
2134
        self.assertEqual((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.assertEquals((name, value), calls[0][1:])
 
2159
        self.assertEqual((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'))
2272
2272
 
2273
2273
    def test_default_value(self):
2274
2274
        opt = config.Option('foo', default='bar')
2275
 
        self.assertEquals('bar', opt.get_default())
 
2275
        self.assertEqual('bar', opt.get_default())
2276
2276
 
2277
2277
    def test_callable_default_value(self):
2278
2278
        def bar_as_unicode():
2279
2279
            return u'bar'
2280
2280
        opt = config.Option('foo', default=bar_as_unicode)
2281
 
        self.assertEquals('bar', opt.get_default())
 
2281
        self.assertEqual('bar', opt.get_default())
2282
2282
 
2283
2283
    def test_default_value_from_env(self):
2284
2284
        opt = config.Option('foo', default='bar', default_from_env=['FOO'])
2285
2285
        self.overrideEnv('FOO', 'quux')
2286
2286
        # Env variable provides a default taking over the option one
2287
 
        self.assertEquals('quux', opt.get_default())
 
2287
        self.assertEqual('quux', opt.get_default())
2288
2288
 
2289
2289
    def test_first_default_value_from_env_wins(self):
2290
2290
        opt = config.Option('foo', default='bar',
2292
2292
        self.overrideEnv('FOO', 'foo')
2293
2293
        self.overrideEnv('BAZ', 'baz')
2294
2294
        # The first env var set wins
2295
 
        self.assertEquals('foo', opt.get_default())
 
2295
        self.assertEqual('foo', opt.get_default())
2296
2296
 
2297
2297
    def test_not_supported_list_default_value(self):
2298
2298
        self.assertRaises(AssertionError, config.Option, 'foo', default=[1])
2309
2309
 
2310
2310
    def test_get_help_topic(self):
2311
2311
        opt = config.Option('foo')
2312
 
        self.assertEquals('foo', opt.get_help_topic())
 
2312
        self.assertEqual('foo', opt.get_help_topic())
2313
2313
 
2314
2314
 
2315
2315
class TestOptionConverter(tests.TestCase):
2316
2316
 
2317
2317
    def assertConverted(self, expected, opt, value):
2318
 
        self.assertEquals(expected, opt.convert_from_unicode(None, value))
 
2318
        self.assertEqual(expected, opt.convert_from_unicode(None, value))
2319
2319
 
2320
2320
    def assertCallsWarning(self, opt, value):
2321
2321
        warnings = []
2323
2323
        def warning(*args):
2324
2324
            warnings.append(args[0] % args[1:])
2325
2325
        self.overrideAttr(trace, 'warning', warning)
2326
 
        self.assertEquals(None, opt.convert_from_unicode(None, value))
 
2326
        self.assertEqual(None, opt.convert_from_unicode(None, value))
2327
2327
        self.assertLength(1, warnings)
2328
 
        self.assertEquals(
 
2328
        self.assertEqual(
2329
2329
            'Value "%s" is not valid for "%s"' % (value, opt.name),
2330
2330
            warnings[0])
2331
2331
 
2335
2335
 
2336
2336
    def assertConvertInvalid(self, opt, invalid_value):
2337
2337
        opt.invalid = None
2338
 
        self.assertEquals(None, opt.convert_from_unicode(None, invalid_value))
 
2338
        self.assertEqual(None, opt.convert_from_unicode(None, invalid_value))
2339
2339
        opt.invalid = 'warning'
2340
2340
        self.assertCallsWarning(opt, invalid_value)
2341
2341
        opt.invalid = 'error'
2456
2456
        registry.register("someval", 1234, help="some option")
2457
2457
        registry.register("dunno", 1234, help="some other option")
2458
2458
        opt = self.get_option(registry)
2459
 
        self.assertEquals(
 
2459
        self.assertEqual(
2460
2460
            'A registry option.\n'
2461
2461
            '\n'
2462
2462
            'The following values are supported:\n'
2469
2469
        registry.register("someval", 1234, help="some option")
2470
2470
        registry.register("dunno", 1234, help="some other option")
2471
2471
        opt = self.get_option(registry)
2472
 
        self.assertEquals(
 
2472
        self.assertEqual(
2473
2473
            'A registry option.\n'
2474
2474
            '\n'
2475
2475
            'The following values are supported:\n'
2494
2494
    def test_registered_help(self):
2495
2495
        opt = config.Option('foo', help='A simple option')
2496
2496
        self.registry.register(opt)
2497
 
        self.assertEquals('A simple option', self.registry.get_help('foo'))
 
2497
        self.assertEqual('A simple option', self.registry.get_help('foo'))
2498
2498
 
2499
2499
    def test_dont_register_illegal_name(self):
2500
2500
        self.assertRaises(errors.IllegalOptionName,
2512
2512
    def test_registered_lazy_help(self):
2513
2513
        self.registry.register_lazy('lazy_foo', self.__module__,
2514
2514
                                    'TestOptionRegistry.lazy_option')
2515
 
        self.assertEquals('Lazy help', self.registry.get_help('lazy_foo'))
 
2515
        self.assertEqual('Lazy help', self.registry.get_help('lazy_foo'))
2516
2516
 
2517
2517
    def test_dont_lazy_register_illegal_name(self):
2518
2518
        # This is where the root cause of http://pad.lv/1235099 is better
2541
2541
    def test_proper_name(self):
2542
2542
        # An option should be registered under its own name, this can't be
2543
2543
        # checked at registration time for the lazy ones.
2544
 
        self.assertEquals(self.option_name, self.option.name)
 
2544
        self.assertEqual(self.option_name, self.option.name)
2545
2545
 
2546
2546
    def test_help_is_set(self):
2547
2547
        option_help = self.registry.get_help(self.option_name)
2548
2548
        # Come on, think about the user, he really wants to know what the
2549
2549
        # option is about
2550
2550
        self.assertIsNot(None, option_help)
2551
 
        self.assertNotEquals('', option_help)
 
2551
        self.assertNotEqual('', option_help)
2552
2552
 
2553
2553
 
2554
2554
class TestSection(tests.TestCase):
2559
2559
    def test_get_a_value(self):
2560
2560
        a_dict = dict(foo='bar')
2561
2561
        section = config.Section('myID', a_dict)
2562
 
        self.assertEquals('bar', section.get('foo'))
 
2562
        self.assertEqual('bar', section.get('foo'))
2563
2563
 
2564
2564
    def test_get_unknown_option(self):
2565
2565
        a_dict = dict()
2566
2566
        section = config.Section(None, a_dict)
2567
 
        self.assertEquals('out of thin air',
 
2567
        self.assertEqual('out of thin air',
2568
2568
                          section.get('foo', 'out of thin air'))
2569
2569
 
2570
2570
    def test_options_is_shared(self):
2584
2584
        a_dict = dict(foo='bar')
2585
2585
        section = self.get_section(a_dict)
2586
2586
        section.set('foo', 'new_value')
2587
 
        self.assertEquals('new_value', section.get('foo'))
 
2587
        self.assertEqual('new_value', section.get('foo'))
2588
2588
        # The change appears in the shared section
2589
 
        self.assertEquals('new_value', a_dict.get('foo'))
 
2589
        self.assertEqual('new_value', a_dict.get('foo'))
2590
2590
        # We keep track of the change
2591
2591
        self.assertTrue('foo' in section.orig)
2592
 
        self.assertEquals('bar', section.orig.get('foo'))
 
2592
        self.assertEqual('bar', section.orig.get('foo'))
2593
2593
 
2594
2594
    def test_set_preserve_original_once(self):
2595
2595
        a_dict = dict(foo='bar')
2598
2598
        section.set('foo', 'second_value')
2599
2599
        # We keep track of the original value
2600
2600
        self.assertTrue('foo' in section.orig)
2601
 
        self.assertEquals('bar', section.orig.get('foo'))
 
2601
        self.assertEqual('bar', section.orig.get('foo'))
2602
2602
 
2603
2603
    def test_remove(self):
2604
2604
        a_dict = dict(foo='bar')
2605
2605
        section = self.get_section(a_dict)
2606
2606
        section.remove('foo')
2607
2607
        # We get None for unknown options via the default value
2608
 
        self.assertEquals(None, section.get('foo'))
 
2608
        self.assertEqual(None, section.get('foo'))
2609
2609
        # Or we just get the default value
2610
 
        self.assertEquals('unknown', section.get('foo', 'unknown'))
 
2610
        self.assertEqual('unknown', section.get('foo', 'unknown'))
2611
2611
        self.assertFalse('foo' in section.options)
2612
2612
        # We keep track of the deletion
2613
2613
        self.assertTrue('foo' in section.orig)
2614
 
        self.assertEquals('bar', section.orig.get('foo'))
 
2614
        self.assertEqual('bar', section.orig.get('foo'))
2615
2615
 
2616
2616
    def test_remove_new_option(self):
2617
2617
        a_dict = dict()
2622
2622
        # The option didn't exist initially so it we need to keep track of it
2623
2623
        # with a special value
2624
2624
        self.assertTrue('foo' in section.orig)
2625
 
        self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
 
2625
        self.assertEqual(config._NewlyCreatedOption, section.orig['foo'])
2626
2626
 
2627
2627
 
2628
2628
class TestCommandLineStore(tests.TestCase):
2637
2637
        sections = list(self.store.get_sections())
2638
2638
        self.assertLength(1, sections)
2639
2639
        store, section = sections[0]
2640
 
        self.assertEquals(self.store, store)
 
2640
        self.assertEqual(self.store, store)
2641
2641
        return section
2642
2642
 
2643
2643
    def test_no_override(self):
2664
2664
    def test_multiple_overrides(self):
2665
2665
        self.store._from_cmdline(['a=b', 'x=y'])
2666
2666
        section = self.get_section()
2667
 
        self.assertEquals('b', section.get('a'))
2668
 
        self.assertEquals('y', section.get('x'))
 
2667
        self.assertEqual('b', section.get('a'))
 
2668
        self.assertEqual('y', section.get('x'))
2669
2669
 
2670
2670
    def test_wrong_syntax(self):
2671
2671
        self.assertRaises(errors.BzrCommandError,
2691
2691
    def assertSectionContent(self, expected, (store, section)):
2692
2692
        """Assert that some options have the proper values in a section."""
2693
2693
        expected_name, expected_options = expected
2694
 
        self.assertEquals(expected_name, section.id)
2695
 
        self.assertEquals(
 
2694
        self.assertEqual(expected_name, section.id)
 
2695
        self.assertEqual(
2696
2696
            expected_options,
2697
2697
            dict([(k, section.get(k)) for k in expected_options.keys()]))
2698
2698
 
2704
2704
 
2705
2705
    def test_building_delays_load(self):
2706
2706
        store = self.get_store(self)
2707
 
        self.assertEquals(False, store.is_loaded())
 
2707
        self.assertEqual(False, store.is_loaded())
2708
2708
        store._load_from_string('')
2709
 
        self.assertEquals(True, store.is_loaded())
 
2709
        self.assertEqual(True, store.is_loaded())
2710
2710
 
2711
2711
    def test_get_no_sections_for_empty(self):
2712
2712
        store = self.get_store(self)
2713
2713
        store._load_from_string('')
2714
 
        self.assertEquals([], list(store.get_sections()))
 
2714
        self.assertEqual([], list(store.get_sections()))
2715
2715
 
2716
2716
    def test_get_default_section(self):
2717
2717
        store = self.get_store(self)
2752
2752
 
2753
2753
        :param s: A string, quoted if required.
2754
2754
        """
2755
 
        self.assertEquals(s, self.store.quote(self.store.unquote(s)))
2756
 
        self.assertEquals(s, self.store.unquote(self.store.quote(s)))
 
2755
        self.assertEqual(s, self.store.quote(self.store.unquote(s)))
 
2756
        self.assertEqual(s, self.store.unquote(self.store.quote(s)))
2757
2757
 
2758
2758
    def test_empty_string(self):
2759
2759
        if isinstance(self.store, config.IniFileStore):
2797
2797
        value = conf.get('a_section')
2798
2798
        # Urgh, despite 'conf' asking for the no-name section, we get the
2799
2799
        # content of another section as a dict o_O
2800
 
        self.assertEquals({'a': '1'}, value)
 
2800
        self.assertEqual({'a': '1'}, value)
2801
2801
        unquoted = conf.store.unquote(value)
2802
2802
        # Which cannot be unquoted but shouldn't crash either (the use cases
2803
2803
        # are getting the value or displaying it. In the later case, '%s' will
2804
2804
        # do).
2805
 
        self.assertEquals({'a': '1'}, unquoted)
2806
 
        self.assertEquals("{u'a': u'1'}", '%s' % (unquoted,))
 
2805
        self.assertEqual({'a': '1'}, unquoted)
 
2806
        self.assertEqual("{u'a': u'1'}", '%s' % (unquoted,))
2807
2807
 
2808
2808
 
2809
2809
class TestIniFileStoreContent(tests.TestCaseWithTransport):
2829
2829
        store = config.TransportIniFileStore(t, 'foo.conf')
2830
2830
        store.load()
2831
2831
        stack = config.Stack([store.get_sections], store)
2832
 
        self.assertEquals(unicode_user, stack.get('user'))
 
2832
        self.assertEqual(unicode_user, stack.get('user'))
2833
2833
 
2834
2834
    def test_load_non_ascii(self):
2835
2835
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2859
2859
        t.get_bytes = get_bytes
2860
2860
        store = config.TransportIniFileStore(t, 'foo.conf')
2861
2861
        self.assertRaises(errors.PermissionDenied, store.load)
2862
 
        self.assertEquals(
 
2862
        self.assertEqual(
2863
2863
            warnings,
2864
2864
            [u'Permission denied while trying to load configuration store %s.'
2865
2865
             % store.external_url()])
2886
2886
        with open('foo.conf', 'wb') as f:
2887
2887
            f.write(utf8_content)
2888
2888
        conf = config.IniBasedConfig(file_name='foo.conf')
2889
 
        self.assertEquals(unicode_user, conf.get_user_option('user'))
 
2889
        self.assertEqual(unicode_user, conf.get_user_option('user'))
2890
2890
 
2891
2891
    def test_load_badly_encoded_content(self):
2892
2892
        """Ensure we display a proper error on non-ascii, non utf-8 content."""
2925
2925
                'branch.conf is *always* created when a branch is initialized')
2926
2926
        store = self.get_store(self)
2927
2927
        store.save()
2928
 
        self.assertEquals(False, self.has_store(store))
 
2928
        self.assertEqual(False, self.has_store(store))
2929
2929
 
2930
2930
    def test_mutable_section_shared(self):
2931
2931
        store = self.get_store(self)
2952
2952
        section = store.get_mutable_section(None)
2953
2953
        section.remove('foo')
2954
2954
        store.save()
2955
 
        self.assertEquals(True, self.has_store(store))
 
2955
        self.assertEqual(True, self.has_store(store))
2956
2956
        modified_store = self.get_store(self)
2957
2957
        sections = list(modified_store.get_sections())
2958
2958
        self.assertLength(0, sections)
2965
2965
                'branch.conf is *always* created when a branch is initialized')
2966
2966
        store = self.get_store(self)
2967
2967
        store._load_from_string('foo=bar\n')
2968
 
        self.assertEquals(False, self.has_store(store))
 
2968
        self.assertEqual(False, self.has_store(store))
2969
2969
        store.save()
2970
 
        self.assertEquals(True, self.has_store(store))
 
2970
        self.assertEqual(True, self.has_store(store))
2971
2971
        modified_store = self.get_store(self)
2972
2972
        sections = list(modified_store.get_sections())
2973
2973
        self.assertLength(1, sections)
3040
3040
        self.assertLength(0, calls)
3041
3041
        store.load()
3042
3042
        self.assertLength(1, calls)
3043
 
        self.assertEquals((store,), calls[0])
 
3043
        self.assertEqual((store,), calls[0])
3044
3044
 
3045
3045
    def test_save_hook(self):
3046
3046
        calls = []
3058
3058
        section.set('foo', 'bar')
3059
3059
        store.save()
3060
3060
        self.assertLength(1, calls)
3061
 
        self.assertEquals((store,), calls[0])
 
3061
        self.assertEqual((store,), calls[0])
3062
3062
 
3063
3063
    def test_set_mark_dirty(self):
3064
3064
        stack = config.MemoryStack('')
3103
3103
    def test_no_changes_no_save(self):
3104
3104
        s = self.get_stack(self.st1)
3105
3105
        s.store.save_changes()
3106
 
        self.assertEquals(False, self.has_store(self.st1))
 
3106
        self.assertEqual(False, self.has_store(self.st1))
3107
3107
 
3108
3108
    def test_unrelated_concurrent_update(self):
3109
3109
        s1 = self.get_stack(self.st1)
3112
3112
        s2.set('baz', 'quux')
3113
3113
        s1.store.save()
3114
3114
        # Changes don't propagate magically
3115
 
        self.assertEquals(None, s1.get('baz'))
 
3115
        self.assertEqual(None, s1.get('baz'))
3116
3116
        s2.store.save_changes()
3117
 
        self.assertEquals('quux', s2.get('baz'))
 
3117
        self.assertEqual('quux', s2.get('baz'))
3118
3118
        # Changes are acquired when saving
3119
 
        self.assertEquals('bar', s2.get('foo'))
 
3119
        self.assertEqual('bar', s2.get('foo'))
3120
3120
        # Since there is no overlap, no warnings are emitted
3121
3121
        self.assertLength(0, self.warnings)
3122
3122
 
3128
3128
        s1.store.save()
3129
3129
        # Last speaker wins
3130
3130
        s2.store.save_changes()
3131
 
        self.assertEquals('baz', s2.get('foo'))
 
3131
        self.assertEqual('baz', s2.get('foo'))
3132
3132
        # But the user get a warning
3133
3133
        self.assertLength(1, self.warnings)
3134
3134
        warning = self.warnings[0]
3164
3164
        store = self.get_store()
3165
3165
        store._load_from_string('foo= " abc "')
3166
3166
        stack = config.Stack([store.get_sections])
3167
 
        self.assertEquals(' abc ', stack.get('foo'))
 
3167
        self.assertEqual(' abc ', stack.get('foo'))
3168
3168
 
3169
3169
    def test_set_quoted_string(self):
3170
3170
        store = self.get_store()
3183
3183
 
3184
3184
    def test_invalid_content(self):
3185
3185
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
3186
 
        self.assertEquals(False, store.is_loaded())
 
3186
        self.assertEqual(False, store.is_loaded())
3187
3187
        exc = self.assertRaises(
3188
3188
            errors.ParseConfigError, store._load_from_string,
3189
3189
            'this is invalid !')
3190
3190
        self.assertEndsWith(exc.filename, 'foo.conf')
3191
3191
        # And the load failed
3192
 
        self.assertEquals(False, store.is_loaded())
 
3192
        self.assertEqual(False, store.is_loaded())
3193
3193
 
3194
3194
    def test_get_embedded_sections(self):
3195
3195
        # A more complicated example (which also shows that section names and
3262
3262
        self.stack.store.save()
3263
3263
 
3264
3264
    def test_simple_read_access(self):
3265
 
        self.assertEquals('1', self.stack.get('one'))
 
3265
        self.assertEqual('1', self.stack.get('one'))
3266
3266
 
3267
3267
    def test_simple_write_access(self):
3268
3268
        self.stack.set('one', 'one')
3269
 
        self.assertEquals('one', self.stack.get('one'))
 
3269
        self.assertEqual('one', self.stack.get('one'))
3270
3270
 
3271
3271
    def test_listen_to_the_last_speaker(self):
3272
3272
        c1 = self.stack
3273
3273
        c2 = self.get_stack(self)
3274
3274
        c1.set('one', 'ONE')
3275
3275
        c2.set('two', 'TWO')
3276
 
        self.assertEquals('ONE', c1.get('one'))
3277
 
        self.assertEquals('TWO', c2.get('two'))
 
3276
        self.assertEqual('ONE', c1.get('one'))
 
3277
        self.assertEqual('TWO', c2.get('two'))
3278
3278
        # The second update respect the first one
3279
 
        self.assertEquals('ONE', c2.get('one'))
 
3279
        self.assertEqual('ONE', c2.get('one'))
3280
3280
 
3281
3281
    def test_last_speaker_wins(self):
3282
3282
        # If the same config is not shared, the same variable modified twice
3285
3285
        c2 = self.get_stack(self)
3286
3286
        c1.set('one', 'c1')
3287
3287
        c2.set('one', 'c2')
3288
 
        self.assertEquals('c2', c2.get('one'))
 
3288
        self.assertEqual('c2', c2.get('one'))
3289
3289
        # The first modification is still available until another refresh
3290
3290
        # occur
3291
 
        self.assertEquals('c1', c1.get('one'))
 
3291
        self.assertEqual('c1', c1.get('one'))
3292
3292
        c1.set('two', 'done')
3293
 
        self.assertEquals('c2', c1.get('one'))
 
3293
        self.assertEqual('c2', c1.get('one'))
3294
3294
 
3295
3295
    def test_writes_are_serialized(self):
3296
3296
        c1 = self.stack
3320
3320
        before_writing.wait()
3321
3321
        self.assertRaises(errors.LockContention,
3322
3322
                          c2.set, 'one', 'c2')
3323
 
        self.assertEquals('c1', c1.get('one'))
 
3323
        self.assertEqual('c1', c1.get('one'))
3324
3324
        # Let the lock be released
3325
3325
        after_writing.set()
3326
3326
        writing_done.wait()
3327
3327
        c2.set('one', 'c2')
3328
 
        self.assertEquals('c2', c2.get('one'))
 
3328
        self.assertEqual('c2', c2.get('one'))
3329
3329
 
3330
3330
    def test_read_while_writing(self):
3331
3331
       c1 = self.stack
3353
3353
       t1.start()
3354
3354
       # Ensure the thread is ready to write
3355
3355
       ready_to_write.wait()
3356
 
       self.assertEquals('c1', c1.get('one'))
 
3356
       self.assertEqual('c1', c1.get('one'))
3357
3357
       # If we read during the write, we get the old value
3358
3358
       c2 = self.get_stack(self)
3359
 
       self.assertEquals('1', c2.get('one'))
 
3359
       self.assertEqual('1', c2.get('one'))
3360
3360
       # Let the writing occur and ensure it occurred
3361
3361
       do_writing.set()
3362
3362
       writing_done.wait()
3363
3363
       # Now we get the updated value
3364
3364
       c3 = self.get_stack(self)
3365
 
       self.assertEquals('c1', c3.get('one'))
 
3365
       self.assertEqual('c1', c3.get('one'))
3366
3366
 
3367
3367
    # FIXME: It may be worth looking into removing the lock dir when it's not
3368
3368
    # needed anymore and look at possible fallouts for concurrent lockers. This
3384
3384
        store = self.get_store(self)
3385
3385
        store._load_from_string('')
3386
3386
        matcher = self.matcher(store, '/bar')
3387
 
        self.assertEquals([], list(matcher.get_sections()))
 
3387
        self.assertEqual([], list(matcher.get_sections()))
3388
3388
 
3389
3389
    def test_build_doesnt_load_store(self):
3390
3390
        store = self.get_store(self)
3400
3400
 
3401
3401
    def test_simple_option(self):
3402
3402
        section = self.get_section({'foo': 'bar'}, '')
3403
 
        self.assertEquals('bar', section.get('foo'))
 
3403
        self.assertEqual('bar', section.get('foo'))
3404
3404
 
3405
3405
    def test_option_with_extra_path(self):
3406
3406
        section = self.get_section({'foo': 'bar', 'foo:policy': 'appendpath'},
3407
3407
                                   'baz')
3408
 
        self.assertEquals('bar/baz', section.get('foo'))
 
3408
        self.assertEqual('bar/baz', section.get('foo'))
3409
3409
 
3410
3410
    def test_invalid_policy(self):
3411
3411
        section = self.get_section({'foo': 'bar', 'foo:policy': 'die'},
3412
3412
                                   'baz')
3413
3413
        # invalid policies are ignored
3414
 
        self.assertEquals('bar', section.get('foo'))
 
3414
        self.assertEqual('bar', section.get('foo'))
3415
3415
 
3416
3416
 
3417
3417
class TestLocationMatcher(TestStore):
3435
3435
[/quux/quux]
3436
3436
section=/quux/quux
3437
3437
''')
3438
 
        self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
 
3438
        self.assertEqual(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
3439
3439
                           '/quux/quux'],
3440
3440
                          [section.id for _, section in store.get_sections()])
3441
3441
        matcher = config.LocationMatcher(store, '/foo/bar/quux')
3442
3442
        sections = [section for _, section in matcher.get_sections()]
3443
 
        self.assertEquals(['/foo/bar', '/foo'],
 
3443
        self.assertEqual(['/foo/bar', '/foo'],
3444
3444
                          [section.id for section in sections])
3445
 
        self.assertEquals(['quux', 'bar/quux'],
 
3445
        self.assertEqual(['quux', 'bar/quux'],
3446
3446
                          [section.extra_path for section in sections])
3447
3447
 
3448
3448
    def test_more_specific_sections_first(self):
3453
3453
[/foo/bar]
3454
3454
section=/foo/bar
3455
3455
''')
3456
 
        self.assertEquals(['/foo', '/foo/bar'],
 
3456
        self.assertEqual(['/foo', '/foo/bar'],
3457
3457
                          [section.id for _, section in store.get_sections()])
3458
3458
        matcher = config.LocationMatcher(store, '/foo/bar/baz')
3459
3459
        sections = [section for _, section in matcher.get_sections()]
3460
 
        self.assertEquals(['/foo/bar', '/foo'],
 
3460
        self.assertEqual(['/foo/bar', '/foo'],
3461
3461
                          [section.id for section in sections])
3462
 
        self.assertEquals(['baz', 'bar/baz'],
 
3462
        self.assertEqual(['baz', 'bar/baz'],
3463
3463
                          [section.extra_path for section in sections])
3464
3464
 
3465
3465
    def test_appendpath_in_no_name_section(self):
3473
3473
        matcher = config.LocationMatcher(store, 'dir/subdir')
3474
3474
        sections = list(matcher.get_sections())
3475
3475
        self.assertLength(1, sections)
3476
 
        self.assertEquals('bar/dir/subdir', sections[0][1].get('foo'))
 
3476
        self.assertEqual('bar/dir/subdir', sections[0][1].get('foo'))
3477
3477
 
3478
3478
    def test_file_urls_are_normalized(self):
3479
3479
        store = self.get_store(self)
3484
3484
            expected_url = 'file:///dir/subdir'
3485
3485
            expected_location = '/dir/subdir'
3486
3486
        matcher = config.LocationMatcher(store, expected_url)
3487
 
        self.assertEquals(expected_location, matcher.location)
 
3487
        self.assertEqual(expected_location, matcher.location)
3488
3488
 
3489
3489
    def test_branch_name_colo(self):
3490
3490
        store = self.get_store(self)
3553
3553
[/foo]
3554
3554
[/foo/bar]
3555
3555
''')
3556
 
        self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
 
3556
        self.assertEqual(['baz', 'bar/baz', '/foo/bar/baz'],
3557
3557
                          [s.locals['relpath'] for _, s in sections])
3558
3558
 
3559
3559
    def test_order_reversed(self):
3580
3580
        # Note that 'baz' as a relpath for /foo/b* is not fully correct, but
3581
3581
        # nothing really is... as far using {relpath} to append it to something
3582
3582
        # else, this seems good enough though.
3583
 
        self.assertEquals(['', 'baz', 'bar/baz'],
 
3583
        self.assertEqual(['', 'baz', 'bar/baz'],
3584
3584
                          [s.locals['relpath'] for _, s in sections])
3585
3585
 
3586
3586
    def test_respect_order(self):
3636
3636
        store2 = config.IniFileStore()
3637
3637
        store2._load_from_string('foo=baz')
3638
3638
        conf = config.Stack([store1.get_sections, store2.get_sections])
3639
 
        self.assertEquals('bar', conf.get('foo'))
 
3639
        self.assertEqual('bar', conf.get('foo'))
3640
3640
 
3641
3641
    def test_get_with_registered_default_value(self):
3642
3642
        config.option_registry.register(config.Option('foo', default='bar'))
3643
3643
        conf_stack = config.Stack([])
3644
 
        self.assertEquals('bar', conf_stack.get('foo'))
 
3644
        self.assertEqual('bar', conf_stack.get('foo'))
3645
3645
 
3646
3646
    def test_get_without_registered_default_value(self):
3647
3647
        config.option_registry.register(config.Option('foo'))
3648
3648
        conf_stack = config.Stack([])
3649
 
        self.assertEquals(None, conf_stack.get('foo'))
 
3649
        self.assertEqual(None, conf_stack.get('foo'))
3650
3650
 
3651
3651
    def test_get_without_default_value_for_not_registered(self):
3652
3652
        conf_stack = config.Stack([])
3653
 
        self.assertEquals(None, conf_stack.get('foo'))
 
3653
        self.assertEqual(None, conf_stack.get('foo'))
3654
3654
 
3655
3655
    def test_get_for_empty_section_callable(self):
3656
3656
        conf_stack = config.Stack([lambda : []])
3657
 
        self.assertEquals(None, conf_stack.get('foo'))
 
3657
        self.assertEqual(None, conf_stack.get('foo'))
3658
3658
 
3659
3659
    def test_get_for_broken_callable(self):
3660
3660
        # Trying to use and invalid callable raises an exception on first use
3679
3679
        self.overrideEnv('FOO', 'quux')
3680
3680
        # Env variable provides a default taking over the option one
3681
3681
        conf = self.get_conf('foo=store')
3682
 
        self.assertEquals('quux', conf.get('foo'))
 
3682
        self.assertEqual('quux', conf.get('foo'))
3683
3683
 
3684
3684
    def test_first_override_value_from_env_wins(self):
3685
3685
        self.overrideEnv('NO_VALUE', None)
3692
3692
        self.overrideEnv('BAZ', 'baz')
3693
3693
        # The first env var set wins
3694
3694
        conf = self.get_conf('foo=store')
3695
 
        self.assertEquals('foo', conf.get('foo'))
 
3695
        self.assertEqual('foo', conf.get('foo'))
3696
3696
 
3697
3697
 
3698
3698
class TestMemoryStack(tests.TestCase):
3699
3699
 
3700
3700
    def test_get(self):
3701
3701
        conf = config.MemoryStack('foo=bar')
3702
 
        self.assertEquals('bar', conf.get('foo'))
 
3702
        self.assertEqual('bar', conf.get('foo'))
3703
3703
 
3704
3704
    def test_set(self):
3705
3705
        conf = config.MemoryStack('foo=bar')
3706
3706
        conf.set('foo', 'baz')
3707
 
        self.assertEquals('baz', conf.get('foo'))
 
3707
        self.assertEqual('baz', conf.get('foo'))
3708
3708
 
3709
3709
    def test_no_content(self):
3710
3710
        conf = config.MemoryStack()
3713
3713
        self.assertRaises(NotImplementedError, conf.get, 'foo')
3714
3714
        # But a content can still be provided
3715
3715
        conf.store._load_from_string('foo=bar')
3716
 
        self.assertEquals('bar', conf.get('foo'))
 
3716
        self.assertEqual('bar', conf.get('foo'))
3717
3717
 
3718
3718
 
3719
3719
class TestStackIterSections(tests.TestCase):
3771
3771
        self.conf = self.get_stack(self)
3772
3772
 
3773
3773
    def test_get_for_empty_stack(self):
3774
 
        self.assertEquals(None, self.conf.get('foo'))
 
3774
        self.assertEqual(None, self.conf.get('foo'))
3775
3775
 
3776
3776
    def test_get_hook(self):
3777
3777
        self.conf.set('foo', 'bar')
3781
3781
        config.ConfigHooks.install_named_hook('get', hook, None)
3782
3782
        self.assertLength(0, calls)
3783
3783
        value = self.conf.get('foo')
3784
 
        self.assertEquals('bar', value)
 
3784
        self.assertEqual('bar', value)
3785
3785
        self.assertLength(1, calls)
3786
 
        self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
 
3786
        self.assertEqual((self.conf, 'foo', 'bar'), calls[0])
3787
3787
 
3788
3788
 
3789
3789
class TestStackGetWithConverter(tests.TestCase):
3805
3805
    def test_get_default_bool_None(self):
3806
3806
        self.register_bool_option('foo')
3807
3807
        conf = self.get_conf('')
3808
 
        self.assertEquals(None, conf.get('foo'))
 
3808
        self.assertEqual(None, conf.get('foo'))
3809
3809
 
3810
3810
    def test_get_default_bool_True(self):
3811
3811
        self.register_bool_option('foo', u'True')
3812
3812
        conf = self.get_conf('')
3813
 
        self.assertEquals(True, conf.get('foo'))
 
3813
        self.assertEqual(True, conf.get('foo'))
3814
3814
 
3815
3815
    def test_get_default_bool_False(self):
3816
3816
        self.register_bool_option('foo', False)
3817
3817
        conf = self.get_conf('')
3818
 
        self.assertEquals(False, conf.get('foo'))
 
3818
        self.assertEqual(False, conf.get('foo'))
3819
3819
 
3820
3820
    def test_get_default_bool_False_as_string(self):
3821
3821
        self.register_bool_option('foo', u'False')
3822
3822
        conf = self.get_conf('')
3823
 
        self.assertEquals(False, conf.get('foo'))
 
3823
        self.assertEqual(False, conf.get('foo'))
3824
3824
 
3825
3825
    def test_get_default_bool_from_env_converted(self):
3826
3826
        self.register_bool_option('foo', u'True', default_from_env=['FOO'])
3827
3827
        self.overrideEnv('FOO', 'False')
3828
3828
        conf = self.get_conf('')
3829
 
        self.assertEquals(False, conf.get('foo'))
 
3829
        self.assertEqual(False, conf.get('foo'))
3830
3830
 
3831
3831
    def test_get_default_bool_when_conversion_fails(self):
3832
3832
        self.register_bool_option('foo', default='True')
3833
3833
        conf = self.get_conf('foo=invalid boolean')
3834
 
        self.assertEquals(True, conf.get('foo'))
 
3834
        self.assertEqual(True, conf.get('foo'))
3835
3835
 
3836
3836
    def register_integer_option(self, name,
3837
3837
                                default=None, default_from_env=None):
3843
3843
    def test_get_default_integer_None(self):
3844
3844
        self.register_integer_option('foo')
3845
3845
        conf = self.get_conf('')
3846
 
        self.assertEquals(None, conf.get('foo'))
 
3846
        self.assertEqual(None, conf.get('foo'))
3847
3847
 
3848
3848
    def test_get_default_integer(self):
3849
3849
        self.register_integer_option('foo', 42)
3850
3850
        conf = self.get_conf('')
3851
 
        self.assertEquals(42, conf.get('foo'))
 
3851
        self.assertEqual(42, conf.get('foo'))
3852
3852
 
3853
3853
    def test_get_default_integer_as_string(self):
3854
3854
        self.register_integer_option('foo', u'42')
3855
3855
        conf = self.get_conf('')
3856
 
        self.assertEquals(42, conf.get('foo'))
 
3856
        self.assertEqual(42, conf.get('foo'))
3857
3857
 
3858
3858
    def test_get_default_integer_from_env(self):
3859
3859
        self.register_integer_option('foo', default_from_env=['FOO'])
3860
3860
        self.overrideEnv('FOO', '18')
3861
3861
        conf = self.get_conf('')
3862
 
        self.assertEquals(18, conf.get('foo'))
 
3862
        self.assertEqual(18, conf.get('foo'))
3863
3863
 
3864
3864
    def test_get_default_integer_when_conversion_fails(self):
3865
3865
        self.register_integer_option('foo', default='12')
3866
3866
        conf = self.get_conf('foo=invalid integer')
3867
 
        self.assertEquals(12, conf.get('foo'))
 
3867
        self.assertEqual(12, conf.get('foo'))
3868
3868
 
3869
3869
    def register_list_option(self, name, default=None, default_from_env=None):
3870
3870
        l = config.ListOption(name, help='A list.', default=default,
3874
3874
    def test_get_default_list_None(self):
3875
3875
        self.register_list_option('foo')
3876
3876
        conf = self.get_conf('')
3877
 
        self.assertEquals(None, conf.get('foo'))
 
3877
        self.assertEqual(None, conf.get('foo'))
3878
3878
 
3879
3879
    def test_get_default_list_empty(self):
3880
3880
        self.register_list_option('foo', '')
3881
3881
        conf = self.get_conf('')
3882
 
        self.assertEquals([], conf.get('foo'))
 
3882
        self.assertEqual([], conf.get('foo'))
3883
3883
 
3884
3884
    def test_get_default_list_from_env(self):
3885
3885
        self.register_list_option('foo', default_from_env=['FOO'])
3886
3886
        self.overrideEnv('FOO', '')
3887
3887
        conf = self.get_conf('')
3888
 
        self.assertEquals([], conf.get('foo'))
 
3888
        self.assertEqual([], conf.get('foo'))
3889
3889
 
3890
3890
    def test_get_with_list_converter_no_item(self):
3891
3891
        self.register_list_option('foo', None)
3892
3892
        conf = self.get_conf('foo=,')
3893
 
        self.assertEquals([], conf.get('foo'))
 
3893
        self.assertEqual([], conf.get('foo'))
3894
3894
 
3895
3895
    def test_get_with_list_converter_many_items(self):
3896
3896
        self.register_list_option('foo', None)
3897
3897
        conf = self.get_conf('foo=m,o,r,e')
3898
 
        self.assertEquals(['m', 'o', 'r', 'e'], conf.get('foo'))
 
3898
        self.assertEqual(['m', 'o', 'r', 'e'], conf.get('foo'))
3899
3899
 
3900
3900
    def test_get_with_list_converter_embedded_spaces_many_items(self):
3901
3901
        self.register_list_option('foo', None)
3902
3902
        conf = self.get_conf('foo=" bar", "baz "')
3903
 
        self.assertEquals([' bar', 'baz '], conf.get('foo'))
 
3903
        self.assertEqual([' bar', 'baz '], conf.get('foo'))
3904
3904
 
3905
3905
    def test_get_with_list_converter_stripped_spaces_many_items(self):
3906
3906
        self.register_list_option('foo', None)
3907
3907
        conf = self.get_conf('foo= bar ,  baz ')
3908
 
        self.assertEquals(['bar', 'baz'], conf.get('foo'))
 
3908
        self.assertEqual(['bar', 'baz'], conf.get('foo'))
3909
3909
 
3910
3910
 
3911
3911
class TestIterOptionRefs(tests.TestCase):
3912
3912
    """iter_option_refs is a bit unusual, document some cases."""
3913
3913
 
3914
3914
    def assertRefs(self, expected, string):
3915
 
        self.assertEquals(expected, list(config.iter_option_refs(string)))
 
3915
        self.assertEqual(expected, list(config.iter_option_refs(string)))
3916
3916
 
3917
3917
    def test_empty(self):
3918
3918
        self.assertRefs([(False, '')], '')
3950
3950
        self.conf = config.Stack([store.get_sections], store)
3951
3951
 
3952
3952
    def assertExpansion(self, expected, string, env=None):
3953
 
        self.assertEquals(expected, self.conf.expand_options(string, env))
 
3953
        self.assertEqual(expected, self.conf.expand_options(string, env))
3954
3954
 
3955
3955
    def test_no_expansion(self):
3956
3956
        self.assertExpansion('foo', 'foo')
3958
3958
    def test_expand_default_value(self):
3959
3959
        self.conf.store._load_from_string('bar=baz')
3960
3960
        self.registry.register(config.Option('foo', default=u'{bar}'))
3961
 
        self.assertEquals('baz', self.conf.get('foo', expand=True))
 
3961
        self.assertEqual('baz', self.conf.get('foo', expand=True))
3962
3962
 
3963
3963
    def test_expand_default_from_env(self):
3964
3964
        self.conf.store._load_from_string('bar=baz')
3965
3965
        self.registry.register(config.Option('foo', default_from_env=['FOO']))
3966
3966
        self.overrideEnv('FOO', '{bar}')
3967
 
        self.assertEquals('baz', self.conf.get('foo', expand=True))
 
3967
        self.assertEqual('baz', self.conf.get('foo', expand=True))
3968
3968
 
3969
3969
    def test_expand_default_on_failed_conversion(self):
3970
3970
        self.conf.store._load_from_string('baz=bogus\nbar=42\nfoo={baz}')
3971
3971
        self.registry.register(
3972
3972
            config.Option('foo', default=u'{bar}',
3973
3973
                          from_unicode=config.int_from_store))
3974
 
        self.assertEquals(42, self.conf.get('foo', expand=True))
 
3974
        self.assertEqual(42, self.conf.get('foo', expand=True))
3975
3975
 
3976
3976
    def test_env_adding_options(self):
3977
3977
        self.assertExpansion('bar', '{foo}', {'foo': 'bar'})
4019
4019
baz={foo}''')
4020
4020
        e = self.assertRaises(errors.OptionExpansionLoop,
4021
4021
                              self.conf.expand_options, '{foo}')
4022
 
        self.assertEquals('foo->bar->baz', e.refs)
4023
 
        self.assertEquals('{foo}', e.string)
 
4022
        self.assertEqual('foo->bar->baz', e.refs)
 
4023
        self.assertEqual('{foo}', e.string)
4024
4024
 
4025
4025
    def test_list(self):
4026
4026
        self.conf.store._load_from_string('''
4031
4031
''')
4032
4032
        self.registry.register(
4033
4033
            config.ListOption('list'))
4034
 
        self.assertEquals(['start', 'middle', 'end'],
 
4034
        self.assertEqual(['start', 'middle', 'end'],
4035
4035
                           self.conf.get('list', expand=True))
4036
4036
 
4037
4037
    def test_cascading_list(self):
4046
4046
        # happen while expanding. Conversion should only occur for the original
4047
4047
        # option ('list' here).
4048
4048
        self.registry.register(config.ListOption('baz'))
4049
 
        self.assertEquals(['start', 'middle', 'end'],
 
4049
        self.assertEqual(['start', 'middle', 'end'],
4050
4050
                           self.conf.get('list', expand=True))
4051
4051
 
4052
4052
    def test_pathologically_hidden_list(self):
4061
4061
        # What matters is what the registration says, the conversion happens
4062
4062
        # only after all expansions have been performed
4063
4063
        self.registry.register(config.ListOption('hidden'))
4064
 
        self.assertEquals(['bin', 'go'],
 
4064
        self.assertEqual(['bin', 'go'],
4065
4065
                          self.conf.get('hidden', expand=True))
4066
4066
 
4067
4067
 
4099
4099
[/project/branch/path]
4100
4100
bar = {foo}ux
4101
4101
''')
4102
 
        self.assertEquals('quux', c.get('bar', expand=True))
 
4102
        self.assertEqual('quux', c.get('bar', expand=True))
4103
4103
 
4104
4104
 
4105
4105
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
4120
4120
''')
4121
4121
        g_store.save()
4122
4122
        stack = config.LocationStack('/branch')
4123
 
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
4124
 
        self.assertEquals('loc-foo', stack.get('gfoo', expand=True))
 
4123
        self.assertEqual('glob-bar', stack.get('lbar', expand=True))
 
4124
        self.assertEqual('loc-foo', stack.get('gfoo', expand=True))
4125
4125
 
4126
4126
 
4127
4127
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
4135
4135
''')
4136
4136
        l_store.save()
4137
4137
        stack = config.LocationStack('/home/user/project/')
4138
 
        self.assertEquals('', stack.get('base', expand=True))
4139
 
        self.assertEquals('', stack.get('rel', expand=True))
 
4138
        self.assertEqual('', stack.get('base', expand=True))
 
4139
        self.assertEqual('', stack.get('rel', expand=True))
4140
4140
 
4141
4141
    def test_expand_basename_locally(self):
4142
4142
        l_store = config.LocationStore()
4146
4146
''')
4147
4147
        l_store.save()
4148
4148
        stack = config.LocationStack('/home/user/project/branch')
4149
 
        self.assertEquals('branch', stack.get('bfoo', expand=True))
 
4149
        self.assertEqual('branch', stack.get('bfoo', expand=True))
4150
4150
 
4151
4151
    def test_expand_basename_locally_longer_path(self):
4152
4152
        l_store = config.LocationStore()
4156
4156
''')
4157
4157
        l_store.save()
4158
4158
        stack = config.LocationStack('/home/user/project/dir/branch')
4159
 
        self.assertEquals('branch', stack.get('bfoo', expand=True))
 
4159
        self.assertEqual('branch', stack.get('bfoo', expand=True))
4160
4160
 
4161
4161
    def test_expand_relpath_locally(self):
4162
4162
        l_store = config.LocationStore()
4166
4166
''')
4167
4167
        l_store.save()
4168
4168
        stack = config.LocationStack('/home/user/project/branch')
4169
 
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
 
4169
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
4170
4170
 
4171
4171
    def test_expand_relpath_unknonw_in_global(self):
4172
4172
        g_store = config.GlobalStore()
4195
4195
''')
4196
4196
        g_store.save()
4197
4197
        stack = config.LocationStack('/home/user/project/branch')
4198
 
        self.assertEquals('glob-bar', stack.get('lbar', expand=True))
4199
 
        self.assertEquals('loc-foo/branch', stack.get('gfoo', expand=True))
 
4198
        self.assertEqual('glob-bar', stack.get('lbar', expand=True))
 
4199
        self.assertEqual('loc-foo/branch', stack.get('gfoo', expand=True))
4200
4200
 
4201
4201
    def test_locals_dont_leak(self):
4202
4202
        """Make sure we chose the right local in presence of several sections.
4210
4210
''')
4211
4211
        l_store.save()
4212
4212
        stack = config.LocationStack('/home/user/project/branch')
4213
 
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
 
4213
        self.assertEqual('loc-foo/branch', stack.get('lfoo', expand=True))
4214
4214
        stack = config.LocationStack('/home/user/bar/baz')
4215
 
        self.assertEquals('loc-foo/bar/baz', stack.get('lfoo', expand=True))
 
4215
        self.assertEqual('loc-foo/bar/baz', stack.get('lfoo', expand=True))
4216
4216
 
4217
4217
 
4218
4218
 
4220
4220
 
4221
4221
    def test_simple_set(self):
4222
4222
        conf = self.get_stack(self)
4223
 
        self.assertEquals(None, conf.get('foo'))
 
4223
        self.assertEqual(None, conf.get('foo'))
4224
4224
        conf.set('foo', 'baz')
4225
4225
        # Did we get it back ?
4226
 
        self.assertEquals('baz', conf.get('foo'))
 
4226
        self.assertEqual('baz', conf.get('foo'))
4227
4227
 
4228
4228
    def test_set_creates_a_new_section(self):
4229
4229
        conf = self.get_stack(self)
4230
4230
        conf.set('foo', 'baz')
4231
 
        self.assertEquals, 'baz', conf.get('foo')
 
4231
        self.assertEqual, 'baz', conf.get('foo')
4232
4232
 
4233
4233
    def test_set_hook(self):
4234
4234
        calls = []
4239
4239
        conf = self.get_stack(self)
4240
4240
        conf.set('foo', 'bar')
4241
4241
        self.assertLength(1, calls)
4242
 
        self.assertEquals((conf, 'foo', 'bar'), calls[0])
 
4242
        self.assertEqual((conf, 'foo', 'bar'), calls[0])
4243
4243
 
4244
4244
 
4245
4245
class TestStackRemove(TestStackWithTransport):
4247
4247
    def test_remove_existing(self):
4248
4248
        conf = self.get_stack(self)
4249
4249
        conf.set('foo', 'bar')
4250
 
        self.assertEquals('bar', conf.get('foo'))
 
4250
        self.assertEqual('bar', conf.get('foo'))
4251
4251
        conf.remove('foo')
4252
4252
        # Did we get it back ?
4253
 
        self.assertEquals(None, conf.get('foo'))
 
4253
        self.assertEqual(None, conf.get('foo'))
4254
4254
 
4255
4255
    def test_remove_unknown(self):
4256
4256
        conf = self.get_stack(self)
4266
4266
        conf.set('foo', 'bar')
4267
4267
        conf.remove('foo')
4268
4268
        self.assertLength(1, calls)
4269
 
        self.assertEquals((conf, 'foo'), calls[0])
 
4269
        self.assertEqual((conf, 'foo'), calls[0])
4270
4270
 
4271
4271
 
4272
4272
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
4441
4441
        else:
4442
4442
            user = credentials['user']
4443
4443
            password = credentials['password']
4444
 
        self.assertEquals(expected_user, user)
4445
 
        self.assertEquals(expected_password, password)
 
4444
        self.assertEqual(expected_user, user)
 
4445
        self.assertEqual(expected_password, password)
4446
4446
 
4447
4447
    def test_empty_config(self):
4448
4448
        conf = config.AuthenticationConfig(_file=StringIO())
4449
 
        self.assertEquals({}, conf._get_config())
 
4449
        self.assertEqual({}, conf._get_config())
4450
4450
        self._got_user_passwd(None, None, conf, 'http', 'foo.net')
4451
4451
 
4452
4452
    def test_non_utf8_config(self):
4634
4634
password=bendover
4635
4635
"""))
4636
4636
        credentials = conf.get_credentials('https', 'bar.org')
4637
 
        self.assertEquals(False, credentials.get('verify_certificates'))
 
4637
        self.assertEqual(False, credentials.get('verify_certificates'))
4638
4638
        credentials = conf.get_credentials('https', 'foo.net')
4639
 
        self.assertEquals(True, credentials.get('verify_certificates'))
 
4639
        self.assertEqual(True, credentials.get('verify_certificates'))
4640
4640
 
4641
4641
 
4642
4642
class TestAuthenticationStorage(tests.TestCaseInTempDir):
4689
4689
                                            stdout=stdout, stderr=stderr)
4690
4690
        # We use an empty conf so that the user is always prompted
4691
4691
        conf = config.AuthenticationConfig()
4692
 
        self.assertEquals(password,
 
4692
        self.assertEqual(password,
4693
4693
                          conf.get_password(scheme, host, user, port=port,
4694
4694
                                            realm=realm, path=path))
4695
 
        self.assertEquals(expected_prompt, stderr.getvalue())
4696
 
        self.assertEquals('', stdout.getvalue())
 
4695
        self.assertEqual(expected_prompt, stderr.getvalue())
 
4696
        self.assertEqual('', stdout.getvalue())
4697
4697
 
4698
4698
    def _check_default_username_prompt(self, expected_prompt_format, scheme,
4699
4699
                                       host=None, port=None, realm=None,
4710
4710
                                            stdout=stdout, stderr=stderr)
4711
4711
        # We use an empty conf so that the user is always prompted
4712
4712
        conf = config.AuthenticationConfig()
4713
 
        self.assertEquals(username, conf.get_user(scheme, host, port=port,
 
4713
        self.assertEqual(username, conf.get_user(scheme, host, port=port,
4714
4714
                          realm=realm, path=path, ask=True))
4715
 
        self.assertEquals(expected_prompt, stderr.getvalue())
4716
 
        self.assertEquals('', stdout.getvalue())
 
4715
        self.assertEqual(expected_prompt, stderr.getvalue())
 
4716
        self.assertEqual('', stdout.getvalue())
4717
4717
 
4718
4718
    def test_username_defaults_prompts(self):
4719
4719
        # HTTP prompts can't be tested here, see test_http.py
4725
4725
 
4726
4726
    def test_username_default_no_prompt(self):
4727
4727
        conf = config.AuthenticationConfig()
4728
 
        self.assertEquals(None,
 
4728
        self.assertEqual(None,
4729
4729
            conf.get_user('ftp', 'example.com'))
4730
 
        self.assertEquals("explicitdefault",
 
4730
        self.assertEqual("explicitdefault",
4731
4731
            conf.get_user('ftp', 'example.com', default="explicitdefault"))
4732
4732
 
4733
4733
    def test_password_default_prompts(self):
4766
4766
 
4767
4767
        # Since the password defined in the authentication config is ignored,
4768
4768
        # the user is prompted
4769
 
        self.assertEquals(entered_password,
 
4769
        self.assertEqual(entered_password,
4770
4770
                          conf.get_password('ssh', 'bar.org', user='jim'))
4771
4771
        self.assertContainsRe(
4772
4772
            self.get_log(),
4789
4789
 
4790
4790
        # Since the password defined in the authentication config is ignored,
4791
4791
        # the user is prompted
4792
 
        self.assertEquals(entered_password,
 
4792
        self.assertEqual(entered_password,
4793
4793
                          conf.get_password('ssh', 'bar.org', user='jim'))
4794
4794
        # No warning shoud be emitted since there is no password. We are only
4795
4795
        # providing "user".
4805
4805
        config.credential_store_registry.register("stub", store, fallback=True)
4806
4806
        conf = config.AuthenticationConfig(_file=StringIO())
4807
4807
        creds = conf.get_credentials("http", "example.com")
4808
 
        self.assertEquals("joe", creds["user"])
4809
 
        self.assertEquals("secret", creds["password"])
 
4808
        self.assertEqual("joe", creds["user"])
 
4809
        self.assertEqual("secret", creds["password"])
4810
4810
 
4811
4811
 
4812
4812
class StubCredentialStore(config.CredentialStore):
4857
4857
 
4858
4858
    def test_fallback_none_registered(self):
4859
4859
        r = config.CredentialStoreRegistry()
4860
 
        self.assertEquals(None,
 
4860
        self.assertEqual(None,
4861
4861
                          r.get_fallback_credentials("http", "example.com"))
4862
4862
 
4863
4863
    def test_register(self):
4864
4864
        r = config.CredentialStoreRegistry()
4865
4865
        r.register("stub", StubCredentialStore(), fallback=False)
4866
4866
        r.register("another", StubCredentialStore(), fallback=True)
4867
 
        self.assertEquals(["another", "stub"], r.keys())
 
4867
        self.assertEqual(["another", "stub"], r.keys())
4868
4868
 
4869
4869
    def test_register_lazy(self):
4870
4870
        r = config.CredentialStoreRegistry()
4871
4871
        r.register_lazy("stub", "bzrlib.tests.test_config",
4872
4872
                        "StubCredentialStore", fallback=False)
4873
 
        self.assertEquals(["stub"], r.keys())
 
4873
        self.assertEqual(["stub"], r.keys())
4874
4874
        self.assertIsInstance(r.get_credential_store("stub"),
4875
4875
                              StubCredentialStore)
4876
4876
 
4878
4878
        r = config.CredentialStoreRegistry()
4879
4879
        r.register("stub1", None, fallback=False)
4880
4880
        r.register("stub2", None, fallback=True)
4881
 
        self.assertEquals(False, r.is_fallback("stub1"))
4882
 
        self.assertEquals(True, r.is_fallback("stub2"))
 
4881
        self.assertEqual(False, r.is_fallback("stub1"))
 
4882
        self.assertEqual(True, r.is_fallback("stub2"))
4883
4883
 
4884
4884
    def test_no_fallback(self):
4885
4885
        r = config.CredentialStoreRegistry()
4886
4886
        store = CountingCredentialStore()
4887
4887
        r.register("count", store, fallback=False)
4888
 
        self.assertEquals(None,
 
4888
        self.assertEqual(None,
4889
4889
                          r.get_fallback_credentials("http", "example.com"))
4890
 
        self.assertEquals(0, store._calls)
 
4890
        self.assertEqual(0, store._calls)
4891
4891
 
4892
4892
    def test_fallback_credentials(self):
4893
4893
        r = config.CredentialStoreRegistry()
4896
4896
                              "somebody", "geheim")
4897
4897
        r.register("stub", store, fallback=True)
4898
4898
        creds = r.get_fallback_credentials("http", "example.com")
4899
 
        self.assertEquals("somebody", creds["user"])
4900
 
        self.assertEquals("geheim", creds["password"])
 
4899
        self.assertEqual("somebody", creds["user"])
 
4900
        self.assertEqual("geheim", creds["password"])
4901
4901
 
4902
4902
    def test_fallback_first_wins(self):
4903
4903
        r = config.CredentialStoreRegistry()
4910
4910
                              "somebody", "stub2")
4911
4911
        r.register("stub2", stub1, fallback=True)
4912
4912
        creds = r.get_fallback_credentials("http", "example.com")
4913
 
        self.assertEquals("somebody", creds["user"])
4914
 
        self.assertEquals("stub1", creds["password"])
 
4913
        self.assertEqual("somebody", creds["user"])
 
4914
        self.assertEqual("stub1", creds["password"])
4915
4915
 
4916
4916
 
4917
4917
class TestPlainTextCredentialStore(tests.TestCase):
4920
4920
        r = config.credential_store_registry
4921
4921
        plain_text = r.get_credential_store()
4922
4922
        decoded = plain_text.decode_password(dict(password='secret'))
4923
 
        self.assertEquals('secret', decoded)
 
4923
        self.assertEqual('secret', decoded)
4924
4924
 
4925
4925
 
4926
4926
class TestBase64CredentialStore(tests.TestCase):
4929
4929
        r = config.credential_store_registry
4930
4930
        plain_text = r.get_credential_store('base64')
4931
4931
        decoded = plain_text.decode_password(dict(password='c2VjcmV0'))
4932
 
        self.assertEquals('secret', decoded)
 
4932
        self.assertEqual('secret', decoded)
4933
4933
 
4934
4934
 
4935
4935
# FIXME: Once we have a way to declare authentication to all test servers, we
4963
4963
            self.assertIsNot(None, realname)
4964
4964
            self.assertIsNot(None, address)
4965
4965
        else:
4966
 
            self.assertEquals((None, None), (realname, address))
 
4966
            self.assertEqual((None, None), (realname, address))
4967
4967
 
4968
4968
 
4969
4969
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4976
4976
        finally:
4977
4977
            f.close()
4978
4978
        r = config._get_default_mail_domain('simple')
4979
 
        self.assertEquals('domainname.com', r)
 
4979
        self.assertEqual('domainname.com', r)
4980
4980
 
4981
4981
    def test_default_mail_domain_no_eol(self):
4982
4982
        f = file('no_eol', 'w')
4985
4985
        finally:
4986
4986
            f.close()
4987
4987
        r = config._get_default_mail_domain('no_eol')
4988
 
        self.assertEquals('domainname.com', r)
 
4988
        self.assertEqual('domainname.com', r)
4989
4989
 
4990
4990
    def test_default_mail_domain_multiple_lines(self):
4991
4991
        f = file('multiple_lines', 'w')
4994
4994
        finally:
4995
4995
            f.close()
4996
4996
        r = config._get_default_mail_domain('multiple_lines')
4997
 
        self.assertEquals('domainname.com', r)
 
4997
        self.assertEqual('domainname.com', r)
4998
4998
 
4999
4999
 
5000
5000
class EmailOptionTests(tests.TestCase):
5004
5004
        # BZR_EMAIL takes precedence over EMAIL
5005
5005
        self.overrideEnv('BZR_EMAIL', 'jelmer@samba.org')
5006
5006
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5007
 
        self.assertEquals('jelmer@samba.org', conf.get('email'))
 
5007
        self.assertEqual('jelmer@samba.org', conf.get('email'))
5008
5008
 
5009
5009
    def test_default_email_uses_EMAIL(self):
5010
5010
        conf = config.MemoryStack('')
5011
5011
        self.overrideEnv('BZR_EMAIL', None)
5012
5012
        self.overrideEnv('EMAIL', 'jelmer@apache.org')
5013
 
        self.assertEquals('jelmer@apache.org', conf.get('email'))
 
5013
        self.assertEqual('jelmer@apache.org', conf.get('email'))
5014
5014
 
5015
5015
    def test_BZR_EMAIL_overrides(self):
5016
5016
        conf = config.MemoryStack('email=jelmer@debian.org')
5017
5017
        self.overrideEnv('BZR_EMAIL', 'jelmer@apache.org')
5018
 
        self.assertEquals('jelmer@apache.org', conf.get('email'))
 
5018
        self.assertEqual('jelmer@apache.org', conf.get('email'))
5019
5019
        self.overrideEnv('BZR_EMAIL', None)
5020
5020
        self.overrideEnv('EMAIL', 'jelmer@samba.org')
5021
 
        self.assertEquals('jelmer@debian.org', conf.get('email'))
 
5021
        self.assertEqual('jelmer@debian.org', conf.get('email'))
5022
5022
 
5023
5023
 
5024
5024
class MailClientOptionTests(tests.TestCase):