Blacken everything else

Black used with the '-l 79 -S' flags.

A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.

Change-Id: I356643d06b2cd408ccaedfe02b858aea55388949
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane
2023-05-08 11:37:42 +01:00
parent a6f81a736c
commit d3f4a3d7f5
12 changed files with 209 additions and 190 deletions

View File

@@ -19,7 +19,8 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.todo',
'openstackdocstheme',
@@ -176,10 +177,8 @@ html_extra_path = ['_extra']
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
@@ -188,9 +187,13 @@ latex_elements = {
# (source start file, target name, title, author, documentclass [howto/manual])
# .
latex_documents = [
('index', 'OpenStackCommandLineClient.tex',
(
'index',
'OpenStackCommandLineClient.tex',
'OpenStack Command Line Client Documentation',
'OpenStack', 'manual'),
'OpenStack',
'manual',
),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -238,11 +241,15 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'OpenStackCommandLineClient',
(
'index',
'OpenStackCommandLineClient',
'OpenStack Command Line Client Documentation',
'OpenStack', 'OpenStackCommandLineClient',
'OpenStack',
'OpenStackCommandLineClient',
'One line description of project.',
'Miscellaneous'),
'Miscellaneous',
),
]
# Documents to append as an appendix to all manuals.
@@ -260,8 +267,16 @@ texinfo_documents = [
autoprogram_cliff_application = 'openstack'
autoprogram_cliff_ignored = [
'--help', '--format', '--column', '--max-width', '--fit-width',
'--print-empty', '--prefix', '--noindent', '--quote']
'--help',
'--format',
'--column',
'--max-width',
'--fit-width',
'--print-empty',
'--prefix',
'--noindent',
'--quote',
]
# Prevent cliff from generating "This command is provided by the
# python-openstackclient plugin."

View File

@@ -57,6 +57,7 @@ dump_stack_trace = False
# Generally useful stuff often found in a utils module
def env(*vars, **kwargs):
"""Search for the first defined of possibly many env vars
@@ -73,6 +74,7 @@ def env(*vars, **kwargs):
# Common Example functions
def base_parser(parser):
"""Set up some of the common CLI options
@@ -128,7 +130,8 @@ def base_parser(parser):
help="Print API call timing info",
)
parser.add_argument(
'-v', '--verbose',
'-v',
'--verbose',
action='count',
dest='verbose_level',
default=1,
@@ -225,16 +228,14 @@ def make_session(opts, **kwargs):
)
auth_p = auth_plugin.load_from_options(**auth_params)
session = ks_session.Session(
auth=auth_p,
**kwargs
)
session = ks_session.Session(auth=auth_p, **kwargs)
return session
# Top-level functions
def run(opts):
"""Default run command"""

View File

@@ -31,14 +31,13 @@ DEFAULT_DOMAIN = 'default'
class OpenStackShell(shell.OpenStackShell):
def __init__(self):
super(OpenStackShell, self).__init__(
description=__doc__.strip(),
version=openstackclient.__version__,
command_manager=commandmanager.CommandManager('openstack.cli'),
deferred_help=True)
deferred_help=True,
)
self.api_version = {}
@@ -51,8 +50,8 @@ class OpenStackShell(shell.OpenStackShell):
def build_option_parser(self, description, version):
parser = super(OpenStackShell, self).build_option_parser(
description,
version)
description, version
)
parser = clientmanager.build_plugin_option_parser(parser)
parser = auth.build_auth_plugins_option_parser(parser)
return parser
@@ -61,7 +60,7 @@ class OpenStackShell(shell.OpenStackShell):
super(OpenStackShell, self)._final_defaults()
# Set the default plugin to admin_token if endpoint and token are given
if (self.options.endpoint and self.options.token):
if self.options.endpoint and self.options.token:
# Use token authentication
self._auth_type = 'admin_token'
else:
@@ -96,10 +95,12 @@ class OpenStackShell(shell.OpenStackShell):
if version_opt not in mod_versions:
sorted_versions = sorted(
mod.API_VERSIONS.keys(),
key=lambda s: list(map(int, s.split('.'))))
key=lambda s: list(map(int, s.split('.'))),
)
self.log.warning(
"%s version %s is not in supported versions: %s"
% (api, version_opt, ', '.join(sorted_versions)))
% (api, version_opt, ', '.join(sorted_versions))
)
# Command groups deal only with major versions
version = '.v' + version_opt.replace('.', '_').split('_')[0]
@@ -107,7 +108,7 @@ class OpenStackShell(shell.OpenStackShell):
self.command_manager.add_command_group(cmd_group)
self.log.debug(
'%(name)s API version %(version)s, cmd group %(group)s',
{'name': api, 'version': version_opt, 'group': cmd_group}
{'name': api, 'version': version_opt, 'group': cmd_group},
)
def _load_commands(self):
@@ -116,8 +117,7 @@ class OpenStackShell(shell.OpenStackShell):
osc-lib has no opinion on what commands should be loaded
"""
# Commands that span multiple APIs
self.command_manager.add_command_group(
'openstack.common')
self.command_manager.add_command_group('openstack.common')
# This is the naive extension implementation referred to in
# blueprint 'client-extensions'
@@ -129,8 +129,7 @@ class OpenStackShell(shell.OpenStackShell):
# 'show_repo=qaz.github.repo:ShowRepo',
# ],
# }
self.command_manager.add_command_group(
'openstack.extension')
self.command_manager.add_command_group('openstack.extension')
def initialize_app(self, argv):
super(OpenStackShell, self).initialize_app(argv)

View File

@@ -40,14 +40,16 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
if not fail_ok and proc.returncode != 0:
raise exceptions.CommandFailed(
proc.returncode, cmd, result_out, result_err,
proc.returncode,
cmd,
result_out,
result_err,
)
return result_out
class TestCase(testtools.TestCase):
@classmethod
def openstack(
cls,
@@ -128,8 +130,9 @@ class TestCase(testtools.TestCase):
@classmethod
def get_opts(cls, fields, output_format='value'):
return ' -f {0} {1}'.format(output_format,
' '.join(['-c ' + it for it in fields]))
return ' -f {0} {1}'.format(
output_format, ' '.join(['-c ' + it for it in fields])
)
@classmethod
def assertOutput(cls, expected, actual):

View File

@@ -29,8 +29,7 @@ REGION_NAME = "richie"
INTERFACE = "catchy"
VERSION = "3"
TEST_RESPONSE_DICT = fixture.V2Token(token_id=AUTH_TOKEN,
user_name=USERNAME)
TEST_RESPONSE_DICT = fixture.V2Token(token_id=AUTH_TOKEN, user_name=USERNAME)
_s = TEST_RESPONSE_DICT.add_service('identity', name='keystone')
_s.add_endpoint(AUTH_URL + ':5000/v2.0')
_s = TEST_RESPONSE_DICT.add_service('network', name='neutron')
@@ -49,7 +48,6 @@ TEST_VERSIONS = fixture.DiscoveryList(href=AUTH_URL)
class FakeStdout(object):
def __init__(self):
self.content = []
@@ -64,7 +62,6 @@ class FakeStdout(object):
class FakeLog(object):
def __init__(self):
self.messages = {}
@@ -85,7 +82,6 @@ class FakeLog(object):
class FakeApp(object):
def __init__(self, _stdout, _log):
self.stdout = _stdout
self.client_manager = None
@@ -102,7 +98,6 @@ class FakeOptions(object):
class FakeClient(object):
def __init__(self, **kwargs):
self.endpoint = kwargs['endpoint']
self.token = kwargs['token']
@@ -131,7 +126,6 @@ class FakeClientManager(object):
self.configuration_type = 'cloud_config'
def get_configuration(self):
config = {
'region': REGION_NAME,
'identity_api_version': VERSION,
@@ -161,7 +155,6 @@ class FakeClientManager(object):
class FakeModule(object):
def __init__(self, name, version):
self.name = name
self.__version__ = version
@@ -171,7 +164,6 @@ class FakeModule(object):
class FakeResource(object):
def __init__(self, manager=None, info=None, loaded=False, methods=None):
"""Set attributes and methods for a resource.
@@ -195,7 +187,7 @@ class FakeResource(object):
self._loaded = loaded
def _add_details(self, info):
for (k, v) in info.items():
for k, v in info.items():
setattr(self, k, v)
def _add_methods(self, methods):
@@ -206,13 +198,14 @@ class FakeResource(object):
@value. When users access the attribute with (), @value will be
returned, which looks like a function call.
"""
for (name, ret) in methods.items():
for name, ret in methods.items():
method = mock.Mock(return_value=ret)
setattr(self, name, method)
def __repr__(self):
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
k != 'manager')
reprkeys = sorted(
k for k in self.__dict__.keys() if k[0] != '_' and k != 'manager'
)
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)
@@ -237,9 +230,9 @@ class FakeResource(object):
class FakeResponse(requests.Response):
def __init__(self, headers=None, status_code=200,
data=None, encoding=None):
def __init__(
self, headers=None, status_code=200, data=None, encoding=None
):
super(FakeResponse, self).__init__()
headers = headers or {}
@@ -253,7 +246,6 @@ class FakeResponse(requests.Response):
class FakeModel(dict):
def __getattr__(self, key):
try:
return self[key]

View File

@@ -51,15 +51,19 @@ V3_VERSION_RESP = {
"version": {
"status": "stable",
"updated": "2016-04-04T00:00:00Z",
"media-types": [{
"media-types": [
{
"base": "application/json",
"type": "application/vnd.openstack.identity-v3+json",
}],
}
],
"id": "v3.6",
"links": [{
"links": [
{
"href": V3_AUTH_URL,
"rel": "self",
}]
}
],
}
}
@@ -114,7 +118,6 @@ def make_v3_token(req_mock):
class TestInteg(utils.TestCase):
def setUp(self):
super(TestInteg, self).setUp()

View File

@@ -20,7 +20,6 @@ from openstackclient.tests.unit import test_shell
class TestIntegV2ProjectID(test_base.TestInteg):
def setUp(self):
super(TestIntegV2ProjectID, self).setUp()
env = {
@@ -78,7 +77,6 @@ class TestIntegV2ProjectID(test_base.TestInteg):
class TestIntegV2ProjectName(test_base.TestInteg):
def setUp(self):
super(TestIntegV2ProjectName, self).setUp()
env = {
@@ -136,7 +134,6 @@ class TestIntegV2ProjectName(test_base.TestInteg):
class TestIntegV3ProjectID(test_base.TestInteg):
def setUp(self):
super(TestIntegV3ProjectID, self).setUp()
env = {
@@ -192,7 +189,6 @@ class TestIntegV3ProjectID(test_base.TestInteg):
class TestIntegV3ProjectName(test_base.TestInteg):
def setUp(self):
super(TestIntegV3ProjectName, self).setUp()
env = {

View File

@@ -22,7 +22,6 @@ from openstackclient.tests.unit import test_shell
class TestIntegShellCliNoAuth(test_base.TestInteg):
def setUp(self):
super(TestIntegShellCliNoAuth, self).setUp()
env = {}
@@ -67,7 +66,6 @@ class TestIntegShellCliNoAuth(test_base.TestInteg):
class TestIntegShellCliV2(test_base.TestInteg):
def setUp(self):
super(TestIntegShellCliV2, self).setUp()
env = {
@@ -155,7 +153,6 @@ class TestIntegShellCliV2(test_base.TestInteg):
class TestIntegShellCliV2Ignore(test_base.TestInteg):
def setUp(self):
super(TestIntegShellCliV2Ignore, self).setUp()
env = {
@@ -202,7 +199,6 @@ class TestIntegShellCliV2Ignore(test_base.TestInteg):
class TestIntegShellCliV3(test_base.TestInteg):
def setUp(self):
super(TestIntegShellCliV3, self).setUp()
env = {
@@ -293,7 +289,6 @@ class TestIntegShellCliV3(test_base.TestInteg):
class TestIntegShellCliV3Prompt(test_base.TestInteg):
def setUp(self):
super(TestIntegShellCliV3Prompt, self).setUp()
env = {
@@ -318,8 +313,7 @@ class TestIntegShellCliV3Prompt(test_base.TestInteg):
# Check password callback set correctly
self.assertEqual(
mock_prompt,
_shell.cloud._openstack_config._pw_callback
mock_prompt, _shell.cloud._openstack_config._pw_callback
)
# Check auth request
@@ -358,8 +352,9 @@ class TestIntegShellCliPrecedence(test_base.TestInteg):
self.token = test_base.make_v3_token(self.requests_mock)
# Patch a v3 auth URL into the o-c-c data
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
= test_base.V3_AUTH_URL
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth'][
'auth_url'
] = test_base.V3_AUTH_URL
def test_shell_args_options(self):
"""Verify command line options override environment variables"""
@@ -432,8 +427,9 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
self.token = test_base.make_v3_token(self.requests_mock)
# Patch a v3 auth URL into the o-c-c data
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
= test_base.V3_AUTH_URL
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth'][
'auth_url'
] = test_base.V3_AUTH_URL
def get_temp_file_path(self, filename):
"""Returns an absolute path for a temporary file.
@@ -457,10 +453,12 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
log_file = self.get_temp_file_path('test_log_file')
cloud2 = test_shell.get_cloud(log_file)
return ('file.yaml', cloud2)
config_mock.side_effect = config_mock_return
def vendor_mock_return():
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
vendor_mock.side_effect = vendor_mock_return
_shell = shell.OpenStackShell()
@@ -528,10 +526,12 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
log_file = self.get_temp_file_path('test_log_file')
cloud2 = test_shell.get_cloud(log_file)
return ('file.yaml', cloud2)
config_mock.side_effect = config_mock_return
def vendor_mock_return():
return ('file.yaml', copy.deepcopy(test_shell.PUBLIC_1))
vendor_mock.side_effect = vendor_mock_return
_shell = shell.OpenStackShell()

View File

@@ -96,7 +96,7 @@ global_options = {
'--os-cacert': ('/dev/null', True, True),
'--timing': (True, True, False),
'--os-profile': ('SECRET_KEY', True, False),
'--os-interface': (DEFAULT_INTERFACE, True, True)
'--os-interface': (DEFAULT_INTERFACE, True, True),
}
@@ -138,7 +138,6 @@ wrapt.wrap_function_wrapper(
class TestShell(osc_lib_test_utils.TestShell):
# Full name of the OpenStackShell class to test (cliff.app.App subclass)
shell_class_name = "openstackclient.shell.OpenStackShell"
@@ -191,14 +190,12 @@ class TestShell(osc_lib_test_utils.TestShell):
self.app.assert_called_with(["list", "role"])
self.assertEqual(
default_args.get("token", ''),
_shell.options.token,
"token"
default_args.get("token", ''), _shell.options.token, "token"
)
self.assertEqual(
default_args.get("auth_url", ''),
_shell.options.auth_url,
"auth_url"
"auth_url",
)
def _assert_cli(self, cmd_options, default_args):
@@ -213,20 +210,29 @@ class TestShell(osc_lib_test_utils.TestShell):
osc_lib_test_utils.fake_execute(_shell, _cmd)
self.app.assert_called_with(["list", "server"])
self.assertEqual(default_args["compute_api_version"],
_shell.options.os_compute_api_version)
self.assertEqual(default_args["identity_api_version"],
_shell.options.os_identity_api_version)
self.assertEqual(default_args["image_api_version"],
_shell.options.os_image_api_version)
self.assertEqual(default_args["volume_api_version"],
_shell.options.os_volume_api_version)
self.assertEqual(default_args["network_api_version"],
_shell.options.os_network_api_version)
self.assertEqual(
default_args["compute_api_version"],
_shell.options.os_compute_api_version,
)
self.assertEqual(
default_args["identity_api_version"],
_shell.options.os_identity_api_version,
)
self.assertEqual(
default_args["image_api_version"],
_shell.options.os_image_api_version,
)
self.assertEqual(
default_args["volume_api_version"],
_shell.options.os_volume_api_version,
)
self.assertEqual(
default_args["network_api_version"],
_shell.options.os_network_api_version,
)
class TestShellOptions(TestShell):
def setUp(self):
super(TestShellOptions, self).setUp()
self.useFixture(osc_lib_test_utils.EnvFixture())
@@ -289,7 +295,6 @@ class TestShellOptions(TestShell):
class TestShellTokenAuthEnv(TestShell):
def setUp(self):
super(TestShellTokenAuthEnv, self).setUp()
env = {
@@ -333,7 +338,6 @@ class TestShellTokenAuthEnv(TestShell):
class TestShellTokenEndpointAuthEnv(TestShell):
def setUp(self):
super(TestShellTokenEndpointAuthEnv, self).setUp()
env = {
@@ -377,7 +381,6 @@ class TestShellTokenEndpointAuthEnv(TestShell):
class TestShellCli(TestShell):
def setUp(self):
super(TestShellCli, self).setUp()
env = {
@@ -408,6 +411,6 @@ class TestShellCli(TestShell):
"identity_api_version": LIB_IDENTITY_API_VERSION,
"image_api_version": LIB_IMAGE_API_VERSION,
"volume_api_version": LIB_VOLUME_API_VERSION,
"network_api_version": LIB_NETWORK_API_VERSION
"network_api_version": LIB_NETWORK_API_VERSION,
}
self._assert_cli(flag, kwargs)

View File

@@ -29,22 +29,26 @@ class ParserException(Exception):
class CompareBySet(list):
"""Class to compare value using set."""
def __eq__(self, other):
return set(self) == set(other)
class TestCase(testtools.TestCase):
def setUp(self):
testtools.TestCase.setUp(self)
if (os.environ.get("OS_STDOUT_CAPTURE") == "True" or
os.environ.get("OS_STDOUT_CAPTURE") == "1"):
if (
os.environ.get("OS_STDOUT_CAPTURE") == "True"
or os.environ.get("OS_STDOUT_CAPTURE") == "1"
):
stdout = self.useFixture(fixtures.StringStream("stdout")).stream
self.useFixture(fixtures.MonkeyPatch("sys.stdout", stdout))
if (os.environ.get("OS_STDERR_CAPTURE") == "True" or
os.environ.get("OS_STDERR_CAPTURE") == "1"):
if (
os.environ.get("OS_STDERR_CAPTURE") == "True"
or os.environ.get("OS_STDERR_CAPTURE") == "1"
):
stderr = self.useFixture(fixtures.StringStream("stderr")).stream
self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr))
@@ -76,8 +80,9 @@ class TestCommand(TestCase):
try:
parsed_args = cmd_parser.parse_args(args)
except SystemExit:
raise ParserException("Argument parse failed: %s" %
stderr.getvalue())
raise ParserException(
"Argument parse failed: %s" % stderr.getvalue()
)
for av in verify_args:
attr, value = av
if attr:

View File

@@ -224,10 +224,8 @@ htmlhelp_basename = 'OpenStackClientReleaseNotesdoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
@@ -235,13 +233,15 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [(
latex_documents = [
(
'index',
'OpenStackClientReleaseNotes.tex',
'OpenStackClient Release Notes Documentation',
'OpenStackClient Developers',
'manual',
)]
)
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
@@ -268,13 +268,15 @@ latex_documents = [(
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(
man_pages = [
(
'index',
'openstackclientreleasenotes',
'OpenStackClient Release Notes Documentation',
['OpenStackClient Developers'],
1,
)]
)
]
# If true, show URL addresses after external links.
# man_show_urls = False
@@ -285,7 +287,8 @@ man_pages = [(
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [(
texinfo_documents = [
(
'index',
'OpenStackClientReleaseNotes',
'OpenStackclient Release Notes Documentation',
@@ -293,7 +296,8 @@ texinfo_documents = [(
'OpenStackClientReleaseNotes',
'A unified command-line client for OpenStack.',
'Miscellaneous',
)]
)
]
# Documents to append as an appendix to all manuals.
# texinfo_appendices = []

View File

@@ -15,6 +15,4 @@
import setuptools
setuptools.setup(
setup_requires=['pbr>=2.0.0'],
pbr=True)
setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True)