~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_aliases.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
import os
20
20
 
 
21
from bzrlib import config
21
22
from bzrlib.branch import Branch
22
 
from bzrlib.tests.blackbox import ExternalBase
 
23
from bzrlib.tests import TestCaseWithTransport
23
24
from bzrlib.trace import mutter
24
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
25
 
 
26
 
 
27
 
class TestAliases(ExternalBase):
 
25
 
 
26
 
 
27
class TestAliases(TestCaseWithTransport):
28
28
 
29
29
    def test_aliases(self):
30
30
 
35
35
            return self.run_bzr(args, **kwargs)[1]
36
36
 
37
37
 
38
 
        if os.path.isfile(config_filename()):
39
 
            # Something is wrong in environment,
40
 
            # we risk overwriting users config
41
 
            self.assert_(config_filename() + "exists, abort")
42
 
 
43
 
        ensure_config_dir_exists()
44
 
        CONFIG=("[ALIASES]\n"
45
 
                "c=cat\n"
46
 
                "c1=cat -r 1\n"
47
 
                "c2=cat -r 1 -r2\n")
48
 
 
49
 
        open(config_filename(),'wb').write(CONFIG)
 
38
        conf = config.GlobalConfig.from_string('''[ALIASES]
 
39
c=cat
 
40
c1=cat -r 1
 
41
c2=cat -r 1 -r2
 
42
''', save=True)
50
43
 
51
44
        str1 = 'foo\n'
52
45
        str2 = 'bar\n'