~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Use global osutils, otherwise it creates a local var.

Which works, but causes us to run the import on every call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
510
510
    def test_cached(self):
511
511
        my_config = config.IniBasedConfig.from_string(sample_config_text)
512
512
        parser = my_config._get_parser()
513
 
        self.assertTrue(my_config._get_parser() is parser)
 
513
        self.failUnless(my_config._get_parser() is parser)
514
514
 
515
515
    def _dummy_chown(self, path, uid, gid):
516
516
        self.path, self.uid, self.gid = path, uid, gid
962
962
            parser = my_config._get_parser()
963
963
        finally:
964
964
            config.ConfigObj = oldparserclass
965
 
        self.assertIsInstance(parser, InstrumentedConfigObj)
 
965
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
966
966
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
967
967
                                          'utf-8')])
968
968
 
979
979
        my_config = config.BranchConfig(branch)
980
980
        location_config = my_config._get_location_config()
981
981
        self.assertEqual(branch.base, location_config.location)
982
 
        self.assertIs(location_config, my_config._get_location_config())
 
982
        self.failUnless(location_config is my_config._get_location_config())
983
983
 
984
984
    def test_get_config(self):
985
985
        """The Branch.get_config method works properly"""
1253
1253
            parser = my_config._get_parser()
1254
1254
        finally:
1255
1255
            config.ConfigObj = oldparserclass
1256
 
        self.assertIsInstance(parser, InstrumentedConfigObj)
 
1256
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
1257
1257
        self.assertEqual(parser._calls,
1258
1258
                         [('__init__', config.locations_config_filename(),
1259
1259
                           'utf-8')])
1261
1261
    def test_get_global_config(self):
1262
1262
        my_config = config.BranchConfig(FakeBranch('http://example.com'))
1263
1263
        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()))
 
1264
        self.failUnless(isinstance(global_config, config.GlobalConfig))
 
1265
        self.failUnless(global_config is my_config._get_global_config())
1270
1266
 
1271
1267
    def test__get_matching_sections_no_match(self):
1272
1268
        self.get_branch_config('/')
1273
 
        self.assertLocationMatching([])
 
1269
        self.assertEqual([], self.my_location_config._get_matching_sections())
1274
1270
 
1275
1271
    def test__get_matching_sections_exact(self):
1276
1272
        self.get_branch_config('http://www.example.com')
1277
 
        self.assertLocationMatching([('http://www.example.com', '')])
 
1273
        self.assertEqual([('http://www.example.com', '')],
 
1274
                         self.my_location_config._get_matching_sections())
1278
1275
 
1279
1276
    def test__get_matching_sections_suffix_does_not(self):
1280
1277
        self.get_branch_config('http://www.example.com-com')
1281
 
        self.assertLocationMatching([])
 
1278
        self.assertEqual([], self.my_location_config._get_matching_sections())
1282
1279
 
1283
1280
    def test__get_matching_sections_subdir_recursive(self):
1284
1281
        self.get_branch_config('http://www.example.com/com')
1285
 
        self.assertLocationMatching([('http://www.example.com', 'com')])
 
1282
        self.assertEqual([('http://www.example.com', 'com')],
 
1283
                         self.my_location_config._get_matching_sections())
1286
1284
 
1287
1285
    def test__get_matching_sections_ignoreparent(self):
1288
1286
        self.get_branch_config('http://www.example.com/ignoreparent')
1289
 
        self.assertLocationMatching([('http://www.example.com/ignoreparent',
1290
 
                                      '')])
 
1287
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
 
1288
                         self.my_location_config._get_matching_sections())
1291
1289
 
1292
1290
    def test__get_matching_sections_ignoreparent_subdir(self):
1293
1291
        self.get_branch_config(
1294
1292
            'http://www.example.com/ignoreparent/childbranch')
1295
 
        self.assertLocationMatching([('http://www.example.com/ignoreparent',
1296
 
                                      'childbranch')])
 
1293
        self.assertEqual([('http://www.example.com/ignoreparent',
 
1294
                           'childbranch')],
 
1295
                         self.my_location_config._get_matching_sections())
1297
1296
 
1298
1297
    def test__get_matching_sections_subdir_trailing_slash(self):
1299
1298
        self.get_branch_config('/b')
1300
 
        self.assertLocationMatching([('/b/', '')])
 
1299
        self.assertEqual([('/b/', '')],
 
1300
                         self.my_location_config._get_matching_sections())
1301
1301
 
1302
1302
    def test__get_matching_sections_subdir_child(self):
1303
1303
        self.get_branch_config('/a/foo')
1304
 
        self.assertLocationMatching([('/a/*', ''), ('/a/', 'foo')])
 
1304
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
 
1305
                         self.my_location_config._get_matching_sections())
1305
1306
 
1306
1307
    def test__get_matching_sections_subdir_child_child(self):
1307
1308
        self.get_branch_config('/a/foo/bar')
1308
 
        self.assertLocationMatching([('/a/*', 'bar'), ('/a/', 'foo/bar')])
 
1309
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
 
1310
                         self.my_location_config._get_matching_sections())
1309
1311
 
1310
1312
    def test__get_matching_sections_trailing_slash_with_children(self):
1311
1313
        self.get_branch_config('/a/')
1312
 
        self.assertLocationMatching([('/a/', '')])
 
1314
        self.assertEqual([('/a/', '')],
 
1315
                         self.my_location_config._get_matching_sections())
1313
1316
 
1314
1317
    def test__get_matching_sections_explicit_over_glob(self):
1315
1318
        # XXX: 2006-09-08 jamesh
1317
1320
        # was a config section for '/a/?', it would get precedence
1318
1321
        # over '/a/c'.
1319
1322
        self.get_branch_config('/a/c')
1320
 
        self.assertLocationMatching([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')])
 
1323
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
 
1324
                         self.my_location_config._get_matching_sections())
1321
1325
 
1322
1326
    def test__get_option_policy_normal(self):
1323
1327
        self.get_branch_config('http://www.example.com')
2483
2487
            raise TestSkipped("User name inference not implemented on win32")
2484
2488
        realname, address = config._auto_user_id()
2485
2489
        if os.path.exists('/etc/mailname'):
2486
 
            self.assertIsNot(None, realname)
2487
 
            self.assertIsNot(None, address)
 
2490
            self.assertTrue(realname)
 
2491
            self.assertTrue(address)
2488
2492
        else:
2489
2493
            self.assertEquals((None, None), (realname, address))
2490
2494