Remove six

We don't need this in a Python 3-only world. We can't remove mock yet
since there's an issue with the stdlib variant in python3.6, but that is
called out.

Change-Id: I9657b1fd4409be90d645175a6e177d7e1d2ebac2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-10-08 15:58:38 +01:00
parent d5142cdf07
commit 20a7cee3e3
13 changed files with 67 additions and 90 deletions

View File

@ -17,15 +17,9 @@
import argparse import argparse
import collections import collections
from collections import abc
# TODO(smcginnis) update this once six has support for collections.abc
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
import copy import copy
import enum
import errno import errno
import functools import functools
import glob import glob
@ -36,8 +30,6 @@ import os
import string import string
import sys import sys
import enum
import six
# NOTE(bnemec): oslo.log depends on oslo.config, so we can't # NOTE(bnemec): oslo.log depends on oslo.config, so we can't
# have a hard dependency on oslo.log. However, in most cases # have a hard dependency on oslo.log. However, in most cases
# oslo.log will be installed so we can use it. # oslo.log will be installed so we can use it.
@ -607,7 +599,7 @@ class Opt(object):
def _default_is_ref(self): def _default_is_ref(self):
"""Check if default is a reference to another var.""" """Check if default is a reference to another var."""
if isinstance(self.default, six.string_types): if isinstance(self.default, str):
tmpl = self.default.replace(r'\$', '').replace('$$', '') tmpl = self.default.replace(r'\$', '').replace('$$', '')
return '$' in tmpl return '$' in tmpl
return False return False
@ -939,7 +931,7 @@ class StrOpt(Opt):
return '<None>' return '<None>'
elif choice == '': elif choice == '':
return "''" return "''"
return six.text_type(choice) return str(choice)
def _get_argparse_kwargs(self, group, **kwargs): def _get_argparse_kwargs(self, group, **kwargs):
"""Extends the base argparse keyword dict for the config dir option.""" """Extends the base argparse keyword dict for the config dir option."""
@ -1564,7 +1556,7 @@ class ConfigParser(iniparser.BaseParser):
def parse(self): def parse(self):
with open(self.filename) as f: with open(self.filename) as f:
return super(ConfigParser, self).parse(f) return super(ConfigParser, self).parse(f.readlines())
def new_section(self, section): def new_section(self, section):
self.section = section self.section = section
@ -1930,7 +1922,7 @@ class _CachedArgumentParser(argparse.ArgumentParser):
super(_CachedArgumentParser, self).print_usage(file) super(_CachedArgumentParser, self).print_usage(file)
class ConfigOpts(Mapping): class ConfigOpts(abc.Mapping):
"""Config options which may be set on the command line or in config files. """Config options which may be set on the command line or in config files.
@ -3121,7 +3113,7 @@ class ConfigOpts(Mapping):
value, loc = self._do_get(name, opt_group, None) value, loc = self._do_get(name, opt_group, None)
return loc return loc
class GroupAttr(Mapping): class GroupAttr(abc.Mapping):
"""Helper class. """Helper class.

View File

@ -32,7 +32,6 @@ import textwrap
import json import json
import pkg_resources import pkg_resources
import six
import yaml import yaml
@ -119,7 +118,7 @@ def _format_defaults(opt):
default_str = str(opt.default) default_str = str(opt.default)
elif isinstance(opt, (cfg.ListOpt, cfg._ConfigFileOpt, elif isinstance(opt, (cfg.ListOpt, cfg._ConfigFileOpt,
cfg._ConfigDirOpt)): cfg._ConfigDirOpt)):
default_str = ','.join(six.text_type(d) for d in opt.default) default_str = ','.join(str(d) for d in opt.default)
elif isinstance(opt, cfg.DictOpt): elif isinstance(opt, cfg.DictOpt):
sorted_items = sorted(opt.default.items(), sorted_items = sorted(opt.default.items(),
key=operator.itemgetter(0)) key=operator.itemgetter(0))
@ -131,8 +130,8 @@ def _format_defaults(opt):
results = [] results = []
for default_str in defaults: for default_str in defaults:
if not isinstance(default_str, six.text_type): if not isinstance(default_str, str):
default_str = six.text_type(default_str) default_str = str(default_str)
if default_str.strip() != default_str: if default_str.strip() != default_str:
default_str = '"%s"' % default_str default_str = '"%s"' % default_str
results.append(default_str) results.append(default_str)
@ -201,7 +200,7 @@ class _OptFormatter(object):
return '<None>' return '<None>'
elif choice == '': elif choice == '':
return "''" return "''"
return six.text_type(choice) return str(choice)
def format_group(self, group_or_groupname): def format_group(self, group_or_groupname):
"""Format the description of a group header to the output file """Format the description of a group header to the output file

View File

@ -42,7 +42,6 @@ The Configuration Source Class
""" """
import abc import abc
import six
# We cannot use None as a sentinel indicating a missing value because it # We cannot use None as a sentinel indicating a missing value because it
@ -50,8 +49,7 @@ import six
_NoValue = object() _NoValue = object()
@six.add_metaclass(abc.ABCMeta) class ConfigurationSourceDriver(object, metaclass=abc.ABCMeta):
class ConfigurationSourceDriver(object):
"""A backend driver option for oslo.config. """A backend driver option for oslo.config.
For each group name listed in **config_source** on the **DEFAULT** group, For each group name listed in **config_source** on the **DEFAULT** group,
@ -114,8 +112,7 @@ class ConfigurationSourceDriver(object):
""" """
@six.add_metaclass(abc.ABCMeta) class ConfigurationSource(object, metaclass=abc.ABCMeta):
class ConfigurationSource(object):
"""A configuration source option for oslo.config. """A configuration source option for oslo.config.
A configuration source is able to fetch configuration values based on A configuration source is able to fetch configuration values based on

View File

@ -15,7 +15,6 @@ from docutils.parsers import rst
from docutils.parsers.rst import directives from docutils.parsers.rst import directives
from docutils.statemachine import ViewList from docutils.statemachine import ViewList
import oslo_i18n import oslo_i18n
import six
from sphinx import addnodes from sphinx import addnodes
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.domains import Domain from sphinx.domains import Domain
@ -89,7 +88,7 @@ def _get_choice_text(choice):
return '<None>' return '<None>'
elif choice == '': elif choice == '':
return "''" return "''"
return six.text_type(choice) return str(choice)
def _format_opt(opt, group_name): def _format_opt(opt, group_name):

View File

@ -15,6 +15,7 @@
import argparse import argparse
import errno import errno
import functools import functools
import io
import logging import logging
import os import os
import shutil import shutil
@ -24,8 +25,6 @@ import tempfile
import fixtures import fixtures
import mock import mock
from oslotest import base from oslotest import base
import six
from six import moves
import testscenarios import testscenarios
from oslo_config import cfg from oslo_config import cfg
@ -139,7 +138,7 @@ class BaseTestCase(base.BaseTestCase):
class UsageTestCase(BaseTestCase): class UsageTestCase(BaseTestCase):
def test_print_usage(self): def test_print_usage(self):
f = moves.StringIO() f = io.StringIO()
self.conf([]) self.conf([])
self.conf.print_usage(file=f) self.conf.print_usage(file=f)
self.assertIn( self.assertIn(
@ -154,7 +153,7 @@ class UsageTestCase(BaseTestCase):
conf = self.TestConfigOpts() conf = self.TestConfigOpts()
self.tempdirs = [] self.tempdirs = []
f = moves.StringIO() f = io.StringIO()
conf([], usage='%(prog)s FOO BAR') conf([], usage='%(prog)s FOO BAR')
conf.print_usage(file=f) conf.print_usage(file=f)
self.assertIn('usage: test FOO BAR', f.getvalue()) self.assertIn('usage: test FOO BAR', f.getvalue())
@ -163,7 +162,7 @@ class UsageTestCase(BaseTestCase):
self.assertNotIn('optional:', f.getvalue()) self.assertNotIn('optional:', f.getvalue())
def test_print_help(self): def test_print_help(self):
f = moves.StringIO() f = io.StringIO()
self.conf([]) self.conf([])
self.conf.print_help(file=f) self.conf.print_help(file=f)
self.assertIn( self.assertIn(
@ -178,7 +177,7 @@ class UsageTestCase(BaseTestCase):
class HelpTestCase(BaseTestCase): class HelpTestCase(BaseTestCase):
def test_print_help(self): def test_print_help(self):
f = moves.StringIO() f = io.StringIO()
self.conf([]) self.conf([])
self.conf.print_help(file=f) self.conf.print_help(file=f)
self.assertIn( self.assertIn(
@ -189,7 +188,7 @@ class HelpTestCase(BaseTestCase):
self.assertIn('-h, --help', f.getvalue()) self.assertIn('-h, --help', f.getvalue())
def test_print_strOpt_with_choices_help(self): def test_print_strOpt_with_choices_help(self):
f = moves.StringIO() f = io.StringIO()
cli_opts = [ cli_opts = [
cfg.StrOpt('aa', short='a', default='xx', cfg.StrOpt('aa', short='a', default='xx',
choices=['xx', 'yy', 'zz'], choices=['xx', 'yy', 'zz'],
@ -218,7 +217,7 @@ class HelpTestCase(BaseTestCase):
f.getvalue()) f.getvalue())
def test_print_sorted_help(self): def test_print_sorted_help(self):
f = moves.StringIO() f = io.StringIO()
self.conf.register_cli_opt(cfg.StrOpt('abc')) self.conf.register_cli_opt(cfg.StrOpt('abc'))
self.conf.register_cli_opt(cfg.StrOpt('zba')) self.conf.register_cli_opt(cfg.StrOpt('zba'))
self.conf.register_cli_opt(cfg.StrOpt('ghi')) self.conf.register_cli_opt(cfg.StrOpt('ghi'))
@ -233,7 +232,7 @@ class HelpTestCase(BaseTestCase):
self.assertEqual(sorted(list), list) self.assertEqual(sorted(list), list)
def test_print_sorted_help_with_positionals(self): def test_print_sorted_help_with_positionals(self):
f = moves.StringIO() f = io.StringIO()
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('pst', positional=True, required=False)) cfg.StrOpt('pst', positional=True, required=False))
self.conf.register_cli_opt(cfg.StrOpt('abc')) self.conf.register_cli_opt(cfg.StrOpt('abc'))
@ -248,7 +247,7 @@ class HelpTestCase(BaseTestCase):
self.assertEqual(sorted(list), list) self.assertEqual(sorted(list), list)
def test_print_help_with_deprecated(self): def test_print_help_with_deprecated(self):
f = moves.StringIO() f = io.StringIO()
abc = cfg.StrOpt('a-bc', abc = cfg.StrOpt('a-bc',
deprecated_opts=[cfg.DeprecatedOpt('d-ef')]) deprecated_opts=[cfg.DeprecatedOpt('d-ef')])
uvw = cfg.StrOpt('u-vw', uvw = cfg.StrOpt('u-vw',
@ -779,7 +778,7 @@ class CliOptsTestCase(BaseTestCase):
class CliSpecialOptsTestCase(BaseTestCase): class CliSpecialOptsTestCase(BaseTestCase):
def test_help(self): def test_help(self):
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn('usage: test', sys.stdout.getvalue()) self.assertIn('usage: test', sys.stdout.getvalue())
self.assertIn('[--version]', sys.stdout.getvalue()) self.assertIn('[--version]', sys.stdout.getvalue())
@ -796,7 +795,7 @@ class CliSpecialOptsTestCase(BaseTestCase):
else: else:
stream_name = 'stderr' stream_name = 'stderr'
self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name, self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name,
moves.StringIO())) io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--version']) self.assertRaises(SystemExit, self.conf, ['--version'])
self.assertIn('1.0', getattr(sys, stream_name).getvalue()) self.assertIn('1.0', getattr(sys, stream_name).getvalue())
@ -925,7 +924,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo', required=True, positional=True)) cfg.StrOpt('foo', required=True, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' foo\n', sys.stdout.getvalue()) self.assertIn(' foo\n', sys.stdout.getvalue())
@ -938,7 +937,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo', required=True, positional=True)) cfg.StrOpt('foo', required=True, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' foo\n', sys.stdout.getvalue()) self.assertIn(' foo\n', sys.stdout.getvalue())
@ -948,7 +947,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo', required=False, positional=True)) cfg.StrOpt('foo', required=False, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' [foo]\n', sys.stdout.getvalue()) self.assertIn(' [foo]\n', sys.stdout.getvalue())
@ -961,7 +960,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo', required=False, positional=True)) cfg.StrOpt('foo', required=False, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' [foo]\n', sys.stdout.getvalue()) self.assertIn(' [foo]\n', sys.stdout.getvalue())
@ -974,7 +973,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo-bar', required=False, positional=True)) cfg.StrOpt('foo-bar', required=False, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' [foo_bar]\n', sys.stdout.getvalue()) self.assertIn(' [foo_bar]\n', sys.stdout.getvalue())
@ -986,7 +985,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo-bar', required=False, positional=True)) cfg.StrOpt('foo-bar', required=False, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' [foo_bar]\n', sys.stdout.getvalue()) self.assertIn(' [foo_bar]\n', sys.stdout.getvalue())
@ -998,7 +997,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo-bar', required=True, positional=True)) cfg.StrOpt('foo-bar', required=True, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' foo_bar\n', sys.stdout.getvalue()) self.assertIn(' foo_bar\n', sys.stdout.getvalue())
@ -1010,7 +1009,7 @@ class PositionalTestCase(BaseTestCase):
self.conf.register_cli_opt( self.conf.register_cli_opt(
cfg.StrOpt('foo-bar', required=True, positional=True)) cfg.StrOpt('foo-bar', required=True, positional=True))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn(' foo_bar\n', sys.stdout.getvalue()) self.assertIn(' foo_bar\n', sys.stdout.getvalue())
@ -3775,7 +3774,7 @@ class SadPathTestCase(BaseTestCase):
def test_bad_cli_arg(self): def test_bad_cli_arg(self):
self.conf.register_opt(cfg.BoolOpt('foo')) self.conf.register_opt(cfg.BoolOpt('foo'))
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stderr', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--foo']) self.assertRaises(SystemExit, self.conf, ['--foo'])
@ -3785,7 +3784,7 @@ class SadPathTestCase(BaseTestCase):
def _do_test_bad_cli_value(self, opt_class): def _do_test_bad_cli_value(self, opt_class):
self.conf.register_cli_opt(opt_class('foo')) self.conf.register_cli_opt(opt_class('foo'))
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stderr', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--foo', 'bar']) self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
@ -4071,7 +4070,7 @@ class ConfigParserTestCase(BaseTestCase):
def test_no_section(self): def test_no_section(self):
with tempfile.NamedTemporaryFile() as tmpfile: with tempfile.NamedTemporaryFile() as tmpfile:
tmpfile.write(six.b('foo = bar')) tmpfile.write(b'foo = bar')
tmpfile.flush() tmpfile.flush()
parser = cfg.ConfigParser(tmpfile.name, {}) parser = cfg.ConfigParser(tmpfile.name, {})
@ -4306,7 +4305,7 @@ class SubCommandTestCase(BaseTestCase):
def test_sub_command_no_handler(self): def test_sub_command_no_handler(self):
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd')) self.conf.register_cli_opt(cfg.SubCommandOpt('cmd'))
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stderr', io.StringIO()))
self.assertRaises(SystemExit, self.conf, []) self.assertRaises(SystemExit, self.conf, [])
self.assertIn('error', sys.stderr.getvalue()) self.assertIn('error', sys.stderr.getvalue())
@ -4319,7 +4318,7 @@ class SubCommandTestCase(BaseTestCase):
description='bar bar', description='bar bar',
help='blaa blaa', help='blaa blaa',
handler=add_parsers)) handler=add_parsers))
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stdout', io.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help']) self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertIn('foo foo', sys.stdout.getvalue()) self.assertIn('foo foo', sys.stdout.getvalue())
self.assertIn('bar bar', sys.stdout.getvalue()) self.assertIn('bar bar', sys.stdout.getvalue())
@ -4340,7 +4339,7 @@ class SubCommandTestCase(BaseTestCase):
def test_sub_command_multiple(self): def test_sub_command_multiple(self):
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1')) self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1'))
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd2')) self.conf.register_cli_opt(cfg.SubCommandOpt('cmd2'))
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO())) self.useFixture(fixtures.MonkeyPatch('sys.stderr', io.StringIO()))
self.assertRaises(SystemExit, self.conf, []) self.assertRaises(SystemExit, self.conf, [])
self.assertIn('multiple', sys.stderr.getvalue()) self.assertIn('multiple', sys.stderr.getvalue())

View File

@ -12,13 +12,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import io
import sys import sys
import textwrap import textwrap
import fixtures import fixtures
import mock import mock
from oslotest import base from oslotest import base
from six import moves
import tempfile import tempfile
import testscenarios import testscenarios
@ -963,7 +963,7 @@ class GeneratorTestCase(base.BaseTestCase):
def _capture_stream(self, stream_name): def _capture_stream(self, stream_name):
self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name, self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name,
moves.StringIO())) io.StringIO()))
return getattr(sys, stream_name) return getattr(sys, stream_name)
def _capture_stdout(self): def _capture_stdout(self):
@ -1103,7 +1103,7 @@ class DriverOptionTestCase(base.BaseTestCase):
# Initialize the generator to produce YAML output to a buffer. # Initialize the generator to produce YAML output to a buffer.
generator.register_cli_opts(self.conf) generator.register_cli_opts(self.conf)
self.config(namespace=['test_generator'], format_='yaml') self.config(namespace=['test_generator'], format_='yaml')
stdout = moves.StringIO() stdout = io.StringIO()
# Generate the output and parse it back to a data structure. # Generate the output and parse it back to a data structure.
generator.generate(self.conf, output_file=stdout) generator.generate(self.conf, output_file=stdout)
@ -1609,7 +1609,7 @@ class GeneratorAdditionalTestCase(base.BaseTestCase):
class GeneratorMutableOptionTestCase(base.BaseTestCase): class GeneratorMutableOptionTestCase(base.BaseTestCase):
def test_include_message(self): def test_include_message(self):
out = moves.StringIO() out = io.StringIO()
opt = cfg.StrOpt('foo', help='foo option', mutable=True) opt = cfg.StrOpt('foo', help='foo option', mutable=True)
gen = build_formatter(out) gen = build_formatter(out)
gen.format(opt, 'group1') gen.format(opt, 'group1')
@ -1620,7 +1620,7 @@ class GeneratorMutableOptionTestCase(base.BaseTestCase):
) )
def test_do_not_include_message(self): def test_do_not_include_message(self):
out = moves.StringIO() out = io.StringIO()
opt = cfg.StrOpt('foo', help='foo option', mutable=False) opt = cfg.StrOpt('foo', help='foo option', mutable=False)
gen = build_formatter(out) gen = build_formatter(out)
gen.format(opt, 'group1') gen.format(opt, 'group1')
@ -1854,7 +1854,7 @@ class HostAddressTestCase(base.BaseTestCase):
config = [("namespace", [("alpha", self.opts)])] config = [("namespace", [("alpha", self.opts)])]
groups = generator._get_groups(config) groups = generator._get_groups(config)
out = moves.StringIO() out = io.StringIO()
formatter = build_formatter(out) formatter = build_formatter(out)
generator._output_opts(formatter, 'alpha', groups.pop('alpha')) generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
result = out.getvalue() result = out.getvalue()
@ -1871,5 +1871,6 @@ class HostAddressTestCase(base.BaseTestCase):
''').lstrip() ''').lstrip()
self.assertEqual(expected, result) self.assertEqual(expected, result)
GeneratorTestCase.generate_scenarios() GeneratorTestCase.generate_scenarios()
MachineReadableGeneratorTestCase.generate_scenarios() MachineReadableGeneratorTestCase.generate_scenarios()

View File

@ -12,7 +12,9 @@
import os import os
from oslotest import base
from requests import HTTPError from requests import HTTPError
import requests_mock
from oslo_config import _list_opts from oslo_config import _list_opts
from oslo_config import cfg from oslo_config import cfg
@ -20,9 +22,6 @@ from oslo_config import fixture
from oslo_config import sources from oslo_config import sources
from oslo_config.sources import _uri from oslo_config.sources import _uri
from oslotest import base
import requests_mock
class TestProcessingSources(base.BaseTestCase): class TestProcessingSources(base.BaseTestCase):

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock import mock
from oslotest import base from oslotest import base

View File

@ -16,7 +16,6 @@ import re
import unittest import unittest
from oslo_config import types from oslo_config import types
from six.moves import range as compat_range
class ConfigTypeTests(unittest.TestCase): class ConfigTypeTests(unittest.TestCase):
@ -601,7 +600,7 @@ class RangeTypeTests(TypeTestHelper, unittest.TestCase):
type = types.Range() type = types.Range()
def assertRange(self, s, r1, r2, step=1): def assertRange(self, s, r1, r2, step=1):
self.assertEqual(list(compat_range(r1, r2, step)), self.assertEqual(list(range(r1, r2, step)),
list(self.type_instance(s))) list(self.type_instance(s)))
def test_range(self): def test_range(self):

View File

@ -14,7 +14,6 @@
import mock import mock
from oslotest import base from oslotest import base
import six
from oslo_config import cfg from oslo_config import cfg
from oslo_config import fixture from oslo_config import fixture
@ -49,10 +48,6 @@ class TestValidator(base.BaseTestCase):
self.conf = cfg.ConfigOpts() self.conf = cfg.ConfigOpts()
self.conf_fixture = self.useFixture(fixture.Config(self.conf)) self.conf_fixture = self.useFixture(fixture.Config(self.conf))
validator._register_cli_opts(self.conf) validator._register_cli_opts(self.conf)
if six.PY2:
self.open_name = '__builtin__.open'
else:
self.open_name = 'builtins.open'
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
def test_passing(self, mock_lod): def test_passing(self, mock_lod):
@ -60,7 +55,7 @@ class TestValidator(base.BaseTestCase):
self.conf_fixture.config(opt_data='mocked.yaml', self.conf_fixture.config(opt_data='mocked.yaml',
input_file='mocked.conf') input_file='mocked.conf')
m = mock.mock_open(read_data=VALID_CONF) m = mock.mock_open(read_data=VALID_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(0, validator._validate(self.conf)) self.assertEqual(0, validator._validate(self.conf))
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
@ -69,7 +64,7 @@ class TestValidator(base.BaseTestCase):
self.conf_fixture.config(opt_data='mocked.yaml', self.conf_fixture.config(opt_data='mocked.yaml',
input_file='mocked.conf') input_file='mocked.conf')
m = mock.mock_open(read_data=DEPRECATED_CONF) m = mock.mock_open(read_data=DEPRECATED_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(0, validator._validate(self.conf)) self.assertEqual(0, validator._validate(self.conf))
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
@ -79,7 +74,7 @@ class TestValidator(base.BaseTestCase):
input_file='mocked.conf', input_file='mocked.conf',
fatal_warnings=True) fatal_warnings=True)
m = mock.mock_open(read_data=DEPRECATED_CONF) m = mock.mock_open(read_data=DEPRECATED_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(1, validator._validate(self.conf)) self.assertEqual(1, validator._validate(self.conf))
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
@ -88,7 +83,7 @@ class TestValidator(base.BaseTestCase):
self.conf_fixture.config(opt_data='mocked.yaml', self.conf_fixture.config(opt_data='mocked.yaml',
input_file='mocked.conf') input_file='mocked.conf')
m = mock.mock_open(read_data=INVALID_CONF) m = mock.mock_open(read_data=INVALID_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(1, validator._validate(self.conf)) self.assertEqual(1, validator._validate(self.conf))
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
@ -97,7 +92,7 @@ class TestValidator(base.BaseTestCase):
self.conf_fixture.config(opt_data='mocked.yaml', self.conf_fixture.config(opt_data='mocked.yaml',
input_file='mocked.conf') input_file='mocked.conf')
m = mock.mock_open(read_data=MISSING_GROUP_CONF) m = mock.mock_open(read_data=MISSING_GROUP_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(1, validator._validate(self.conf)) self.assertEqual(1, validator._validate(self.conf))
@mock.patch('oslo_config.validator.load_opt_data') @mock.patch('oslo_config.validator.load_opt_data')
@ -107,7 +102,7 @@ class TestValidator(base.BaseTestCase):
input_file='mocked.conf', input_file='mocked.conf',
exclude_group=['oo']) exclude_group=['oo'])
m = mock.mock_open(read_data=MISSING_GROUP_CONF) m = mock.mock_open(read_data=MISSING_GROUP_CONF)
with mock.patch(self.open_name, m): with mock.patch('builtins.open', m):
self.assertEqual(0, validator._validate(self.conf)) self.assertEqual(0, validator._validate(self.conf))
def test_invalid_options(self): def test_invalid_options(self):

View File

@ -28,12 +28,10 @@ import abc
from debtcollector import removals from debtcollector import removals
import netaddr import netaddr
import rfc3986 import rfc3986
import six
from six.moves import range as compat_range
@six.add_metaclass(abc.ABCMeta) class ConfigType(object, metaclass=abc.ABCMeta):
class ConfigType(object):
def __init__(self, type_name='unknown type'): def __init__(self, type_name='unknown type'):
self.type_name = type_name self.type_name = type_name
@ -44,7 +42,7 @@ class ConfigType(object):
""" """
if sample_default is not None: if sample_default is not None:
if isinstance(sample_default, six.string_types): if isinstance(sample_default, str):
default_str = sample_default default_str = sample_default
else: else:
default_str = self._formatter(sample_default) default_str = self._formatter(sample_default)
@ -55,9 +53,9 @@ class ConfigType(object):
return [default_str] return [default_str]
def quote_trailing_and_leading_space(self, str_val): def quote_trailing_and_leading_space(self, str_val):
if not isinstance(str_val, six.string_types): if not isinstance(str_val, str):
warnings.warn('converting \'%s\' to a string' % str_val) warnings.warn('converting \'%s\' to a string' % str_val)
str_val = six.text_type(str_val) str_val = str(str_val)
if str_val.strip() != str_val: if str_val.strip() != str_val:
return '"%s"' % str_val return '"%s"' % str_val
return str_val return str_val
@ -135,7 +133,7 @@ class String(ConfigType):
re_flags = re.IGNORECASE if self.ignore_case else 0 re_flags = re.IGNORECASE if self.ignore_case else 0
# Check if regex is a string or an already compiled regex # Check if regex is a string or an already compiled regex
if isinstance(regex, six.string_types): if isinstance(regex, str):
self.regex = re.compile(regex, re_flags) self.regex = re.compile(regex, re_flags)
else: else:
self.regex = re.compile(regex.pattern, re_flags | regex.flags) self.regex = re.compile(regex.pattern, re_flags | regex.flags)
@ -351,7 +349,7 @@ class Number(ConfigType):
) )
def _formatter(self, value): def _formatter(self, value):
return six.text_type(value) return str(value)
class Integer(Number): class Integer(Number):
@ -484,7 +482,7 @@ class List(ConfigType):
def __call__(self, value): def __call__(self, value):
if isinstance(value, (list, tuple)): if isinstance(value, (list, tuple)):
return list(six.moves.map(self.item_type, value)) return list(map(self.item_type, value))
s = value.strip().rstrip(',') s = value.strip().rstrip(',')
if self.bounds: if self.bounds:
@ -531,7 +529,7 @@ class List(ConfigType):
def _formatter(self, value): def _formatter(self, value):
fmtstr = '[{}]' if self.bounds else '{}' fmtstr = '[{}]' if self.bounds else '{}'
if isinstance(value, six.string_types): if isinstance(value, str):
return fmtstr.format(value) return fmtstr.format(value)
if isinstance(value, list): if isinstance(value, list):
value = [ value = [
@ -585,7 +583,7 @@ class Range(ConfigType):
step = -1 step = -1
if self.inclusive: if self.inclusive:
right += step right += step
return compat_range(left, right, step) return range(left, right, step)
def __eq__(self, other): def __eq__(self, other):
return ( return (

View File

@ -4,7 +4,6 @@
debtcollector>=1.2.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0
netaddr>=0.7.18 # BSD netaddr>=0.7.18 # BSD
six>=1.10.0 # MIT
stevedore>=1.20.0 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0
rfc3986>=1.2.0 # Apache-2.0 rfc3986>=1.2.0 # Apache-2.0

View File

@ -20,7 +20,8 @@ oslo.log>=3.36.0 # Apache-2.0
# deps = {[testenv]deps} coverage # deps = {[testenv]deps} coverage
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
# mocking framework # we can switch to unittest.mock once we drop support for Python 3.6 as that
# includes https://bugs.python.org/issue32933
mock>=3.0.0 # BSD mock>=3.0.0 # BSD
requests_mock>=1.5.0 # Apache-2.0 requests_mock>=1.5.0 # Apache-2.0