diff options
Diffstat (limited to 'oslo_config/tests')
-rw-r--r-- | oslo_config/tests/test_cfg.py | 51 | ||||
-rw-r--r-- | oslo_config/tests/test_generator.py | 13 | ||||
-rw-r--r-- | oslo_config/tests/test_sources.py | 5 | ||||
-rw-r--r-- | oslo_config/tests/test_sphinxconfiggen.py | 1 | ||||
-rw-r--r-- | oslo_config/tests/test_types.py | 3 | ||||
-rw-r--r-- | oslo_config/tests/test_validator.py | 17 |
6 files changed, 41 insertions, 49 deletions
diff --git a/oslo_config/tests/test_cfg.py b/oslo_config/tests/test_cfg.py index e304807..302f39f 100644 --- a/oslo_config/tests/test_cfg.py +++ b/oslo_config/tests/test_cfg.py @@ -15,6 +15,7 @@ import argparse import errno import functools +import io import logging import os import shutil @@ -24,8 +25,6 @@ import tempfile import fixtures import mock from oslotest import base -import six -from six import moves import testscenarios from oslo_config import cfg @@ -139,7 +138,7 @@ class BaseTestCase(base.BaseTestCase): class UsageTestCase(BaseTestCase): def test_print_usage(self): - f = moves.StringIO() + f = io.StringIO() self.conf([]) self.conf.print_usage(file=f) self.assertIn( @@ -154,7 +153,7 @@ class UsageTestCase(BaseTestCase): conf = self.TestConfigOpts() self.tempdirs = [] - f = moves.StringIO() + f = io.StringIO() conf([], usage='%(prog)s FOO BAR') conf.print_usage(file=f) self.assertIn('usage: test FOO BAR', f.getvalue()) @@ -163,7 +162,7 @@ class UsageTestCase(BaseTestCase): self.assertNotIn('optional:', f.getvalue()) def test_print_help(self): - f = moves.StringIO() + f = io.StringIO() self.conf([]) self.conf.print_help(file=f) self.assertIn( @@ -178,7 +177,7 @@ class UsageTestCase(BaseTestCase): class HelpTestCase(BaseTestCase): def test_print_help(self): - f = moves.StringIO() + f = io.StringIO() self.conf([]) self.conf.print_help(file=f) self.assertIn( @@ -189,7 +188,7 @@ class HelpTestCase(BaseTestCase): self.assertIn('-h, --help', f.getvalue()) def test_print_strOpt_with_choices_help(self): - f = moves.StringIO() + f = io.StringIO() cli_opts = [ cfg.StrOpt('aa', short='a', default='xx', choices=['xx', 'yy', 'zz'], @@ -218,7 +217,7 @@ class HelpTestCase(BaseTestCase): f.getvalue()) 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('zba')) self.conf.register_cli_opt(cfg.StrOpt('ghi')) @@ -233,7 +232,7 @@ class HelpTestCase(BaseTestCase): self.assertEqual(sorted(list), list) def test_print_sorted_help_with_positionals(self): - f = moves.StringIO() + f = io.StringIO() self.conf.register_cli_opt( cfg.StrOpt('pst', positional=True, required=False)) self.conf.register_cli_opt(cfg.StrOpt('abc')) @@ -248,7 +247,7 @@ class HelpTestCase(BaseTestCase): self.assertEqual(sorted(list), list) def test_print_help_with_deprecated(self): - f = moves.StringIO() + f = io.StringIO() abc = cfg.StrOpt('a-bc', deprecated_opts=[cfg.DeprecatedOpt('d-ef')]) uvw = cfg.StrOpt('u-vw', @@ -779,7 +778,7 @@ class CliOptsTestCase(BaseTestCase): class CliSpecialOptsTestCase(BaseTestCase): 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.assertIn('usage: test', sys.stdout.getvalue()) self.assertIn('[--version]', sys.stdout.getvalue()) @@ -796,7 +795,7 @@ class CliSpecialOptsTestCase(BaseTestCase): else: stream_name = 'stderr' self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name, - moves.StringIO())) + io.StringIO())) self.assertRaises(SystemExit, self.conf, ['--version']) self.assertIn('1.0', getattr(sys, stream_name).getvalue()) @@ -925,7 +924,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' foo\n', sys.stdout.getvalue()) @@ -938,7 +937,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' foo\n', sys.stdout.getvalue()) @@ -948,7 +947,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' [foo]\n', sys.stdout.getvalue()) @@ -961,7 +960,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' [foo]\n', sys.stdout.getvalue()) @@ -974,7 +973,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' [foo_bar]\n', sys.stdout.getvalue()) @@ -986,7 +985,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' [foo_bar]\n', sys.stdout.getvalue()) @@ -998,7 +997,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' foo_bar\n', sys.stdout.getvalue()) @@ -1010,7 +1009,7 @@ class PositionalTestCase(BaseTestCase): self.conf.register_cli_opt( 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.assertIn(' foo_bar\n', sys.stdout.getvalue()) @@ -3775,7 +3774,7 @@ class SadPathTestCase(BaseTestCase): def test_bad_cli_arg(self): 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']) @@ -3785,7 +3784,7 @@ class SadPathTestCase(BaseTestCase): def _do_test_bad_cli_value(self, opt_class): 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']) @@ -4071,7 +4070,7 @@ class ConfigParserTestCase(BaseTestCase): def test_no_section(self): with tempfile.NamedTemporaryFile() as tmpfile: - tmpfile.write(six.b('foo = bar')) + tmpfile.write(b'foo = bar') tmpfile.flush() parser = cfg.ConfigParser(tmpfile.name, {}) @@ -4306,7 +4305,7 @@ class SubCommandTestCase(BaseTestCase): def test_sub_command_no_handler(self): 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.assertIn('error', sys.stderr.getvalue()) @@ -4319,7 +4318,7 @@ class SubCommandTestCase(BaseTestCase): description='bar bar', help='blaa blaa', 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.assertIn('foo foo', sys.stdout.getvalue()) self.assertIn('bar bar', sys.stdout.getvalue()) @@ -4340,7 +4339,7 @@ class SubCommandTestCase(BaseTestCase): def test_sub_command_multiple(self): self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1')) 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.assertIn('multiple', sys.stderr.getvalue()) diff --git a/oslo_config/tests/test_generator.py b/oslo_config/tests/test_generator.py index f28e5ea..becd49a 100644 --- a/oslo_config/tests/test_generator.py +++ b/oslo_config/tests/test_generator.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +import io import sys import textwrap import fixtures import mock from oslotest import base -from six import moves import tempfile import testscenarios @@ -963,7 +963,7 @@ class GeneratorTestCase(base.BaseTestCase): def _capture_stream(self, stream_name): self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name, - moves.StringIO())) + io.StringIO())) return getattr(sys, stream_name) def _capture_stdout(self): @@ -1103,7 +1103,7 @@ class DriverOptionTestCase(base.BaseTestCase): # Initialize the generator to produce YAML output to a buffer. generator.register_cli_opts(self.conf) self.config(namespace=['test_generator'], format_='yaml') - stdout = moves.StringIO() + stdout = io.StringIO() # Generate the output and parse it back to a data structure. generator.generate(self.conf, output_file=stdout) @@ -1609,7 +1609,7 @@ class GeneratorAdditionalTestCase(base.BaseTestCase): class GeneratorMutableOptionTestCase(base.BaseTestCase): def test_include_message(self): - out = moves.StringIO() + out = io.StringIO() opt = cfg.StrOpt('foo', help='foo option', mutable=True) gen = build_formatter(out) gen.format(opt, 'group1') @@ -1620,7 +1620,7 @@ class GeneratorMutableOptionTestCase(base.BaseTestCase): ) def test_do_not_include_message(self): - out = moves.StringIO() + out = io.StringIO() opt = cfg.StrOpt('foo', help='foo option', mutable=False) gen = build_formatter(out) gen.format(opt, 'group1') @@ -1854,7 +1854,7 @@ class HostAddressTestCase(base.BaseTestCase): config = [("namespace", [("alpha", self.opts)])] groups = generator._get_groups(config) - out = moves.StringIO() + out = io.StringIO() formatter = build_formatter(out) generator._output_opts(formatter, 'alpha', groups.pop('alpha')) result = out.getvalue() @@ -1871,5 +1871,6 @@ class HostAddressTestCase(base.BaseTestCase): ''').lstrip() self.assertEqual(expected, result) + GeneratorTestCase.generate_scenarios() MachineReadableGeneratorTestCase.generate_scenarios() diff --git a/oslo_config/tests/test_sources.py b/oslo_config/tests/test_sources.py index dca83b8..656f61e 100644 --- a/oslo_config/tests/test_sources.py +++ b/oslo_config/tests/test_sources.py @@ -12,7 +12,9 @@ import os +from oslotest import base from requests import HTTPError +import requests_mock from oslo_config import _list_opts from oslo_config import cfg @@ -20,9 +22,6 @@ from oslo_config import fixture from oslo_config import sources from oslo_config.sources import _uri -from oslotest import base -import requests_mock - class TestProcessingSources(base.BaseTestCase): diff --git a/oslo_config/tests/test_sphinxconfiggen.py b/oslo_config/tests/test_sphinxconfiggen.py index f28c731..982641e 100644 --- a/oslo_config/tests/test_sphinxconfiggen.py +++ b/oslo_config/tests/test_sphinxconfiggen.py @@ -10,7 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. - import mock from oslotest import base diff --git a/oslo_config/tests/test_types.py b/oslo_config/tests/test_types.py index e4f4779..644a239 100644 --- a/oslo_config/tests/test_types.py +++ b/oslo_config/tests/test_types.py @@ -16,7 +16,6 @@ import re import unittest from oslo_config import types -from six.moves import range as compat_range class ConfigTypeTests(unittest.TestCase): @@ -601,7 +600,7 @@ class RangeTypeTests(TypeTestHelper, unittest.TestCase): type = types.Range() 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))) def test_range(self): diff --git a/oslo_config/tests/test_validator.py b/oslo_config/tests/test_validator.py index 9d4aef8..a2ffde7 100644 --- a/oslo_config/tests/test_validator.py +++ b/oslo_config/tests/test_validator.py @@ -14,7 +14,6 @@ import mock from oslotest import base -import six from oslo_config import cfg from oslo_config import fixture @@ -49,10 +48,6 @@ class TestValidator(base.BaseTestCase): self.conf = cfg.ConfigOpts() self.conf_fixture = self.useFixture(fixture.Config(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') def test_passing(self, mock_lod): @@ -60,7 +55,7 @@ class TestValidator(base.BaseTestCase): self.conf_fixture.config(opt_data='mocked.yaml', input_file='mocked.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)) @mock.patch('oslo_config.validator.load_opt_data') @@ -69,7 +64,7 @@ class TestValidator(base.BaseTestCase): self.conf_fixture.config(opt_data='mocked.yaml', input_file='mocked.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)) @mock.patch('oslo_config.validator.load_opt_data') @@ -79,7 +74,7 @@ class TestValidator(base.BaseTestCase): input_file='mocked.conf', fatal_warnings=True) 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)) @mock.patch('oslo_config.validator.load_opt_data') @@ -88,7 +83,7 @@ class TestValidator(base.BaseTestCase): self.conf_fixture.config(opt_data='mocked.yaml', input_file='mocked.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)) @mock.patch('oslo_config.validator.load_opt_data') @@ -97,7 +92,7 @@ class TestValidator(base.BaseTestCase): self.conf_fixture.config(opt_data='mocked.yaml', input_file='mocked.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)) @mock.patch('oslo_config.validator.load_opt_data') @@ -107,7 +102,7 @@ class TestValidator(base.BaseTestCase): input_file='mocked.conf', exclude_group=['oo']) 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)) def test_invalid_options(self): |