~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-05 01:12:15 UTC
  • mto: This revision was merged to the branch mainline in revision 5757.
  • Revision ID: jelmer@samba.org-20110405011215-8g6izwf3uz8v4174
Remove some unnecessary imports, clean up lazy imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    )
43
43
from bzrlib.tests import (
44
44
    features,
45
 
    TestSkipped,
46
45
    scenarios,
47
46
    )
48
47
from bzrlib.util.configobj import configobj
510
509
    def test_cached(self):
511
510
        my_config = config.IniBasedConfig.from_string(sample_config_text)
512
511
        parser = my_config._get_parser()
513
 
        self.assertTrue(my_config._get_parser() is parser)
 
512
        self.failUnless(my_config._get_parser() is parser)
514
513
 
515
514
    def _dummy_chown(self, path, uid, gid):
516
515
        self.path, self.uid, self.gid = path, uid, gid
962
961
            parser = my_config._get_parser()
963
962
        finally:
964
963
            config.ConfigObj = oldparserclass
965
 
        self.assertIsInstance(parser, InstrumentedConfigObj)
 
964
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
966
965
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
967
966
                                          'utf-8')])
968
967
 
979
978
        my_config = config.BranchConfig(branch)
980
979
        location_config = my_config._get_location_config()
981
980
        self.assertEqual(branch.base, location_config.location)
982
 
        self.assertIs(location_config, my_config._get_location_config())
 
981
        self.failUnless(location_config is my_config._get_location_config())
983
982
 
984
983
    def test_get_config(self):
985
984
        """The Branch.get_config method works properly"""
1253
1252
            parser = my_config._get_parser()
1254
1253
        finally:
1255
1254
            config.ConfigObj = oldparserclass
1256
 
        self.assertIsInstance(parser, InstrumentedConfigObj)
 
1255
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
1257
1256
        self.assertEqual(parser._calls,
1258
1257
                         [('__init__', config.locations_config_filename(),
1259
1258
                           'utf-8')])
1261
1260
    def test_get_global_config(self):
1262
1261
        my_config = config.BranchConfig(FakeBranch('http://example.com'))
1263
1262
        global_config = my_config._get_global_config()
1264
 
        self.assertIsInstance(global_config, config.GlobalConfig)
1265
 
        self.assertIs(global_config, my_config._get_global_config())
1266
 
 
1267
 
    def assertLocationMatching(self, expected):
1268
 
        self.assertEqual(expected,
1269
 
                         list(self.my_location_config._get_matching_sections()))
 
1263
        self.failUnless(isinstance(global_config, config.GlobalConfig))
 
1264
        self.failUnless(global_config is my_config._get_global_config())
1270
1265
 
1271
1266
    def test__get_matching_sections_no_match(self):
1272
1267
        self.get_branch_config('/')
1273
 
        self.assertLocationMatching([])
 
1268
        self.assertEqual([], self.my_location_config._get_matching_sections())
1274
1269
 
1275
1270
    def test__get_matching_sections_exact(self):
1276
1271
        self.get_branch_config('http://www.example.com')
1277
 
        self.assertLocationMatching([('http://www.example.com', '')])
 
1272
        self.assertEqual([('http://www.example.com', '')],
 
1273
                         self.my_location_config._get_matching_sections())
1278
1274
 
1279
1275
    def test__get_matching_sections_suffix_does_not(self):
1280
1276
        self.get_branch_config('http://www.example.com-com')
1281
 
        self.assertLocationMatching([])
 
1277
        self.assertEqual([], self.my_location_config._get_matching_sections())
1282
1278
 
1283
1279
    def test__get_matching_sections_subdir_recursive(self):
1284
1280
        self.get_branch_config('http://www.example.com/com')
1285
 
        self.assertLocationMatching([('http://www.example.com', 'com')])
 
1281
        self.assertEqual([('http://www.example.com', 'com')],
 
1282
                         self.my_location_config._get_matching_sections())
1286
1283
 
1287
1284
    def test__get_matching_sections_ignoreparent(self):
1288
1285
        self.get_branch_config('http://www.example.com/ignoreparent')
1289
 
        self.assertLocationMatching([('http://www.example.com/ignoreparent',
1290
 
                                      '')])
 
1286
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
 
1287
                         self.my_location_config._get_matching_sections())
1291
1288
 
1292
1289
    def test__get_matching_sections_ignoreparent_subdir(self):
1293
1290
        self.get_branch_config(
1294
1291
            'http://www.example.com/ignoreparent/childbranch')
1295
 
        self.assertLocationMatching([('http://www.example.com/ignoreparent',
1296
 
                                      'childbranch')])
 
1292
        self.assertEqual([('http://www.example.com/ignoreparent',
 
1293
                           'childbranch')],
 
1294
                         self.my_location_config._get_matching_sections())
1297
1295
 
1298
1296
    def test__get_matching_sections_subdir_trailing_slash(self):
1299
1297
        self.get_branch_config('/b')
1300
 
        self.assertLocationMatching([('/b/', '')])
 
1298
        self.assertEqual([('/b/', '')],
 
1299
                         self.my_location_config._get_matching_sections())
1301
1300
 
1302
1301
    def test__get_matching_sections_subdir_child(self):
1303
1302
        self.get_branch_config('/a/foo')
1304
 
        self.assertLocationMatching([('/a/*', ''), ('/a/', 'foo')])
 
1303
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
 
1304
                         self.my_location_config._get_matching_sections())
1305
1305
 
1306
1306
    def test__get_matching_sections_subdir_child_child(self):
1307
1307
        self.get_branch_config('/a/foo/bar')
1308
 
        self.assertLocationMatching([('/a/*', 'bar'), ('/a/', 'foo/bar')])
 
1308
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
 
1309
                         self.my_location_config._get_matching_sections())
1309
1310
 
1310
1311
    def test__get_matching_sections_trailing_slash_with_children(self):
1311
1312
        self.get_branch_config('/a/')
1312
 
        self.assertLocationMatching([('/a/', '')])
 
1313
        self.assertEqual([('/a/', '')],
 
1314
                         self.my_location_config._get_matching_sections())
1313
1315
 
1314
1316
    def test__get_matching_sections_explicit_over_glob(self):
1315
1317
        # XXX: 2006-09-08 jamesh
1317
1319
        # was a config section for '/a/?', it would get precedence
1318
1320
        # over '/a/c'.
1319
1321
        self.get_branch_config('/a/c')
1320
 
        self.assertLocationMatching([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')])
 
1322
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
 
1323
                         self.my_location_config._get_matching_sections())
1321
1324
 
1322
1325
    def test__get_option_policy_normal(self):
1323
1326
        self.get_branch_config('http://www.example.com')
2466
2469
# test_user_prompted ?
2467
2470
class TestAuthenticationRing(tests.TestCaseWithTransport):
2468
2471
    pass
2469
 
 
2470
 
 
2471
 
class TestAutoUserId(tests.TestCase):
2472
 
    """Test inferring an automatic user name."""
2473
 
 
2474
 
    def test_auto_user_id(self):
2475
 
        """Automatic inference of user name.
2476
 
        
2477
 
        This is a bit hard to test in an isolated way, because it depends on
2478
 
        system functions that go direct to /etc or perhaps somewhere else.
2479
 
        But it's reasonable to say that on Unix, with an /etc/mailname, we ought
2480
 
        to be able to choose a user name with no configuration.
2481
 
        """
2482
 
        if sys.platform == 'win32':
2483
 
            raise TestSkipped("User name inference not implemented on win32")
2484
 
        realname, address = config._auto_user_id()
2485
 
        if os.path.exists('/etc/mailname'):
2486
 
            self.assertIsNot(None, realname)
2487
 
            self.assertIsNot(None, address)
2488
 
        else:
2489
 
            self.assertEquals((None, None), (realname, address))
2490