From cb7b96aa1a57faa62ea03911dd66373dfb6e335e Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Sat, 4 Feb 2017 10:50:16 +0530 Subject: [PATCH] Refactor tests to comply with Flake8 Resolves Issue #378 --- CONTRIBUTORS | 1 + cement/ext/ext_daemon.py | 4 +- cement/ext/ext_handlebars.py | 2 + cement/utils/fs.py | 1 + scripts/devtools.py | 2 +- tests/core/backend_tests.py | 2 +- tests/core/cache_tests.py | 2 +- tests/core/config_tests.py | 3 +- tests/core/controller_tests.py | 6 +-- tests/core/extension_tests.py | 2 +- tests/core/foundation_tests.py | 67 +++++++++++++++---------------- tests/core/handler_tests.py | 13 ++++-- tests/core/hook_tests.py | 5 ++- tests/core/interface_tests.py | 7 ++-- tests/core/log_tests.py | 3 +- tests/core/meta_tests.py | 2 +- tests/core/output_tests.py | 7 ++-- tests/core/plugin_tests.py | 2 +- tests/ext/alarm_tests.py | 2 - tests/ext/argcomplete_tests.py | 20 ++++----- tests/ext/argparse_tests.py | 22 +++++----- tests/ext/colorlog_tests.py | 2 +- tests/ext/configobj_tests.py | 3 -- tests/ext/configparser_tests.py | 1 - tests/ext/daemon_tests.py | 4 +- tests/ext/genshi_tests.py | 12 +++--- tests/ext/handlebars_tests.py | 17 ++++---- tests/ext/jinja2_tests.py | 17 ++++---- tests/ext/json_configobj_tests.py | 3 -- tests/ext/json_tests.py | 2 - tests/ext/logging_tests.py | 4 +- tests/ext/memcached_tests.py | 3 -- tests/ext/mustache_tests.py | 11 +++-- tests/ext/redis_tests.py | 3 -- tests/ext/reload_config_tests.py | 13 +++--- tests/ext/smtp_tests.py | 4 +- tests/ext/tabulate_tests.py | 3 -- tests/ext/watchdog_tests.py | 5 ++- tests/ext/yaml_configobj_tests.py | 4 -- tests/ext/yaml_tests.py | 3 -- tests/utils/fs_tests.py | 9 ++--- tests/utils/misc_tests.py | 8 ++-- tests/utils/shell_tests.py | 8 ++-- 43 files changed, 143 insertions(+), 171 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 432e9f70..e7fd8428 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -9,3 +9,4 @@ documentation, or testing. * Tomasz Czyż (spinus) * Ildar Akhmetgaleev (akhilman) * Nicolas Brisac (zacbri) + * Subhash Bhushan (subhashb) diff --git a/cement/ext/ext_daemon.py b/cement/ext/ext_daemon.py index 8fae75cd..8e646e8e 100644 --- a/cement/ext/ext_daemon.py +++ b/cement/ext/ext_daemon.py @@ -169,7 +169,7 @@ passed. app.pargs.daemon = True app.daemonize() -Note that this would only work **after** arguments have been parsed (i.e. +Note that this would only work **after** arguments have been parsed (i.e. after ``app.run()`` is called). """ @@ -377,7 +377,7 @@ def daemonize(): # pragma: no cover # ugly, but backward compat since this was the way it was built and some # things might rely on calling app.daemonize() before app.run() is called if '--daemon' in app.argv or \ - hasattr(app, 'pargs') and app.pargs.daemon is True: + hasattr(app, 'pargs') and app.pargs.daemon is True: CEMENT_DAEMON_ENV.daemonize() diff --git a/cement/ext/ext_handlebars.py b/cement/ext/ext_handlebars.py index 663b3d40..e922cb3a 100644 --- a/cement/ext/ext_handlebars.py +++ b/cement/ext/ext_handlebars.py @@ -160,6 +160,8 @@ original_prepare = pybars._compiler.prepare def my_prepare(value, escape): return original_prepare(value, False) + + pybars._compiler.prepare = my_prepare from pybars import Compiler # noqa diff --git a/cement/utils/fs.py b/cement/utils/fs.py index a96a52a0..b41f4eac 100644 --- a/cement/utils/fs.py +++ b/cement/utils/fs.py @@ -48,6 +48,7 @@ def backup(path, suffix='.bak'): break return new_path + # Kinda dirty, but should resolve issues on Windows per #183 if 'HOME' in os.environ: HOME_DIR = abspath(os.environ['HOME']) diff --git a/scripts/devtools.py b/scripts/devtools.py index d5578d54..e4a177b0 100755 --- a/scripts/devtools.py +++ b/scripts/devtools.py @@ -78,7 +78,7 @@ class CementDevtoolsController(ArgparseController): def _do_flake8(self): print("Checking Flake8 Compliance (pep8, pycodestyle, mccabe, etc)") - cmd_args = ['flake8', 'cement/'] + cmd_args = ['flake8', 'cement/ tests/'] out, err, res = shell.exec_cmd(cmd_args) if res > 0: self._do_error("\n\nFlake8 checks did not pass.\n\n" + diff --git a/tests/core/backend_tests.py b/tests/core/backend_tests.py index 4410657a..0b336732 100644 --- a/tests/core/backend_tests.py +++ b/tests/core/backend_tests.py @@ -1,3 +1,3 @@ """Tests for cement.core.backend.""" -from cement.core import backend \ No newline at end of file +# from cement.core import backend diff --git a/tests/core/cache_tests.py b/tests/core/cache_tests.py index 1cf4668b..597cd2c3 100644 --- a/tests/core/cache_tests.py +++ b/tests/core/cache_tests.py @@ -1,6 +1,6 @@ """Tests for cement.core.cache.""" -from cement.core import exc, cache +from cement.core import cache from cement.utils import test diff --git a/tests/core/config_tests.py b/tests/core/config_tests.py index 306fce0f..fdc6377c 100644 --- a/tests/core/config_tests.py +++ b/tests/core/config_tests.py @@ -1,7 +1,6 @@ """Tests for cement.core.config.""" -import os -from cement.core import exc, config, backend +from cement.core import exc, config from cement.utils import test CONFIG = """ diff --git a/tests/core/controller_tests.py b/tests/core/controller_tests.py index 61eff8f7..fe6895ce 100644 --- a/tests/core/controller_tests.py +++ b/tests/core/controller_tests.py @@ -324,7 +324,7 @@ class ControllerTestCase(test.CementCoreTestCase): ], ) with self.app as app: - res = app.run() + app.run() except exc.InterfaceError as e: self.ok(re.match("(.*)is not stacked anywhere!(.*)", e.msg)) raise @@ -340,7 +340,7 @@ class ControllerTestCase(test.CementCoreTestCase): ], ) with self.app as app: - res = app.run() + app.run() except exc.InterfaceError as e: self.ok(re.match("(.*)has an unknown stacked type(.*)", e.msg)) raise @@ -368,6 +368,6 @@ class ControllerTestCase(test.CementCoreTestCase): ) with self.app as app: app.run() - help = app.controller._help_text + app.controller._help_text # self.ok(usage.startswith('%s (sub-commands ...)' % \ # self.app._meta.label)) diff --git a/tests/core/extension_tests.py b/tests/core/extension_tests.py index c1a287dc..150b1e19 100644 --- a/tests/core/extension_tests.py +++ b/tests/core/extension_tests.py @@ -1,6 +1,6 @@ """Tests for cement.core.extension.""" -from cement.core import exc, backend, extension, output, interface +from cement.core import exc, extension, interface from cement.utils import test diff --git a/tests/core/foundation_tests.py b/tests/core/foundation_tests.py index cf80503c..1c6b4a5e 100644 --- a/tests/core/foundation_tests.py +++ b/tests/core/foundation_tests.py @@ -4,16 +4,13 @@ import os import sys import json import signal -from time import sleep -from cement.core import foundation, exc, backend, config, extension, plugin +from cement.core import foundation, exc, extension from cement.core.handler import CementBaseHandler from cement.core.controller import CementBaseController, expose -from cement.core import log, output, hook, arg, controller +from cement.core import output, hook, controller from cement.core.interface import Interface from cement.utils import test -from cement.core.exc import CaughtSignal from cement.utils.misc import init_defaults, rando, minimal_logger -from nose.plugins.attrib import attr APP = rando()[:12] @@ -153,16 +150,17 @@ class FoundationTestCase(test.CementCoreTestCase): # forces CementApp._resolve_handler to register the handler from cement.ext import ext_json - app = self.make_app('my-app-test', - config_handler=ext_configparser.ConfigParserConfigHandler, - log_handler=ext_logging.LoggingLogHandler(), - arg_handler=ext_argparse.ArgParseArgumentHandler(), - extension_handler=extension.CementExtensionHandler(), - plugin_handler=ext_plugin.CementPluginHandler(), - output_handler=ext_json.JsonOutputHandler(), - mail_handler=ext_dummy.DummyMailHandler(), - argv=[__file__, '--debug'] - ) + app = self.make_app( + 'my-app-test', + config_handler=ext_configparser.ConfigParserConfigHandler, + log_handler=ext_logging.LoggingLogHandler(), + arg_handler=ext_argparse.ArgParseArgumentHandler(), + extension_handler=extension.CementExtensionHandler(), + plugin_handler=ext_plugin.CementPluginHandler(), + output_handler=ext_json.JsonOutputHandler(), + mail_handler=ext_dummy.DummyMailHandler(), + argv=[__file__, '--debug'] + ) app.setup() @@ -226,7 +224,7 @@ class FoundationTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_bad_label(self): try: - app = foundation.CementApp(None) + foundation.CementApp(None) except exc.FrameworkError as e: # FIX ME: verify error msg raise @@ -234,7 +232,7 @@ class FoundationTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_bad_label_chars(self): try: - app = foundation.CementApp('some!bogus()label') + foundation.CementApp('some!bogus()label') except exc.FrameworkError as e: self.ok(e.msg.find('alpha-numeric')) raise @@ -254,7 +252,7 @@ class FoundationTestCase(test.CementCoreTestCase): app._setup_output_handler() def test_lay_cement(self): - app = self.make_app('test', argv=['--quiet']) + self.make_app('test', argv=['--quiet']) def test_none_member(self): class Test(object): @@ -433,12 +431,12 @@ class FoundationTestCase(test.CementCoreTestCase): def my_custom_hook_func(): raise HookTestException('OK') - app = self.make_app(APP, - extensions=['watchdog'], - hooks=[ - ('watchdog_pre_start', my_custom_hook_func) - ] - ) + app = self.make_app(APP, + extensions=['watchdog'], + hooks=[ + ('watchdog_pre_start', my_custom_hook_func) + ] + ) app.setup() self.eq(len(app.hook.__hooks__['watchdog_pre_start']), 1) @@ -453,18 +451,18 @@ class FoundationTestCase(test.CementCoreTestCase): handlers=[MyTestHandler], ) app.setup() - self.ok(app.handler.registered('my_test_interface', + self.ok(app.handler.registered('my_test_interface', 'my_test_handler')) def test_disable_backend_globals(self): - app = self.make_app(APP, - use_backend_globals=False, - define_handlers=[MyTestInterface], - handlers=[MyTestHandler], - define_hooks=['my_hook'], - ) + app = self.make_app(APP, + use_backend_globals=False, + define_handlers=[MyTestInterface], + handlers=[MyTestHandler], + define_hooks=['my_hook'], + ) app.setup() - self.ok(app.handler.registered('my_test_interface', + self.ok(app.handler.registered('my_test_interface', 'my_test_handler')) self.ok(app.hook.defined('my_hook')) @@ -508,11 +506,11 @@ class FoundationTestCase(test.CementCoreTestCase): self.eq(e.args[0], 'It ran forever!') raise finally: - signal.alarm(0) + signal.alarm(0) def test_add_template_directory(self): self.app.setup() - + self.app.add_template_dir(self.tmp_dir) res = self.tmp_dir in self.app._meta.template_dirs self.ok(res) @@ -544,4 +542,3 @@ class FoundationTestCase(test.CementCoreTestCase): app = self.make_app(meta_defaults=META) app.setup() self.eq(app.log._meta.debug_format, DEBUG_FORMAT) - diff --git a/tests/core/handler_tests.py b/tests/core/handler_tests.py index 67f62deb..436869cc 100644 --- a/tests/core/handler_tests.py +++ b/tests/core/handler_tests.py @@ -10,7 +10,7 @@ from cement.ext.ext_configparser import ConfigParserConfigHandler class BogusOutputHandler(meta.MetaMixin): class Meta: - #interface = IBogus + # interface = IBogus label = 'bogus_handler' @@ -138,7 +138,8 @@ class HandlerTestCase(test.CementCoreTestCase): self.app.setup() self.ok(self.app.handler.registered('output', 'dummy')) self.eq(self.app.handler.registered('output', 'bogus_handler'), False) - self.eq(self.app.handler.registered('bogus_type', 'bogus_handler'), False) + self.eq(self.app.handler.registered('bogus_type', + 'bogus_handler'), False) @test.raises(exc.FrameworkError) def test_get_bogus_handler(self): @@ -165,7 +166,7 @@ class HandlerTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_handler_list_bogus_type(self): self.app.setup() - handler_list = self.app.handler.list('bogus') + self.app.handler.list('bogus') def is_defined(handler_type): self.eq(self.app.handler.defined(handler_type), True) @@ -204,9 +205,11 @@ class HandlerTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_register_invalid_handler_type(self): self.app.setup() + class BadInterface: class IMeta: label = 'bad_interface' + class BadHandler(TestHandler): class Meta: interface = BadInterface @@ -283,14 +286,16 @@ class DeprecatedHandlerTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_handler_list_bogus_type(self): self.app.setup() - handler_list = handler.list('bogus') + handler.list('bogus') @test.raises(exc.FrameworkError) def test_register_invalid_handler_type(self): self.app.setup() + class BadInterface: class IMeta: label = 'bad_interface' + class BadHandler(TestHandler): class Meta: interface = BadInterface diff --git a/tests/core/hook_tests.py b/tests/core/hook_tests.py index 544bf755..ebff4195 100644 --- a/tests/core/hook_tests.py +++ b/tests/core/hook_tests.py @@ -55,7 +55,9 @@ class HookTestCase(test.CementCoreTestCase): def test_hooks_registered(self): self.app.hook.register('nosetests_hook', cement_hook_one, weight=99) self.app.hook.register('nosetests_hook', cement_hook_two, weight=-1) - self.app.hook.register('some_bogus_hook', cement_hook_three, weight=-99) + self.app.hook.register('some_bogus_hook', + cement_hook_three, + weight=-99) self.eq(len(self.app.hook.__hooks__['nosetests_hook']), 2) def test_run(self): @@ -111,6 +113,7 @@ class HookTestCase(test.CementCoreTestCase): except exc.CaughtSignal as e: pass + class DeprecatedHookTestCase(test.CementCoreTestCase): def setUp(self): diff --git a/tests/core/interface_tests.py b/tests/core/interface_tests.py index e74f5f75..c3f2ecb6 100644 --- a/tests/core/interface_tests.py +++ b/tests/core/interface_tests.py @@ -1,6 +1,6 @@ """Tests for cement.core.interface.""" -from cement.core import exc, interface, output, meta +from cement.core import exc, interface, output from cement.core.handler import CementBaseHandler from cement.utils import test @@ -38,7 +38,7 @@ class InterfaceTestCase(test.CementCoreTestCase): @test.raises(exc.InterfaceError) def test_interface_class(self): try: - i = interface.Interface() + interface.Interface() except exc.InterfaceError as e: self.eq(e.msg, "Interfaces can not be used directly.") raise @@ -75,7 +75,8 @@ class InterfaceTestCase(test.CementCoreTestCase): interface.validate(TestInterface, han, [], ['missing_meta']) except exc.InterfaceError as e: self.eq( - e.msg, "Invalid or missing: ['_meta.missing_meta'] in %s" % han) + e.msg, + "Invalid or missing: ['_meta.missing_meta'] in %s" % han) raise def test_interface_list(self): diff --git a/tests/core/log_tests.py b/tests/core/log_tests.py index 053d5908..8254d0e6 100644 --- a/tests/core/log_tests.py +++ b/tests/core/log_tests.py @@ -1,7 +1,6 @@ """Tests for cement.core.log.""" -import logging -from cement.core import exc, backend, log +from cement.core import exc, log from cement.utils import test from cement.utils.misc import init_defaults diff --git a/tests/core/meta_tests.py b/tests/core/meta_tests.py index 0f88c516..62aa9c94 100644 --- a/tests/core/meta_tests.py +++ b/tests/core/meta_tests.py @@ -1,6 +1,6 @@ """Cement meta tests.""" -from cement.core import backend, exc, meta +from cement.core import meta from cement.utils import test diff --git a/tests/core/output_tests.py b/tests/core/output_tests.py index 1e83ef33..1f76cd6a 100644 --- a/tests/core/output_tests.py +++ b/tests/core/output_tests.py @@ -1,9 +1,9 @@ """Tests for cement.core.output.""" import os -from cement.core import exc, backend, output +from cement.core import exc, output from cement.utils import test -from cement.utils.misc import init_defaults, rando +from cement.utils.misc import rando APP = rando()[:12] @@ -17,6 +17,7 @@ class TestOutputHandler(output.TemplateOutputHandler): content = self.load_template(template) return content % data + TEST_TEMPLATE = "%(foo)s" @@ -44,7 +45,7 @@ class OutputTestCase(test.CementCoreTestCase): @test.raises(exc.FrameworkError) def test_load_template_from_bad_file(self): - template = os.path.join(self.tmp_dir, 'my-bogus-template.txt') + os.path.join(self.tmp_dir, 'my-bogus-template.txt') app = self.make_app(APP, config_files=[], diff --git a/tests/core/plugin_tests.py b/tests/core/plugin_tests.py index 96c2720b..15c0cff7 100644 --- a/tests/core/plugin_tests.py +++ b/tests/core/plugin_tests.py @@ -3,7 +3,7 @@ import os import sys import shutil -from cement.core import exc, backend, plugin +from cement.core import exc from cement.utils import test from cement.utils.misc import init_defaults, rando diff --git a/tests/ext/alarm_tests.py b/tests/ext/alarm_tests.py index eaa74e5f..054528ed 100644 --- a/tests/ext/alarm_tests.py +++ b/tests/ext/alarm_tests.py @@ -1,6 +1,5 @@ """Tests for cement.ext.ext_alarm.""" -import sys import time import signal from cement.core.exc import CaughtSignal @@ -33,4 +32,3 @@ class AlarmExtTestCase(test.CementExtTestCase): app.alarm.set(3, "The Timer Works!") time.sleep(1) app.alarm.stop() - \ No newline at end of file diff --git a/tests/ext/argcomplete_tests.py b/tests/ext/argcomplete_tests.py index e49279dc..4ad474f7 100644 --- a/tests/ext/argcomplete_tests.py +++ b/tests/ext/argcomplete_tests.py @@ -1,13 +1,12 @@ """Tests for cement.ext.ext_argcomplete.""" -import os -from cement.ext import ext_argcomplete from cement.ext.ext_argparse import ArgparseController, expose from cement.utils import test from cement.utils.misc import rando APP = rando()[:12] + class MyBaseController(ArgparseController): class Meta: label = 'base' @@ -16,18 +15,19 @@ class MyBaseController(ArgparseController): def default(self): pass + class ArgcompleteExtTestCase(test.CementExtTestCase): def setUp(self): super(ArgcompleteExtTestCase, self).setUp() - self.app = self.make_app(APP, - argv=['default'], - base_controller=MyBaseController, - extensions=[ - 'argparse', - 'argcomplete' - ], - ) + self.app = self.make_app(APP, + argv=['default'], + base_controller=MyBaseController, + extensions=[ + 'argparse', + 'argcomplete' + ], + ) def test_argcomplete(self): # not really sure how to test this for reals... but let's atleast get diff --git a/tests/ext/argparse_tests.py b/tests/ext/argparse_tests.py index 1b227a42..cbb42a2f 100644 --- a/tests/ext/argparse_tests.py +++ b/tests/ext/argparse_tests.py @@ -1,6 +1,5 @@ """Tests for cement.ext.ext_argparse.""" -import os import sys import re from argparse import ArgumentError @@ -8,8 +7,7 @@ from cement.ext.ext_argparse import ArgparseArgumentHandler from cement.ext.ext_argparse import ArgparseController, expose from cement.ext.ext_argparse import _clean_label, _clean_func from cement.utils import test -from cement.utils.misc import rando, init_defaults -from cement.core import handler +from cement.utils.misc import rando from cement.core.exc import InterfaceError, FrameworkError APP = rando()[:12] @@ -286,7 +284,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): res = app.run() self.eq(res, "Inside Second.cmd2") self.tearDown() - + self.setUp() with self.app as app: app._meta.argv = ['third', 'cmd3'] @@ -321,7 +319,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): res = app.run() self.eq(res, "Inside Seventh.cmd7") self.tearDown() - + def test_base_cmd1_parsing(self): with self.app as app: app._meta.argv = ['--foo=bar', 'cmd1'] @@ -398,9 +396,9 @@ class ArgparseExtTestCase(test.CementExtTestCase): def test_collect(self): with self.app as app: - args = self.app.controller._collect_arguments() - cmds = self.app.controller._collect_commands() - args2, cmds2 = self.app.controller._collect() + args = app.controller._collect_arguments() + cmds = app.controller._collect_commands() + args2, cmds2 = app.controller._collect() self.eq((args, cmds), (args2, cmds2)) def test_controller_embedded_on_base(self): @@ -512,7 +510,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): ], ) with self.app as app: - res = app.run() + app.run() except InterfaceError as e: self.ok(re.match("(.*)is not stacked anywhere!(.*)", e.msg)) raise @@ -529,7 +527,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): ], ) with self.app as app: - res = app.run() + app.run() except InterfaceError as e: self.ok(re.match("(.*)has an unknown stacked type(.*)", e.msg)) raise @@ -546,7 +544,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): ], ) with self.app as app: - res = app.run() + app.run() except ArgumentError as e: self.ok(re.match("(.*)conflicting option string(.*)", e.__str__())) @@ -564,7 +562,7 @@ class ArgparseExtTestCase(test.CementExtTestCase): ], ) with self.app as app: - res = app.run() + app.run() except ArgumentError as e: self.ok(re.match("(.*)conflicting option string(.*)", e.__str__())) diff --git a/tests/ext/colorlog_tests.py b/tests/ext/colorlog_tests.py index a1534a4c..c3a7b2d2 100644 --- a/tests/ext/colorlog_tests.py +++ b/tests/ext/colorlog_tests.py @@ -2,7 +2,7 @@ import os import logging -from cement.ext.ext_colorlog import ColorLogHandler, ColoredFormatter +from cement.ext.ext_colorlog import ColoredFormatter from cement.utils import test from cement.utils.misc import rando, init_defaults diff --git a/tests/ext/configobj_tests.py b/tests/ext/configobj_tests.py index f9d70d81..5c666aa9 100644 --- a/tests/ext/configobj_tests.py +++ b/tests/ext/configobj_tests.py @@ -1,8 +1,5 @@ """Tests for cement.ext.ext_configobj.""" -import os -import sys -from cement.core import handler, backend, log from cement.utils import test from cement.utils.misc import rando diff --git a/tests/ext/configparser_tests.py b/tests/ext/configparser_tests.py index 511f83ab..ebc10143 100644 --- a/tests/ext/configparser_tests.py +++ b/tests/ext/configparser_tests.py @@ -1,6 +1,5 @@ from cement.utils import test -from cement.utils.misc import init_defaults @test.attr('core') diff --git a/tests/ext/daemon_tests.py b/tests/ext/daemon_tests.py index 0c3e7e7f..c0e725e4 100644 --- a/tests/ext/daemon_tests.py +++ b/tests/ext/daemon_tests.py @@ -5,10 +5,8 @@ # sub-process is forked. import os -#import tempfile from random import random -from cement.core import handler, backend, log, hook, exc -from cement.utils import shell +from cement.core import exc from cement.utils import test from cement.utils.misc import rando from cement.ext import ext_daemon diff --git a/tests/ext/genshi_tests.py b/tests/ext/genshi_tests.py index 7c15a149..5de0c4f7 100644 --- a/tests/ext/genshi_tests.py +++ b/tests/ext/genshi_tests.py @@ -3,11 +3,11 @@ import sys import random -from cement.core import exc, foundation, handler, backend, controller +from cement.core import exc from cement.utils import test if sys.version_info[0] < 3: - import configobj + import configobj # NOQA else: raise test.SkipTest('Genshi does not support Python 3') # pragma: no cover @@ -32,18 +32,18 @@ class GenshiExtTestCase(test.CementExtTestCase): @test.raises(exc.FrameworkError) def test_genshi_bad_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'bad_template2.genshi') + self.app.render(dict(foo='bar'), 'bad_template2.genshi') @test.raises(exc.FrameworkError) def test_genshi_nonexistent_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'missing_template.genshi') + self.app.render(dict(foo='bar'), 'missing_template.genshi') @test.raises(exc.FrameworkError) def test_genshi_none_template(self): self.app.setup() try: - res = self.app.render(dict(foo='bar'), None) + self.app.render(dict(foo='bar'), None) except exc.FrameworkError as e: self.eq(e.msg, "Invalid template path 'None'.") raise @@ -52,4 +52,4 @@ class GenshiExtTestCase(test.CementExtTestCase): def test_genshi_bad_module(self): self.app.setup() self.app._meta.template_module = 'this_is_a_bogus_module' - res = self.app.render(dict(foo='bar'), 'bad_template.genshi') + self.app.render(dict(foo='bar'), 'bad_template.genshi') diff --git a/tests/ext/handlebars_tests.py b/tests/ext/handlebars_tests.py index 91779cd4..a4a7f7d4 100644 --- a/tests/ext/handlebars_tests.py +++ b/tests/ext/handlebars_tests.py @@ -1,11 +1,11 @@ """Tests for cement.ext.ext_handlebars.""" -import sys import random -from cement.core import exc, foundation, handler, backend, controller +from cement.core import exc from cement.utils import test from nose.plugins.attrib import attr + class HandlebarsTestApp(test.TestApp): class Meta: extensions = ['handlebars'] @@ -14,8 +14,9 @@ class HandlebarsTestApp(test.TestApp): template_dirs = [] handlebars_helpers = {} handlebars_partials = ['test_partial_template.handlebars'] - -@attr('ext_handlebars') + + +@attr('ext_handlebars') class HandlebarsExtTestCase(test.CementExtTestCase): app_class = HandlebarsTestApp @@ -38,18 +39,18 @@ class HandlebarsExtTestCase(test.CementExtTestCase): @test.raises(exc.FrameworkError) def test_handlebars_bad_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'bad_template2.handlebars') + self.app.render(dict(foo='bar'), 'bad_template2.handlebars') @test.raises(exc.FrameworkError) def test_handlebars_nonexistent_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'missing_template.handlebars') + self.app.render(dict(foo='bar'), 'missing_template.handlebars') @test.raises(exc.FrameworkError) def test_handlebars_none_template(self): self.app.setup() try: - res = self.app.render(dict(foo='bar'), None) + self.app.render(dict(foo='bar'), None) except exc.FrameworkError as e: self.eq(e.msg, "Invalid template path 'None'.") raise @@ -58,4 +59,4 @@ class HandlebarsExtTestCase(test.CementExtTestCase): def test_handlebars_bad_module(self): self.app.setup() self.app._meta.template_module = 'this_is_a_bogus_module' - res = self.app.render(dict(foo='bar'), 'bad_template.handlebars') + self.app.render(dict(foo='bar'), 'bad_template.handlebars') diff --git a/tests/ext/jinja2_tests.py b/tests/ext/jinja2_tests.py index 7696e4fa..8463da60 100644 --- a/tests/ext/jinja2_tests.py +++ b/tests/ext/jinja2_tests.py @@ -2,11 +2,10 @@ """Tests for cement.ext.ext_jinja2.""" import os -import sys import random -from shutil import copyfile, rmtree +from shutil import copyfile -from cement.core import exc, foundation, handler, backend, controller +from cement.core import exc from cement.utils import test @@ -43,12 +42,12 @@ class Jinja2ExtTestCase(test.CementExtTestCase): tests_dir = os.path.dirname(os.path.dirname(__file__)) - from_file = os.path.join(tests_dir, 'templates', + from_file = os.path.join(tests_dir, 'templates', 'test_template_parent.jinja2') to_file = os.path.join(self.tmp_dir, 'test_template_parent.jinja2') copyfile(from_file, to_file) - from_file = os.path.join(tests_dir, 'templates', + from_file = os.path.join(tests_dir, 'templates', 'test_template_child.jinja2') to_file = os.path.join(self.tmp_dir, 'test_template_child.jinja2') copyfile(from_file, to_file) @@ -70,18 +69,18 @@ class Jinja2ExtTestCase(test.CementExtTestCase): @test.raises(exc.FrameworkError) def test_jinja2_bad_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'bad_template2.jinja2') + self.app.render(dict(foo='bar'), 'bad_template2.jinja2') @test.raises(exc.FrameworkError) def test_jinja2_nonexistent_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'missing_template.jinja2') + self.app.render(dict(foo='bar'), 'missing_template.jinja2') @test.raises(exc.FrameworkError) def test_jinja2_none_template(self): self.app.setup() try: - res = self.app.render(dict(foo='bar'), None) + self.app.render(dict(foo='bar'), None) except exc.FrameworkError as e: self.eq(e.msg, "Invalid template path 'None'.") raise @@ -90,4 +89,4 @@ class Jinja2ExtTestCase(test.CementExtTestCase): def test_jinja2_bad_module(self): self.app.setup() self.app._meta.template_module = 'this_is_a_bogus_module' - res = self.app.render(dict(foo='bar'), 'bad_template.jinja2') + self.app.render(dict(foo='bar'), 'bad_template.jinja2') diff --git a/tests/ext/json_configobj_tests.py b/tests/ext/json_configobj_tests.py index 371d71bb..287f7061 100644 --- a/tests/ext/json_configobj_tests.py +++ b/tests/ext/json_configobj_tests.py @@ -1,8 +1,5 @@ """Tests for cement.ext.ext_json_configobj.""" -import json -import sys -from cement.core import handler, backend, hook from cement.utils import test diff --git a/tests/ext/json_tests.py b/tests/ext/json_tests.py index 42e0607e..ebb90cf3 100644 --- a/tests/ext/json_tests.py +++ b/tests/ext/json_tests.py @@ -1,8 +1,6 @@ """Tests for cement.ext.ext_json.""" import json -import sys -from cement.core import handler, backend, hook from cement.utils import test from cement.utils.misc import rando diff --git a/tests/ext/logging_tests.py b/tests/ext/logging_tests.py index ff37136a..660170cd 100644 --- a/tests/ext/logging_tests.py +++ b/tests/ext/logging_tests.py @@ -1,9 +1,8 @@ """Tests for cement.ext.ext_logging.""" import os -import logging import shutil -from cement.core import handler, backend, log +from cement.core import handler from cement.ext import ext_logging from cement.utils import test from cement.utils.misc import init_defaults, rando @@ -73,7 +72,6 @@ class LoggingExtTestCase(test.CementExtTestCase): Log = han() Log.clear_loggers(self.app._meta.label) - #previous_logger = logging.getLogger(name) MyLog = ext_logging.LoggingLogHandler(clear_loggers="%s:%s" % (self.app._meta.label, self.app._meta.label)) diff --git a/tests/ext/memcached_tests.py b/tests/ext/memcached_tests.py index a8d4458f..05a868bf 100644 --- a/tests/ext/memcached_tests.py +++ b/tests/ext/memcached_tests.py @@ -1,10 +1,7 @@ """Tests for cement.ext.ext_memcached.""" -import sys -import pylibmc from time import sleep from random import random -from cement.core import handler from cement.utils import test from cement.utils.misc import init_defaults diff --git a/tests/ext/mustache_tests.py b/tests/ext/mustache_tests.py index 49534dcc..3e57abba 100644 --- a/tests/ext/mustache_tests.py +++ b/tests/ext/mustache_tests.py @@ -1,9 +1,8 @@ """Tests for cement.ext.ext_mustache.""" -import sys import random -from cement.core import exc, foundation, handler, backend, controller +from cement.core import exc from cement.utils import test @@ -34,18 +33,18 @@ class MustacheExtTestCase(test.CementExtTestCase): @test.raises(exc.FrameworkError) def test_mustache_bad_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'bad_template2.mustache') + self.app.render(dict(foo='bar'), 'bad_template2.mustache') @test.raises(exc.FrameworkError) def test_mustache_nonexistent_template(self): self.app.setup() - res = self.app.render(dict(foo='bar'), 'missing_template.mustache') + self.app.render(dict(foo='bar'), 'missing_template.mustache') @test.raises(exc.FrameworkError) def test_mustache_none_template(self): self.app.setup() try: - res = self.app.render(dict(foo='bar'), None) + self.app.render(dict(foo='bar'), None) except exc.FrameworkError as e: self.eq(e.msg, "Invalid template path 'None'.") raise @@ -54,4 +53,4 @@ class MustacheExtTestCase(test.CementExtTestCase): def test_mustache_bad_module(self): self.app.setup() self.app._meta.template_module = 'this_is_a_bogus_module' - res = self.app.render(dict(foo='bar'), 'bad_template.mustache') + self.app.render(dict(foo='bar'), 'bad_template.mustache') diff --git a/tests/ext/redis_tests.py b/tests/ext/redis_tests.py index 6fea662f..95e1eb6f 100644 --- a/tests/ext/redis_tests.py +++ b/tests/ext/redis_tests.py @@ -1,10 +1,7 @@ """Tests for cement.ext.ext_redis.""" -import sys -import redis from time import sleep from random import random -from cement.core import handler from cement.utils import test from cement.utils.misc import init_defaults diff --git a/tests/ext/reload_config_tests.py b/tests/ext/reload_config_tests.py index e48313db..da249a6f 100644 --- a/tests/ext/reload_config_tests.py +++ b/tests/ext/reload_config_tests.py @@ -1,18 +1,17 @@ """Tests for cement.ext.ext_reload_config.""" - import platform from cement.utils import test - -system = platform.system() -if not system in ['Linux']: - raise test.SkipTest('ext_reload_config not supported on %s' % system) - import os import shutil import signal from time import sleep from cement.utils.misc import rando -from cement.ext import ext_reload_config + +system = platform.system() +if system not in ['Linux']: + raise test.SkipTest('ext_reload_config not supported on %s' % system) + +from cement.ext import ext_reload_config # NOQA - Run only if Linux APP = rando()[:12] diff --git a/tests/ext/smtp_tests.py b/tests/ext/smtp_tests.py index bc618605..94e46138 100644 --- a/tests/ext/smtp_tests.py +++ b/tests/ext/smtp_tests.py @@ -2,7 +2,6 @@ import mock import sys -import smtplib from cement.utils import test from cement.utils.misc import rando, init_defaults @@ -98,9 +97,8 @@ class SMTPMailHandlerTestCase(test.CementTestCase): instance = mock_smtp.return_value self.eq(instance.login.call_count, 1) - + if int(sys.version[0]) >= 3: self.eq(instance.send_message.call_count, 1) else: self.eq(instance.sendmail.call_count, 1) - diff --git a/tests/ext/tabulate_tests.py b/tests/ext/tabulate_tests.py index 8e415716..6371265a 100644 --- a/tests/ext/tabulate_tests.py +++ b/tests/ext/tabulate_tests.py @@ -1,7 +1,5 @@ """Tests for cement.ext.ext_tabulate.""" -import re -import random from cement.utils import test @@ -17,6 +15,5 @@ class TabulateExtTestCase(test.CementExtTestCase): def test_tabulate(self): self.app.setup() - rando = random.random() res = self.app.render([['John', 'Doe']], headers=['FOO', 'BAR']) self.ok(res.find('FOO')) diff --git a/tests/ext/watchdog_tests.py b/tests/ext/watchdog_tests.py index e76edcf9..99cadb99 100644 --- a/tests/ext/watchdog_tests.py +++ b/tests/ext/watchdog_tests.py @@ -9,6 +9,7 @@ from cement.ext.ext_watchdog import WatchdogEventHandler class MyEventHandler(WatchdogEventHandler): pass + class WatchdogExtTestCase(test.CementExtTestCase): def setUp(self): @@ -47,7 +48,7 @@ class WatchdogExtTestCase(test.CementExtTestCase): f = open(os.path.join(self.tmp_dir, 'test.file'), 'w') f.write('test data') f.close() - + self.app.close() @test.raises(FrameworkError) @@ -75,7 +76,7 @@ class WatchdogExtTestCase(test.CementExtTestCase): self.app.close() def test_watchdog_hooks(self): - # FIX ME: this is only coverage... + # FIX ME: this is only coverage... def test_hook(app): app.counter += 1 diff --git a/tests/ext/yaml_configobj_tests.py b/tests/ext/yaml_configobj_tests.py index f5daf6d8..d1e1816e 100644 --- a/tests/ext/yaml_configobj_tests.py +++ b/tests/ext/yaml_configobj_tests.py @@ -1,9 +1,5 @@ """Tests for cement.ext.ext_yaml_configobj.""" -import os -import sys -import yaml -from cement.core import handler, hook from cement.utils import test diff --git a/tests/ext/yaml_tests.py b/tests/ext/yaml_tests.py index ecbf68b1..ba5829ea 100644 --- a/tests/ext/yaml_tests.py +++ b/tests/ext/yaml_tests.py @@ -1,9 +1,6 @@ """Tests for cement.ext.ext_yaml.""" -import os -import sys import yaml -from cement.core import handler, hook from cement.utils import test from cement.utils.misc import rando diff --git a/tests/utils/fs_tests.py b/tests/utils/fs_tests.py index 848ab2d6..76015e45 100644 --- a/tests/utils/fs_tests.py +++ b/tests/utils/fs_tests.py @@ -1,7 +1,6 @@ """Tests for cement.utils.fs""" import os -import shutil from cement.utils import fs, test @@ -18,8 +17,8 @@ class FsUtilsTestCase(test.CementCoreTestCase): os.makedirs(tmp_dir) bkfile = fs.backup(tmp_file) - self.eq("%s.bak" % os.path.basename(tmp_file), - os.path.basename(bkfile)) + self.eq("%s.bak" % os.path.basename(tmp_file), + os.path.basename(bkfile)) bkfile = fs.backup(tmp_file) self.eq("%s.bak.0" % os.path.basename(tmp_file), os.path.basename(bkfile)) @@ -28,8 +27,8 @@ class FsUtilsTestCase(test.CementCoreTestCase): os.path.basename(tmp_file), os.path.basename(bkfile)) bkdir = fs.backup(tmp_dir) - self.eq("%s.bak" % os.path.basename(tmp_dir), - os.path.basename(bkdir)) + self.eq("%s.bak" % os.path.basename(tmp_dir), + os.path.basename(bkdir)) res = fs.backup('someboguspath') self.eq(res, None) diff --git a/tests/utils/misc_tests.py b/tests/utils/misc_tests.py index d8d5563c..d149a3ee 100644 --- a/tests/utils/misc_tests.py +++ b/tests/utils/misc_tests.py @@ -69,9 +69,9 @@ class BackendTestCase(test.CementCoreTestCase): def test_wrap_int(self): text = int('1' * 80) try: - new_text = misc.wrap(text, width=5) + misc.wrap(text, width=5) except TypeError as e: - self.eq(e.args[0], + self.eq(e.args[0], "Argument `text` must be one of [str, unicode].") raise @@ -79,8 +79,8 @@ class BackendTestCase(test.CementCoreTestCase): def test_wrap_none(self): text = None try: - new_text = misc.wrap(text, width=5) + misc.wrap(text, width=5) except TypeError as e: - self.eq(e.args[0], + self.eq(e.args[0], "Argument `text` must be one of [str, unicode].") raise diff --git a/tests/utils/shell_tests.py b/tests/utils/shell_tests.py index 6e810ed2..d74893b8 100644 --- a/tests/utils/shell_tests.py +++ b/tests/utils/shell_tests.py @@ -127,10 +127,10 @@ class ShellUtilsTestCase(test.CementCoreTestCase): # test that self.input is none if no default, and no input with mock.patch(INPUT, return_value=''): try: - p = shell.Prompt('Test Prompt', - max_attempts=3, - max_attempts_exception=True, - ) + shell.Prompt('Test Prompt', + max_attempts=3, + max_attempts_exception=True, + ) except FrameworkError as e: self.eq(e.msg, "Maximum attempts exceeded getting valid user input",