~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-18 10:42:07 UTC
  • mfrom: (6437.3.6 2.5)
  • mto: (6437.3.7 2.5)
  • mto: This revision was merged to the branch mainline in revision 6441.
  • Revision ID: jelmer@vernstok.nl-20120118104207-yc5fhsaz4mupjcam
Merge 2.5 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3336
3336
 
3337
3337
    def get_section(self, options, extra_path):
3338
3338
        section = config.Section('foo', options)
3339
 
        # We don't care about the length so we use '0'
3340
 
        return config.LocationSection(section, 0, extra_path)
 
3339
        return config.LocationSection(section, extra_path)
3341
3340
 
3342
3341
    def test_simple_option(self):
3343
3342
        section = self.get_section({'foo': 'bar'}, '')
3380
3379
                           '/quux/quux'],
3381
3380
                          [section.id for _, section in store.get_sections()])
3382
3381
        matcher = config.LocationMatcher(store, '/foo/bar/quux')
3383
 
        sections = [section for s, section in matcher.get_sections()]
3384
 
        self.assertEquals([3, 2],
3385
 
                          [section.length for section in sections])
 
3382
        sections = [section for _, section in matcher.get_sections()]
3386
3383
        self.assertEquals(['/foo/bar', '/foo'],
3387
3384
                          [section.id for section in sections])
3388
3385
        self.assertEquals(['quux', 'bar/quux'],
3399
3396
        self.assertEquals(['/foo', '/foo/bar'],
3400
3397
                          [section.id for _, section in store.get_sections()])
3401
3398
        matcher = config.LocationMatcher(store, '/foo/bar/baz')
3402
 
        sections = [section for s, section in matcher.get_sections()]
3403
 
        self.assertEquals([3, 2],
3404
 
                          [section.length for section in sections])
 
3399
        sections = [section for _, section in matcher.get_sections()]
3405
3400
        self.assertEquals(['/foo/bar', '/foo'],
3406
3401
                          [section.id for section in sections])
3407
3402
        self.assertEquals(['baz', 'bar/baz'],
3432
3427
        self.assertEquals(expected_location, matcher.location)
3433
3428
 
3434
3429
 
 
3430
class TestStartingPathMatcher(TestStore):
 
3431
 
 
3432
    def setUp(self):
 
3433
        super(TestStartingPathMatcher, self).setUp()
 
3434
        # Any simple store is good enough
 
3435
        self.store = config.IniFileStore()
 
3436
 
 
3437
    def assertSectionIDs(self, expected, location, content):
 
3438
        self.store._load_from_string(content)
 
3439
        matcher = config.StartingPathMatcher(self.store, location)
 
3440
        sections = list(matcher.get_sections())
 
3441
        self.assertLength(len(expected), sections)
 
3442
        self.assertEqual(expected, [section.id for _, section in sections])
 
3443
        return sections
 
3444
 
 
3445
    def test_empty(self):
 
3446
        self.assertSectionIDs([], self.get_url(), '')
 
3447
 
 
3448
    def test_url_vs_local_paths(self):
 
3449
        # The matcher location is an url and the section names are local paths
 
3450
        sections = self.assertSectionIDs(['/foo/bar', '/foo'],
 
3451
                                         'file:///foo/bar/baz', '''\
 
3452
[/foo]
 
3453
[/foo/bar]
 
3454
''')
 
3455
 
 
3456
    def test_local_path_vs_url(self):
 
3457
        # The matcher location is a local path and the section names are urls
 
3458
        sections = self.assertSectionIDs(['file:///foo/bar', 'file:///foo'],
 
3459
                                         '/foo/bar/baz', '''\
 
3460
[file:///foo]
 
3461
[file:///foo/bar]
 
3462
''')
 
3463
 
 
3464
 
 
3465
    def test_no_name_section_included_when_present(self):
 
3466
        # Note that other tests will cover the case where the no-name section
 
3467
        # is empty and as such, not included.
 
3468
        sections = self.assertSectionIDs(['/foo/bar', '/foo', None],
 
3469
                                         '/foo/bar/baz', '''\
 
3470
option = defined so the no-name section exists
 
3471
[/foo]
 
3472
[/foo/bar]
 
3473
''')
 
3474
        self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
 
3475
                          [s.locals['relpath'] for _, s in sections])
 
3476
 
 
3477
    def test_order_reversed(self):
 
3478
        self.assertSectionIDs(['/foo/bar', '/foo'], '/foo/bar/baz', '''\
 
3479
[/foo]
 
3480
[/foo/bar]
 
3481
''')
 
3482
 
 
3483
    def test_unrelated_section_excluded(self):
 
3484
        self.assertSectionIDs(['/foo/bar', '/foo'], '/foo/bar/baz', '''\
 
3485
[/foo]
 
3486
[/foo/qux]
 
3487
[/foo/bar]
 
3488
''')
 
3489
 
 
3490
    def test_glob_included(self):
 
3491
        sections = self.assertSectionIDs(['/foo/*/baz', '/foo/b*', '/foo'],
 
3492
                                         '/foo/bar/baz', '''\
 
3493
[/foo]
 
3494
[/foo/qux]
 
3495
[/foo/b*]
 
3496
[/foo/*/baz]
 
3497
''')
 
3498
        # Note that 'baz' as a relpath for /foo/b* is not fully correct, but
 
3499
        # nothing really is... as far using {relpath} to append it to something
 
3500
        # else, this seems good enough though.
 
3501
        self.assertEquals(['', 'baz', 'bar/baz'],
 
3502
                          [s.locals['relpath'] for _, s in sections])
 
3503
 
 
3504
    def test_respect_order(self):
 
3505
        self.assertSectionIDs(['/foo', '/foo/b*', '/foo/*/baz'],
 
3506
                              '/foo/bar/baz', '''\
 
3507
[/foo/*/baz]
 
3508
[/foo/qux]
 
3509
[/foo/b*]
 
3510
[/foo]
 
3511
''')
 
3512
 
 
3513
 
3435
3514
class TestNameMatcher(TestStore):
3436
3515
 
3437
3516
    def setUp(self):