diff options
author | Monty Taylor <mordred@inaugust.com> | 2013-03-19 20:15:59 -0700 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2013-03-24 16:36:56 +0100 |
commit | 14a75981b2c4d646b63be333024f98cf9db368a2 (patch) | |
tree | cc1c719c0e39b21d217f20b9f3baca17604fb7aa | |
parent | 329b8dd639e4f65369547f96f0ad841bb2fdf113 (diff) | |
download | oslo-14a75981b2c4d646b63be333024f98cf9db368a2.tar.gz oslo-14a75981b2c4d646b63be333024f98cf9db368a2.tar.xz oslo-14a75981b2c4d646b63be333024f98cf9db368a2.zip |
Update to use flake8.
flake8 is pluggable and handles pep8 and pyflakes, as well as configuration
through tox.ini. It also removes the need for flakes.py.
Change-Id: If5f7d8ad348b4fb8119fa4ec7b5e9d17bdc72a39
-rw-r--r-- | tests/unit/rpc/amqp.py | 4 | ||||
-rw-r--r-- | tests/unit/rpc/test_common.py | 5 | ||||
-rw-r--r-- | tests/unit/rpc/test_kombu.py | 6 | ||||
-rw-r--r-- | tests/unit/rpc/test_proxy.py | 1 | ||||
-rw-r--r-- | tests/unit/rpc/test_qpid.py | 3 | ||||
-rw-r--r-- | tests/unit/rpc/test_zmq.py | 1 | ||||
-rw-r--r-- | tests/unit/scheduler/test_host_filters.py | 1 | ||||
-rw-r--r-- | tests/unit/test_cfgfilter.py | 33 | ||||
-rw-r--r-- | tests/unit/test_cliutils.py | 150 | ||||
-rw-r--r-- | tests/unit/test_jsonutils.py | 2 | ||||
-rw-r--r-- | tests/unit/test_plugin.py | 2 | ||||
-rw-r--r-- | tests/unit/test_policy.py | 4 | ||||
-rw-r--r-- | tests/unit/test_setup.py | 32 | ||||
-rw-r--r-- | tests/unit/test_version.py | 4 | ||||
-rw-r--r-- | tools/test-requires | 3 | ||||
-rw-r--r-- | tox.ini | 13 |
16 files changed, 141 insertions, 123 deletions
diff --git a/tests/unit/rpc/amqp.py b/tests/unit/rpc/amqp.py index d8a3570..64a61f3 100644 --- a/tests/unit/rpc/amqp.py +++ b/tests/unit/rpc/amqp.py @@ -47,7 +47,7 @@ class BaseRpcAMQPTestCase(common.BaseRpcTestCase): def fake_unpack_context(*args, **kwargs): info['unpacked'] = True - raise test.TestingException('moo') + raise Exception('moo') self.stubs.Set(rpc_amqp, 'unpack_context', fake_unpack_context) @@ -144,7 +144,7 @@ class BaseRpcAMQPTestCase(common.BaseRpcTestCase): FLAGS, self.context, self.topic, {"method": "echo", "args": {"value": value}}, timeout=1) - except rpc_common.Timeout as exc: + except rpc_common.Timeout: # expect a timeout in this case if single_reply_queue_for_callee_off: result = 42 diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py index ee7bc96..cb7e35d 100644 --- a/tests/unit/rpc/test_common.py +++ b/tests/unit/rpc/test_common.py @@ -53,7 +53,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase): try: raise_exception() - except Exception as exc: + except Exception: failure = rpc_common.serialize_remote_exception(sys.exc_info()) failure = jsonutils.loads(failure) @@ -74,7 +74,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase): try: raise_custom_exception() - except Exception as exc: + except Exception: failure = rpc_common.serialize_remote_exception(sys.exc_info()) failure = jsonutils.loads(failure) @@ -218,7 +218,6 @@ class RpcCommonTestCase(test_utils.BaseTestCase): def naughty(): raise FooException() - e = None self.assertRaises(FooException, rpc_common.catch_client_exception, [ValueError], naughty) diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py index cb49169..ae07bed 100644 --- a/tests/unit/rpc/test_kombu.py +++ b/tests/unit/rpc/test_kombu.py @@ -434,8 +434,8 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase): conn.declare_direct_consumer('a_direct', _callback) conn.direct_send('a_direct', rpc_common.serialize_msg(message)) - info = _raise_exc_stub(self.stubs, 1, conn.connection, - 'drain_events', 'foo timeout foo') + _raise_exc_stub(self.stubs, 1, conn.connection, + 'drain_events', 'foo timeout foo') conn.consume(limit=1) conn.close() @@ -591,7 +591,7 @@ class RpcKombuHATestCase(utils.BaseTestCase): self.stubs.Set(kombu.connection, 'BrokerConnection', MyConnection) - conn = self.rpc.Connection(FLAGS) + self.rpc.Connection(FLAGS) self.assertEqual(info['attempt'], 5) diff --git a/tests/unit/rpc/test_proxy.py b/tests/unit/rpc/test_proxy.py index 5ac4cea..97bb9d5 100644 --- a/tests/unit/rpc/test_proxy.py +++ b/tests/unit/rpc/test_proxy.py @@ -33,7 +33,6 @@ class RpcProxyTestCase(utils.BaseTestCase): def _test_rpc_method(self, rpc_method, has_timeout=False, has_retval=False, server_params=None, supports_topic_override=True): topic = 'fake_topic' - timeout = None rpc_proxy = proxy.RpcProxy(topic, '1.0') ctxt = context.RequestContext('fake_user', 'fake_project') msg = {'method': 'fake_method', 'args': {'x': 'y'}} diff --git a/tests/unit/rpc/test_qpid.py b/tests/unit/rpc/test_qpid.py index e119793..0ee05cf 100644 --- a/tests/unit/rpc/test_qpid.py +++ b/tests/unit/rpc/test_qpid.py @@ -478,9 +478,6 @@ class RpcQpidTestCase(utils.BaseTestCase): # that it doesn't mess up other test cases. impl_qpid.Connection.pool.get() - def test_call(self): - self._test_call(multi=False) - def test_call_with_timeout(self): """A little more indepth for a timeout test. Specifically we are looking to simulate the event sent to qpid dying on the vine due diff --git a/tests/unit/rpc/test_zmq.py b/tests/unit/rpc/test_zmq.py index 5380a98..21345a9 100644 --- a/tests/unit/rpc/test_zmq.py +++ b/tests/unit/rpc/test_zmq.py @@ -30,7 +30,6 @@ import fixtures from oslo.config import cfg from openstack.common.gettextutils import _ -from openstack.common.rpc import common as rpc_common from tests.unit.rpc import common try: diff --git a/tests/unit/scheduler/test_host_filters.py b/tests/unit/scheduler/test_host_filters.py index bc6b7af..c36021c 100644 --- a/tests/unit/scheduler/test_host_filters.py +++ b/tests/unit/scheduler/test_host_filters.py @@ -418,7 +418,6 @@ class HostFiltersTestCase(utils.BaseTestCase): 'local_gb': 200}, 'scheduler_hints': {'query': json_query}} capabilities = {'enabled': True} - service = {'disabled': True} host = fakes.FakeHostState('host1', {'free_ram_mb': 1024, 'free_disk_mb': 200 * 1024, diff --git a/tests/unit/test_cfgfilter.py b/tests/unit/test_cfgfilter.py index e78acc8..58b4e2d 100644 --- a/tests/unit/test_cfgfilter.py +++ b/tests/unit/test_cfgfilter.py @@ -14,9 +14,9 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo.config.cfg import * +from oslo.config import cfg -from openstack.common.cfgfilter import * +from openstack.common import cfgfilter from tests import utils @@ -24,11 +24,11 @@ class ConfigFilterTestCase(utils.BaseTestCase): def setUp(self): super(ConfigFilterTestCase, self).setUp() - self.conf = ConfigOpts() - self.fconf = ConfigFilter(self.conf) + self.conf = cfg.ConfigOpts() + self.fconf = cfgfilter.ConfigFilter(self.conf) def test_register_opt_default(self): - self.fconf.register_opt(StrOpt('foo', default='bar')) + self.fconf.register_opt(cfg.StrOpt('foo', default='bar')) self.assertEquals(self.fconf.foo, 'bar') self.assertEquals(self.fconf['foo'], 'bar') @@ -37,7 +37,7 @@ class ConfigFilterTestCase(utils.BaseTestCase): self.assertEquals(len(self.fconf), 1) def test_register_opt_none_default(self): - self.fconf.register_opt(StrOpt('foo')) + self.fconf.register_opt(cfg.StrOpt('foo')) self.assertTrue(self.fconf.foo is None) self.assertTrue(self.fconf['foo'] is None) @@ -46,7 +46,8 @@ class ConfigFilterTestCase(utils.BaseTestCase): self.assertEquals(len(self.fconf), 1) def test_register_grouped_opt_default(self): - self.fconf.register_opt(StrOpt('foo', default='bar'), group='blaa') + self.fconf.register_opt(cfg.StrOpt('foo', default='bar'), + group='blaa') self.assertEquals(self.fconf.blaa.foo, 'bar') self.assertEquals(self.fconf['blaa']['foo'], 'bar') @@ -58,7 +59,7 @@ class ConfigFilterTestCase(utils.BaseTestCase): self.assertEquals(len(self.fconf.blaa), 1) def test_register_grouped_opt_none_default(self): - self.fconf.register_opt(StrOpt('foo'), group='blaa') + self.fconf.register_opt(cfg.StrOpt('foo'), group='blaa') self.assertTrue(self.fconf.blaa.foo is None) self.assertTrue(self.fconf['blaa']['foo'] is None) @@ -70,9 +71,9 @@ class ConfigFilterTestCase(utils.BaseTestCase): self.assertEquals(len(self.fconf.blaa), 1) def test_register_group(self): - group = OptGroup('blaa') + group = cfg.OptGroup('blaa') self.fconf.register_group(group) - self.fconf.register_opt(StrOpt('foo'), group=group) + self.fconf.register_opt(cfg.StrOpt('foo'), group=group) self.assertTrue(self.fconf.blaa.foo is None) self.assertTrue(self.fconf['blaa']['foo'] is None) @@ -86,33 +87,33 @@ class ConfigFilterTestCase(utils.BaseTestCase): def test_unknown_opt(self): self.assertFalse('foo' in self.fconf) self.assertEquals(len(self.fconf), 0) - self.assertRaises(NoSuchOptError, getattr, self.fconf, 'foo') + self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo') def test_blocked_opt(self): - self.conf.register_opt(StrOpt('foo')) + self.conf.register_opt(cfg.StrOpt('foo')) self.assertTrue('foo' in self.conf) self.assertEquals(len(self.conf), 1) self.assertTrue(self.conf.foo is None) self.assertFalse('foo' in self.fconf) self.assertEquals(len(self.fconf), 0) - self.assertRaises(NoSuchOptError, getattr, self.fconf, 'foo') + self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo') def test_import_opt(self): - self.fconf = ConfigFilter(CONF) + self.fconf = cfgfilter.ConfigFilter(cfg.CONF) self.assertFalse(hasattr(self.fconf, 'blaa')) self.fconf.import_opt('blaa', 'tests.testmods.blaa_opt') self.assertTrue(hasattr(self.fconf, 'blaa')) def test_import_opt_in_group(self): - self.fconf = ConfigFilter(CONF) + self.fconf = cfgfilter.ConfigFilter(cfg.CONF) self.assertFalse(hasattr(self.fconf, 'bar')) self.fconf.import_opt('foo', 'tests.testmods.bar_foo_opt', group='bar') self.assertTrue(hasattr(self.fconf, 'bar')) self.assertTrue(hasattr(self.fconf.bar, 'foo')) def test_import_group(self): - self.fconf = ConfigFilter(CONF) + self.fconf = cfgfilter.ConfigFilter(cfg.CONF) self.assertFalse(hasattr(self.fconf, 'baar')) self.fconf.import_group('baar', 'tests.testmods.baar_baa_opt') self.assertTrue(hasattr(self.fconf, 'baar')) diff --git a/tests/unit/test_cliutils.py b/tests/unit/test_cliutils.py index 08bd97b..13f954c 100644 --- a/tests/unit/test_cliutils.py +++ b/tests/unit/test_cliutils.py @@ -14,17 +14,17 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.common.cliutils import * +from openstack.common import cliutils from tests import utils class ValidateArgsTest(utils.BaseTestCase): def test_lambda_no_args(self): - validate_args(lambda: None) + cliutils.validate_args(lambda: None) def _test_lambda_with_args(self, *args, **kwargs): - validate_args(lambda x, y: None, *args, **kwargs) + cliutils.validate_args(lambda x, y: None, *args, **kwargs) def test_lambda_positional_args(self): self._test_lambda_with_args(1, 2) @@ -36,16 +36,19 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_lambda_with_args(1, y=2) def test_lambda_missing_args1(self): - self.assertRaises(MissingArgs, self._test_lambda_with_args) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_args) def test_lambda_missing_args2(self): - self.assertRaises(MissingArgs, self._test_lambda_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_args, 1) def test_lambda_missing_args3(self): - self.assertRaises(MissingArgs, self._test_lambda_with_args, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_args, y=2) def _test_lambda_with_default(self, *args, **kwargs): - validate_args(lambda x, y, z=3: None, *args, **kwargs) + cliutils.validate_args(lambda x, y, z=3: None, *args, **kwargs) def test_lambda_positional_args_with_default(self): self._test_lambda_with_default(1, 2) @@ -66,27 +69,30 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_lambda_with_default(1, y=2, z=3) def test_lambda_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_lambda_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_default) def test_lambda_with_default_missing_args2(self): - self.assertRaises(MissingArgs, self._test_lambda_with_default, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_default, 1) def test_lambda_with_default_missing_args3(self): - self.assertRaises(MissingArgs, self._test_lambda_with_default, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_lambda_with_default, y=2) def test_lambda_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_lambda_with_default, y=2, z=3) def test_function_no_args(self): def func(): pass - validate_args(func) + cliutils.validate_args(func) def _test_function_with_args(self, *args, **kwargs): def func(x, y): pass - validate_args(func, *args, **kwargs) + cliutils.validate_args(func, *args, **kwargs) def test_function_positional_args(self): self._test_function_with_args(1, 2) @@ -98,18 +104,20 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_function_with_args(1, y=2) def test_function_missing_args1(self): - self.assertRaises(MissingArgs, self._test_function_with_args) + self.assertRaises(cliutils.MissingArgs, self._test_function_with_args) def test_function_missing_args2(self): - self.assertRaises(MissingArgs, self._test_function_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_function_with_args, 1) def test_function_missing_args3(self): - self.assertRaises(MissingArgs, self._test_function_with_args, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_function_with_args, y=2) def _test_function_with_default(self, *args, **kwargs): def func(x, y, z=3): pass - validate_args(func, *args, **kwargs) + cliutils.validate_args(func, *args, **kwargs) def test_function_positional_args_with_default(self): self._test_function_with_default(1, 2) @@ -130,29 +138,32 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_function_with_default(1, y=2, z=3) def test_function_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_function_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_function_with_default) def test_function_with_default_missing_args2(self): - self.assertRaises(MissingArgs, self._test_function_with_default, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_function_with_default, 1) def test_function_with_default_missing_args3(self): - self.assertRaises(MissingArgs, self._test_function_with_default, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_function_with_default, y=2) def test_function_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_function_with_default, y=2, z=3) def test_bound_method_no_args(self): class Foo: def bar(self): pass - validate_args(Foo().bar) + cliutils.validate_args(Foo().bar) def _test_bound_method_with_args(self, *args, **kwargs): class Foo: def bar(self, x, y): pass - validate_args(Foo().bar, *args, **kwargs) + cliutils.validate_args(Foo().bar, *args, **kwargs) def test_bound_method_positional_args(self): self._test_bound_method_with_args(1, 2) @@ -164,19 +175,22 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_bound_method_with_args(1, y=2) def test_bound_method_missing_args1(self): - self.assertRaises(MissingArgs, self._test_bound_method_with_args) + self.assertRaises(cliutils.MissingArgs, + self._test_bound_method_with_args) def test_bound_method_missing_args2(self): - self.assertRaises(MissingArgs, self._test_bound_method_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_bound_method_with_args, 1) def test_bound_method_missing_args3(self): - self.assertRaises(MissingArgs, self._test_bound_method_with_args, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_bound_method_with_args, y=2) def _test_bound_method_with_default(self, *args, **kwargs): class Foo: def bar(self, x, y, z=3): pass - validate_args(Foo().bar, *args, **kwargs) + cliutils.validate_args(Foo().bar, *args, **kwargs) def test_bound_method_positional_args_with_default(self): self._test_bound_method_with_default(1, 2) @@ -197,30 +211,32 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_bound_method_with_default(1, y=2, z=3) def test_bound_method_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_bound_method_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_bound_method_with_default) def test_bound_method_with_default_missing_args2(self): - self.assertRaises(MissingArgs, self._test_bound_method_with_default, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_bound_method_with_default, 1) def test_bound_method_with_default_missing_args3(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_bound_method_with_default, y=2) def test_bound_method_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_bound_method_with_default, y=2, z=3) def test_unbound_method_no_args(self): class Foo: def bar(self): pass - validate_args(Foo.bar, Foo()) + cliutils.validate_args(Foo.bar, Foo()) def _test_unbound_method_with_args(self, *args, **kwargs): class Foo: def bar(self, x, y): pass - validate_args(Foo.bar, Foo(), *args, **kwargs) + cliutils.validate_args(Foo.bar, Foo(), *args, **kwargs) def test_unbound_method_positional_args(self): self._test_unbound_method_with_args(1, 2) @@ -232,20 +248,22 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_unbound_method_with_args(1, y=2) def test_unbound_method_missing_args1(self): - self.assertRaises(MissingArgs, self._test_unbound_method_with_args) + self.assertRaises(cliutils.MissingArgs, + self._test_unbound_method_with_args) def test_unbound_method_missing_args2(self): - self.assertRaises(MissingArgs, self._test_unbound_method_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_unbound_method_with_args, 1) def test_unbound_method_missing_args3(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_unbound_method_with_args, y=2) def _test_unbound_method_with_default(self, *args, **kwargs): class Foo: def bar(self, x, y, z=3): pass - validate_args(Foo.bar, Foo(), *args, **kwargs) + cliutils.validate_args(Foo.bar, Foo(), *args, **kwargs) def test_unbound_method_positional_args_with_default(self): self._test_unbound_method_with_default(1, 2) @@ -257,18 +275,19 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_unbound_method_with_default(1, y=2) def test_unbound_method_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_unbound_method_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_unbound_method_with_default) def test_unbound_method_with_default_missing_args2(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_unbound_method_with_default, 1) def test_unbound_method_with_default_missing_args3(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_unbound_method_with_default, y=2) def test_unbound_method_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_unbound_method_with_default, y=2, z=3) def test_class_method_no_args(self): @@ -276,14 +295,14 @@ class ValidateArgsTest(utils.BaseTestCase): @classmethod def bar(cls): pass - validate_args(Foo.bar) + cliutils.validate_args(Foo.bar) def _test_class_method_with_args(self, *args, **kwargs): class Foo: @classmethod def bar(cls, x, y): pass - validate_args(Foo.bar, *args, **kwargs) + cliutils.validate_args(Foo.bar, *args, **kwargs) def test_class_method_positional_args(self): self._test_class_method_with_args(1, 2) @@ -295,20 +314,23 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_class_method_with_args(1, y=2) def test_class_method_missing_args1(self): - self.assertRaises(MissingArgs, self._test_class_method_with_args) + self.assertRaises(cliutils.MissingArgs, + self._test_class_method_with_args) def test_class_method_missing_args2(self): - self.assertRaises(MissingArgs, self._test_class_method_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_class_method_with_args, 1) def test_class_method_missing_args3(self): - self.assertRaises(MissingArgs, self._test_class_method_with_args, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_class_method_with_args, y=2) def _test_class_method_with_default(self, *args, **kwargs): class Foo: @classmethod def bar(cls, x, y, z=3): pass - validate_args(Foo.bar, *args, **kwargs) + cliutils.validate_args(Foo.bar, *args, **kwargs) def test_class_method_positional_args_with_default(self): self._test_class_method_with_default(1, 2) @@ -320,17 +342,19 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_class_method_with_default(1, y=2) def test_class_method_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_class_method_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_class_method_with_default) def test_class_method_with_default_missing_args2(self): - self.assertRaises(MissingArgs, self._test_class_method_with_default, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_class_method_with_default, 1) def test_class_method_with_default_missing_args3(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_class_method_with_default, y=2) def test_class_method_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_class_method_with_default, y=2, z=3) def test_static_method_no_args(self): @@ -338,14 +362,14 @@ class ValidateArgsTest(utils.BaseTestCase): @staticmethod def bar(): pass - validate_args(Foo.bar) + cliutils.validate_args(Foo.bar) def _test_static_method_with_args(self, *args, **kwargs): class Foo: @staticmethod def bar(x, y): pass - validate_args(Foo.bar, *args, **kwargs) + cliutils.validate_args(Foo.bar, *args, **kwargs) def test_static_method_positional_args(self): self._test_static_method_with_args(1, 2) @@ -357,20 +381,23 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_static_method_with_args(1, y=2) def test_static_method_missing_args1(self): - self.assertRaises(MissingArgs, self._test_static_method_with_args) + self.assertRaises(cliutils.MissingArgs, + self._test_static_method_with_args) def test_static_method_missing_args2(self): - self.assertRaises(MissingArgs, self._test_static_method_with_args, 1) + self.assertRaises(cliutils.MissingArgs, + self._test_static_method_with_args, 1) def test_static_method_missing_args3(self): - self.assertRaises(MissingArgs, self._test_static_method_with_args, y=2) + self.assertRaises(cliutils.MissingArgs, + self._test_static_method_with_args, y=2) def _test_static_method_with_default(self, *args, **kwargs): class Foo: @staticmethod def bar(x, y, z=3): pass - validate_args(Foo.bar, *args, **kwargs) + cliutils.validate_args(Foo.bar, *args, **kwargs) def test_static_method_positional_args_with_default(self): self._test_static_method_with_default(1, 2) @@ -382,16 +409,17 @@ class ValidateArgsTest(utils.BaseTestCase): self._test_static_method_with_default(1, y=2) def test_static_method_with_default_missing_args1(self): - self.assertRaises(MissingArgs, self._test_static_method_with_default) + self.assertRaises(cliutils.MissingArgs, + self._test_static_method_with_default) def test_static_method_with_default_missing_args2(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_static_method_with_default, 1) def test_static_method_with_default_missing_args3(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_static_method_with_default, y=2) def test_static_method_with_default_missing_args4(self): - self.assertRaises(MissingArgs, + self.assertRaises(cliutils.MissingArgs, self._test_static_method_with_default, y=2, z=3) diff --git a/tests/unit/test_jsonutils.py b/tests/unit/test_jsonutils.py index b6c0feb..35a9487 100644 --- a/tests/unit/test_jsonutils.py +++ b/tests/unit/test_jsonutils.py @@ -115,7 +115,7 @@ class ToPrimitiveTestCase(utils.BaseTestCase): # If the cycle isn't caught, to_primitive() will eventually result in # an exception due to excessive recursion depth. - p = jsonutils.to_primitive(x) + jsonutils.to_primitive(x) def test_instance(self): class MysteryClass(object): diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 8b27397..8ee405a 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -110,8 +110,6 @@ class APITestCase(utils.BaseTestCase): self.stubs.Set(pkg_resources, 'iter_entry_points', mock_iter_entry_points) - stubLoaded = False - mgr = MockExtManager() plugmgr = pluginmanager.PluginManager("testproject", "testservice") plugmgr.load_plugins() diff --git a/tests/unit/test_policy.py b/tests/unit/test_policy.py index 31a4890..7e56796 100644 --- a/tests/unit/test_policy.py +++ b/tests/unit/test_policy.py @@ -175,8 +175,8 @@ class CheckFunctionTestCase(utils.BaseTestCase): policy._rules = None try: - result = policy.check('rule', 'target', 'creds', TestException, - "arg1", "arg2", kw1="kwarg1", kw2="kwarg2") + policy.check('rule', 'target', 'creds', TestException, + "arg1", "arg2", kw1="kwarg1", kw2="kwarg2") except TestException as exc: self.assertEqual(exc.args, ("arg1", "arg2")) self.assertEqual(exc.kwargs, dict(kw1="kwarg1", kw2="kwarg2")) diff --git a/tests/unit/test_setup.py b/tests/unit/test_setup.py index 64ca0e2..fecc1d2 100644 --- a/tests/unit/test_setup.py +++ b/tests/unit/test_setup.py @@ -23,7 +23,7 @@ from tempfile import mkstemp import fixtures -from openstack.common.setup import * +from openstack.common import setup from tests import utils @@ -49,7 +49,7 @@ class EmailTestCase(utils.BaseTestCase): string = 'Johnnie T. Hozer' mapping = {'T.': 'The'} self.assertEqual('Johnnie The Hozer', - canonicalize_emails(string, mapping)) + setup.canonicalize_emails(string, mapping)) class MailmapTestCase(utils.BaseTestCase): @@ -63,19 +63,19 @@ class MailmapTestCase(utils.BaseTestCase): with open(self.mailmap, 'w') as mm_fh: mm_fh.write("Foo Bar <email@foo.com> Foo Bar <email@bar.com>\n") self.assertEqual({'<email@bar.com>': '<email@foo.com>'}, - parse_mailmap(self.mailmap)) + setup.parse_mailmap(self.mailmap)) def test_mailmap_with_firstname(self): with open(self.mailmap, 'w') as mm_fh: mm_fh.write("Foo <email@foo.com> Foo <email@bar.com>\n") self.assertEqual({'<email@bar.com>': '<email@foo.com>'}, - parse_mailmap(self.mailmap)) + setup.parse_mailmap(self.mailmap)) def test_mailmap_with_noname(self): with open(self.mailmap, 'w') as mm_fh: mm_fh.write("<email@foo.com> <email@bar.com>\n") self.assertEqual({'<email@bar.com>': '<email@foo.com>'}, - parse_mailmap(self.mailmap)) + setup.parse_mailmap(self.mailmap)) class GitLogsTest(utils.BaseTestCase): @@ -114,7 +114,7 @@ class GitLogsTest(utils.BaseTestCase): return builtin_open(name, mode) self.useFixture(fixtures.MonkeyPatch("__builtin__.open", _fake_open)) - write_git_changelog() + setup.write_git_changelog() with open(os.path.join(root_dir, "ChangeLog"), "r") as ch_fh: self.assertTrue("email@foo.com" in ch_fh.read()) @@ -156,7 +156,7 @@ class GitLogsTest(utils.BaseTestCase): with open("AUTHORS.in", "w") as auth_fh: auth_fh.write(author_old) - generate_authors() + setup.generate_authors() with open("AUTHORS", "r") as auth_fh: authors = auth_fh.read() @@ -168,7 +168,7 @@ class GitLogsTest(utils.BaseTestCase): class GetCmdClassTest(utils.BaseTestCase): def test_get_cmdclass(self): - cmdclass = get_cmdclass() + cmdclass = setup.get_cmdclass() self.assertTrue("sdist" in cmdclass) build_sphinx = cmdclass.get("build_sphinx") @@ -204,31 +204,31 @@ class ParseRequirementsTest(utils.BaseTestCase): with open(self.tmp_file, 'w') as fh: fh.write("foo\nbar") self.assertEqual(['foo', 'bar'], - parse_requirements([self.tmp_file])) + setup.parse_requirements([self.tmp_file])) def test_parse_requirements_with_git_egg_url(self): with open(self.tmp_file, 'w') as fh: fh.write("-e git://foo.com/zipball#egg=bar") - self.assertEqual(['bar'], parse_requirements([self.tmp_file])) + self.assertEqual(['bar'], setup.parse_requirements([self.tmp_file])) def test_parse_requirements_with_http_egg_url(self): with open(self.tmp_file, 'w') as fh: fh.write("https://foo.com/zipball#egg=bar") - self.assertEqual(['bar'], parse_requirements([self.tmp_file])) + self.assertEqual(['bar'], setup.parse_requirements([self.tmp_file])) def test_parse_requirements_removes_index_lines(self): with open(self.tmp_file, 'w') as fh: fh.write("-f foobar") - self.assertEqual([], parse_requirements([self.tmp_file])) + self.assertEqual([], setup.parse_requirements([self.tmp_file])) def test_parse_requirements_removes_argparse(self): with open(self.tmp_file, 'w') as fh: fh.write("argparse") if sys.version_info >= (2, 7): - self.assertEqual([], parse_requirements([self.tmp_file])) + self.assertEqual([], setup.parse_requirements([self.tmp_file])) def test_get_requirement_from_file_empty(self): - actual = get_reqs_from_files([]) + actual = setup.get_reqs_from_files([]) self.assertEqual([], actual) @@ -244,11 +244,11 @@ class ParseDependencyLinksTest(utils.BaseTestCase): fh.write("http://test.com\n") self.assertEqual( ["http://test.com"], - parse_dependency_links([self.tmp_file])) + setup.parse_dependency_links([self.tmp_file])) def test_parse_dependency_with_git_egg_url(self): with open(self.tmp_file, "w") as fh: fh.write("-e git://foo.com/zipball#egg=bar") self.assertEqual( ["git://foo.com/zipball#egg=bar"], - parse_dependency_links([self.tmp_file])) + setup.parse_dependency_links([self.tmp_file])) diff --git a/tests/unit/test_version.py b/tests/unit/test_version.py index 2133e89..7f80de3 100644 --- a/tests/unit/test_version.py +++ b/tests/unit/test_version.py @@ -18,7 +18,7 @@ import StringIO import sys -from oslo.config.cfg import * +from oslo.config import cfg from openstack.common import version from tests import utils @@ -28,7 +28,7 @@ class DeferredVersionTestCase(utils.BaseTestCase): def setUp(self): super(DeferredVersionTestCase, self).setUp() - self.conf = ConfigOpts() + self.conf = cfg.ConfigOpts() def test_cached_version(self): class MyVersionInfo(version.VersionInfo): diff --git a/tools/test-requires b/tools/test-requires index 48ea78e..93f93e0 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -3,6 +3,7 @@ distribute>=0.6.24 coverage fixtures>=0.3.12 +flake8 mock mox==0.5.3 mysql-python @@ -11,8 +12,6 @@ nose-exclude nosexcover openstack.nose_plugin nosehtmloutput -pep8==1.3.3 -pyflakes>=0.6.1 pylint pyzmq==2.2.0.1 redis @@ -13,8 +13,12 @@ deps = -r{toxinidir}/tools/pip-requires -r{toxinidir}/tools/test-requires commands = nosetests --with-doctest --exclude-dir=tests/testmods {posargs} +[flake8] +show-source = True +exclude = .venv,.tox,dist,doc,*.egg,.update-venv + [testenv:pep8] -commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,*.egg,.update-venv . +commands = flake8 [testenv:pylint] deps = pylint>=0.26.0 @@ -27,10 +31,5 @@ setenv = NOSE_WITH_COVERAGE=1 [testenv:venv] commands = {posargs} -[testenv:full] -deps = -r{toxinidir}/tools/pip-requires - -r{toxinidir}/tools/test-requires - -r{toxinidir}/tools/test-options - [testenv:pyflakes] -commands = python tools/flakes.py openstack setup.py update.py +commands = flake8 |