~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_debug.py

  • Committer: John Arbash Meinel
  • Date: 2010-09-25 20:08:01 UTC
  • mfrom: (5444 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5445.
  • Revision ID: john@arbash-meinel.com-20100925200801-7uf0ux3uwxo9i3x0
Merge bzr.dev 5444 to resolve some small text conflicts.

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
 
 
23
20
from bzrlib import (
 
21
    config,
24
22
    debug,
25
23
    tests,
26
24
    )
27
 
from bzrlib.config import config_filename, ensure_config_dir_exists
28
25
 
29
26
 
30
27
class TestDebugFlags(tests.TestCaseInTempDir):
32
29
    def test_set_debug_flags_from_config(self):
33
30
        # test both combinations because configobject automatically splits up
34
31
        # 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)
 
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)