Merge "Fix debug and info option parsing"
This commit is contained in:
commit
2b391d47f0
@ -1102,6 +1102,13 @@ def parse_args(parser, args, enforce_requires=True):
|
||||
if not args:
|
||||
args = ['-h']
|
||||
(options, args) = parser.parse_args(args)
|
||||
if enforce_requires and (options.debug or options.info):
|
||||
logging.getLogger("swiftclient")
|
||||
if options.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.getLogger('iso8601').setLevel(logging.WARNING)
|
||||
elif options.info:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
if len(args) > 1 and args[1] == '--help':
|
||||
_help = globals().get('st_%s_help' % args[0],
|
||||
@ -1461,14 +1468,6 @@ Examples:
|
||||
|
||||
signal.signal(signal.SIGINT, immediate_exit)
|
||||
|
||||
if options.debug or options.info:
|
||||
logging.getLogger("swiftclient")
|
||||
if options.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.getLogger('iso8601').setLevel(logging.WARNING)
|
||||
elif options.info:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
with OutputManager() as output:
|
||||
|
||||
parser.usage = globals()['st_%s_help' % args[0]]
|
||||
|
@ -16,6 +16,7 @@ from __future__ import unicode_literals
|
||||
from genericpath import getmtime
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
import mock
|
||||
import os
|
||||
import tempfile
|
||||
@ -1296,6 +1297,20 @@ class TestSubcommandHelp(testtools.TestCase):
|
||||
self.assertEqual(out.strip('\n'), expected)
|
||||
|
||||
|
||||
@mock.patch.dict(os.environ, mocked_os_environ)
|
||||
class TestOptionAfterPosArg(testtools.TestCase):
|
||||
@mock.patch('logging.basicConfig')
|
||||
@mock.patch('swiftclient.service.Connection')
|
||||
def test_option_after_posarg(self, connection, mock_logging):
|
||||
argv = ["", "stat", "--info"]
|
||||
swiftclient.shell.main(argv)
|
||||
mock_logging.assert_called_with(level=logging.INFO)
|
||||
|
||||
argv = ["", "stat", "--debug"]
|
||||
swiftclient.shell.main(argv)
|
||||
mock_logging.assert_called_with(level=logging.DEBUG)
|
||||
|
||||
|
||||
class TestBase(testtools.TestCase):
|
||||
"""
|
||||
Provide some common methods to subclasses
|
||||
|
Loading…
x
Reference in New Issue
Block a user