/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_debug.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for breezy.debug"""
18
 
 
19
 
 
20
 
from .. import (
21
 
    config,
 
17
"""Tests for bzrlib.debug"""
 
18
 
 
19
 
 
20
import os
 
21
 
 
22
 
 
23
from bzrlib import (
22
24
    debug,
23
25
    tests,
24
26
    )
 
27
from bzrlib.config import config_filename, ensure_config_dir_exists
25
28
 
26
29
 
27
30
class TestDebugFlags(tests.TestCaseInTempDir):
28
31
 
29
 
    def test_set_no_debug_flags_from_config(self):
30
 
        self.assertDebugFlags([], b'')
31
 
 
32
 
    def test_set_single_debug_flags_from_config(self):
33
 
        self.assertDebugFlags(['hpss'], b'debug_flags = hpss\n')
34
 
 
35
 
    def test_set_multiple_debug_flags_from_config(self):
36
 
        self.assertDebugFlags(
37
 
            ['hpss', 'error'], b'debug_flags = hpss, error\n')
38
 
 
39
 
    def assertDebugFlags(self, expected_flags, conf_bytes):
40
 
        conf = config.GlobalStack()
41
 
        conf.store._load_from_string(b'[DEFAULT]\n' + conf_bytes)
42
 
        conf.store.save()
43
 
        self.overrideAttr(debug, 'debug_flags', set())
44
 
        debug.set_debug_flags_from_config()
45
 
        self.assertEqual(set(expected_flags), debug.debug_flags)
 
32
    def test_set_debug_flags_from_config(self):
 
33
        # test both combinations because configobject automatically splits up
 
34
        # comma-separated lists
 
35
        if os.path.isfile(config_filename()):
 
36
            # Something is wrong in environment,
 
37
            # we risk overwriting users config
 
38
            self.assert_(config_filename() + "exists, abort")
 
39
 
 
40
        self.try_debug_flags(
 
41
            """debug_flags = hpss, error\n""",
 
42
            set(['hpss', 'error']))
 
43
 
 
44
        self.try_debug_flags(
 
45
            """debug_flags = hpss\n""",
 
46
            set(['hpss']))
 
47
 
 
48
    def try_debug_flags(self, conf_bytes, expected_flags):
 
49
        ensure_config_dir_exists()
 
50
        f = open(config_filename(), 'wb')
 
51
        try:
 
52
            f.write(conf_bytes)
 
53
        finally:
 
54
            f.close()
 
55
        saved_debug = set(debug.debug_flags)
 
56
        debug.debug_flags.clear()
 
57
        try:
 
58
            debug.set_debug_flags_from_config()
 
59
            self.assertEqual(expected_flags,
 
60
                debug.debug_flags)
 
61
        finally:
 
62
            # restore without rebinding the variable
 
63
            debug.debug_flags.clear()
 
64
            debug.debug_flags.update(saved_debug)