~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_debug.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

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)