~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: mbp at sourcefrog
  • Date: 2007-01-12 03:40:25 UTC
  • mto: (2230.1.1 short-options)
  • mto: This revision was merged to the branch mainline in revision 2231.
  • Revision ID: mbp@sourcefrog.net-20070112034025-lxlybpp2qcxrs3py
Restore access to SHORT_OPTIONS for compatibility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
16
16
 
17
17
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
18
18
from bzrlib.commands import Command, parse_args
19
 
from bzrlib import errors
20
 
from bzrlib import option
 
19
from bzrlib import (
 
20
        errors,
 
21
        option,
 
22
        symbol_versioning,
 
23
        )
21
24
from bzrlib.tests import TestCase
22
25
 
23
26
# TODO: might be nice to just parse them into a structured form and test
69
72
        force_opt = option.Option.OPTIONS['force']
70
73
        self.assertEquals(force_opt.short_name(), None)
71
74
 
 
75
    def test_old_short_names(self):
 
76
        # test the deprecated method for getting and setting short option
 
77
        # names
 
78
        expected_warning = (
 
79
            "access to SHORT_OPTIONS was deprecated in version 0.14."
 
80
            " Set the short option name when constructing the Option.",
 
81
            DeprecationWarning, 2)
 
82
        _warnings = []
 
83
        def capture_warning(message, category, stacklevel=None):
 
84
            _warnings.append((message, category, stacklevel))
 
85
        old_warning_method = symbol_versioning.warn
 
86
        try:
 
87
            # an example of the kind of thing plugins might want to do through
 
88
            # the old interface - make a new option and then give it a short
 
89
            # name.
 
90
            symbol_versioning.set_warning_method(capture_warning)
 
91
            working_tree_opt = option.Option('working tree', help='example option')
 
92
            option.Option.SHORT_OPTIONS['w'] = working_tree_opt
 
93
            self.assertEqual(working_tree_opt.short_name(), 'w')
 
94
            self.assertEqual([expected_warning], _warnings)
 
95
        finally:
 
96
            symbol_versioning.set_warning_method(old_warning_method)
 
97
 
72
98
    def test_allow_dash(self):
73
99
        """Test that we can pass a plain '-' as an argument."""
74
100
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))