~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_debug.py

  • Committer: Gary van der Merwe
  • Date: 2010-08-02 19:56:52 UTC
  • mfrom: (5050.3.18 2.2)
  • mto: (5050.3.19 2.2)
  • mto: This revision was merged to the branch mainline in revision 5371.
  • Revision ID: garyvdm@gmail.com-20100802195652-o1ppjemhwrr98i61
MergeĀ lp:bzr/2.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for bzrlib.debug"""
18
18
 
19
19
 
 
20
import os
 
21
 
 
22
 
20
23
from bzrlib import (
21
 
    config,
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):
29
32
    def test_set_debug_flags_from_config(self):
30
33
        # test both combinations because configobject automatically splits up
31
34
        # comma-separated lists
32
 
        self.try_debug_flags(['hpss', 'error'], 'debug_flags = hpss, error\n')
33
 
        self.try_debug_flags(['hpss'], 'debug_flags = hpss\n')
34
 
 
35
 
    def try_debug_flags(self, expected_flags, conf_bytes):
36
 
        conf = config.GlobalConfig.from_string(conf_bytes, save=True)
37
 
        self.overrideAttr(debug, 'debug_flags', set())
38
 
        debug.set_debug_flags_from_config()
39
 
        self.assertEqual(set(expected_flags), debug.debug_flags)
 
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)