/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-12-30 15:24:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6425.
  • Revision ID: v.ladeuil+lp@free.fr-20111230152431-5sunnmvtsw3xkdie
Refine implementations and add more precise tests. More tests can be added for more scenarios if it doesn't seem worth it until we encounter them in real life (which is unlikely so far)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2995
2995
        # storage to observe the effects of concurrent changes
2996
2996
        self.st1 = config.TransportIniFileStore(self.transport, 'foo.conf')
2997
2997
        self.st2 = config.TransportIniFileStore(self.transport, 'foo.conf')
 
2998
        self.warnings = []
 
2999
        def warning(*args):
 
3000
            self.warnings.append(args[0] % args[1:])
 
3001
        self.overrideAttr(trace, 'warning', warning)
2998
3002
 
2999
3003
    def has_store(self, store):
3000
3004
        store_basename = urlutils.relative_url(self.transport.external_url(),
3020
3024
        # Changes don't propagate magically
3021
3025
        self.assertEquals(None, s1.get('baz'))
3022
3026
        s2.store.save_changes()
 
3027
        self.assertEquals('quux', s2.get('baz'))
3023
3028
        # Changes are acquired when saving
3024
3029
        self.assertEquals('bar', s2.get('foo'))
3025
 
 
3026
 
# concurrent update on the same option should warn about the lost update
 
3030
        # Since there is no overlap, no warnings are emitted
 
3031
        self.assertLength(0, self.warnings)
 
3032
 
 
3033
    def test_concurrent_update_modified(self):
 
3034
        s1 = self.get_stack(self.st1)
 
3035
        s2 = self.get_stack(self.st2)
 
3036
        s1.set('foo', 'bar')
 
3037
        s2.set('foo', 'baz')
 
3038
        s1.store.save()
 
3039
        # Last speaker wins
 
3040
        s2.store.save_changes()
 
3041
        self.assertEquals('baz', s2.get('foo'))
 
3042
        # But the user get a warning
 
3043
        self.assertLength(1, self.warnings)
 
3044
        warning = self.warnings[0]
 
3045
        self.assertStartsWith(warning, 'Option foo in section None')
 
3046
        self.assertEndsWith(warning, 'was changed from <CREATED> to bar.'
 
3047
                            ' The baz value will be saved.')
 
3048
 
 
3049
    def test_concurrent_deletion(self):
 
3050
        self.st1._load_from_string('foo=bar')
 
3051
        self.st1.save()
 
3052
        s1 = self.get_stack(self.st1)
 
3053
        s2 = self.get_stack(self.st2)
 
3054
        s1.remove('foo')
 
3055
        s2.remove('foo')
 
3056
        s1.store.save_changes()
 
3057
        # No warning yet
 
3058
        self.assertLength(0, self.warnings)
 
3059
        s2.store.save_changes()
 
3060
        # Now we get one
 
3061
        self.assertLength(1, self.warnings)
 
3062
        warning = self.warnings[0]
 
3063
        self.assertStartsWith(warning, 'Option foo in section None')
 
3064
        self.assertEndsWith(warning, 'was changed from bar to <CREATED>.'
 
3065
                            ' The <DELETED> value will be saved.')
3027
3066
 
3028
3067
 
3029
3068
class TestQuotingIniFileStore(tests.TestCaseWithTransport):