From 4a62ffc23e4d7fa411a45b0ed1ab69331163f6ce Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 22 Aug 2016 12:41:54 -0700 Subject: [PATCH] Run flake8 w/ 'E4', fix imports/unused vars --- fabfile.py | 2 +- fabric/api.py | 1 + fabric/context_managers.py | 2 +- fabric/contrib/files.py | 2 +- fabric/state.py | 4 ++-- integration/test_contrib.py | 2 -- integration/test_operations.py | 6 +++--- integration/utils.py | 2 -- setup.cfg | 2 ++ tests/mock_streams.py | 2 +- tests/test_main.py | 2 -- tests/test_operations.py | 1 - tests/test_server.py | 3 ++- tests/test_tasks.py | 10 +++++----- tests/test_utils.py | 9 ++++----- 15 files changed, 23 insertions(+), 27 deletions(-) create mode 100644 setup.cfg diff --git a/fabfile.py b/fabfile.py index 576c4855..487b402d 100644 --- a/fabfile.py +++ b/fabfile.py @@ -6,7 +6,7 @@ import nose -from fabric.api import abort, local, task +from fabric.api import task @task(default=True) diff --git a/fabric/api.py b/fabric/api.py index 65526133..95fe2ff0 100644 --- a/fabric/api.py +++ b/fabric/api.py @@ -6,6 +6,7 @@ setup.py -- without triggering loads of most of the code. Which doesn't work so well when you're using setup.py to install e.g. ssh! """ + from fabric.context_managers import (cd, hide, settings, show, path, prefix, lcd, quiet, warn_only, remote_tunnel, shell_env) from fabric.decorators import (hosts, roles, runs_once, with_settings, task, diff --git a/fabric/context_managers.py b/fabric/context_managers.py index 77833500..dd94cb20 100644 --- a/fabric/context_managers.py +++ b/fabric/context_managers.py @@ -539,7 +539,7 @@ def accept(channel, (src_addr, src_port), (dest_addr, dest_port)): try: sock.connect((local_host, local_port)) - except Exception, e: + except Exception: print "[%s] rtunnel: cannot connect to %s:%d (from local)" % (env.host_string, local_host, local_port) channel.close() return diff --git a/fabric/contrib/files.py b/fabric/contrib/files.py index db98270e..7a07bade 100644 --- a/fabric/contrib/files.py +++ b/fabric/contrib/files.py @@ -10,7 +10,7 @@ from StringIO import StringIO from functools import partial -from fabric.api import * +from fabric.api import run, sudo, hide, settings, env, put, abort from fabric.utils import apply_lcwd diff --git a/fabric/state.py b/fabric/state.py index 51db1348..9701b636 100644 --- a/fabric/state.py +++ b/fabric/state.py @@ -46,8 +46,8 @@ def _get_system_username(): except ImportError: if win32: import win32api - import win32security - import win32profile + import win32security # noqa + import win32profile # noqa username = win32api.GetUserName() return username diff --git a/integration/test_contrib.py b/integration/test_contrib.py index 147abb74..4638f405 100644 --- a/integration/test_contrib.py +++ b/integration/test_contrib.py @@ -1,7 +1,5 @@ import os -import types import re -import sys from fabric.api import run, local from fabric.contrib import files, project diff --git a/integration/test_operations.py b/integration/test_operations.py index 763ce0cd..c85ed243 100644 --- a/integration/test_operations.py +++ b/integration/test_operations.py @@ -6,7 +6,7 @@ import shutil from fabric.api import ( - run, path, put, sudo, abort, warn_only, env, cd, local, settings, get + run, path, put, sudo, env, cd, local, settings, get ) from fabric.contrib.files import exists @@ -143,7 +143,7 @@ def test_get_with_use_sudo_unowned_file(self): sudo("chmod 0440 %s" % target) # Pull down with use_sudo, confirm contents local_ = StringIO() - result = get( + get( local_path=local_, remote_path=target, use_sudo=True, @@ -165,7 +165,7 @@ def test_get_with_use_sudo_groupowned_file(self): sudo("chmod 0640 %s" % target) # Do eet local_ = StringIO() - result = get( + get( local_path=local_, remote_path=target, use_sudo=True, diff --git a/integration/utils.py b/integration/utils.py index 1e9c50c1..21e74ee9 100644 --- a/integration/utils.py +++ b/integration/utils.py @@ -4,8 +4,6 @@ # Pull in regular tests' utilities mod = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'tests')) sys.path.insert(0, mod) -from mock_streams import mock_streams -#from utils import FabricTest # Clean up del sys.path[0] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..f8c43f5a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[flake8] +exclude = tests/support,tests/Python26SocketServer.py,sites,fabric/api.py diff --git a/tests/mock_streams.py b/tests/mock_streams.py index c1bf11df..a5809045 100644 --- a/tests/mock_streams.py +++ b/tests/mock_streams.py @@ -71,7 +71,7 @@ def inner_wrapper(*args, **kwargs): if stderr: my_stderr, sys.stderr = sys.stderr, fake_stderr try: - ret = func(*args, **kwargs) + func(*args, **kwargs) finally: if stdout: sys.stdout = my_stdout diff --git a/tests/test_main.py b/tests/test_main.py index 1aabff38..b7535547 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -494,7 +494,6 @@ def test_class_based_tasks_are_found_with_proper_name(self): Wrapped new-style tasks should preserve their function names """ module = fabfile('decorated_fabfile_with_classbased_task.py') - from fabric.state import env with path_prefix(module): docs, funcs = load_fabfile(module) eq_(len(funcs), 1) @@ -506,7 +505,6 @@ def test_class_based_tasks_are_found_with_variable_name(self): variable name. """ module = fabfile('classbased_task_fabfile.py') - from fabric.state import env with path_prefix(module): docs, funcs = load_fabfile(module) eq_(len(funcs), 1) diff --git a/tests/test_operations.py b/tests/test_operations.py index 8f474aa1..939d6f11 100644 --- a/tests/test_operations.py +++ b/tests/test_operations.py @@ -22,7 +22,6 @@ from fabric.exceptions import CommandTimeout from fabric.sftp import SFTP -from fabric.context_managers import settings from fabric.decorators import with_settings from utils import (eq_, aborts, assert_contains, eq_contents, with_patched_input, FabricTest) diff --git a/tests/test_server.py b/tests/test_server.py index b8ed93a6..18d27f6b 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -6,7 +6,6 @@ no need to pollute Fab's own test suite. (Yes, if these tests fail, it's likely that the Fabric tests using the test server may also have issues, but still.) """ -__test__ = False from nose.tools import eq_, ok_ @@ -14,6 +13,8 @@ from server import FakeSFTPServer +__test__ = False + class AttrHolder(object): pass diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 218231c4..af5b6258 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -2,7 +2,7 @@ from fudge import Fake, patched_context, with_fakes import unittest -from nose.tools import eq_, raises, ok_ +from nose.tools import raises, ok_ import random import sys @@ -31,7 +31,7 @@ def test_passes_unused_args_to_parent(self): def foo(): pass try: - task = WrappedCallableTask(foo, *args) + WrappedCallableTask(foo, *args) except TypeError: msg = "__init__ raised a TypeError, meaning args weren't handled" self.fail(msg) @@ -42,7 +42,7 @@ def test_passes_unused_kwargs_to_parent(self): def foo(): pass try: - task = WrappedCallableTask(foo, **kwargs) + WrappedCallableTask(foo, **kwargs) except TypeError: self.fail( "__init__ raised a TypeError, meaning kwargs weren't handled") @@ -50,12 +50,12 @@ def foo(): pass def test_allows_any_number_of_args(self): args = [i for i in range(random.randint(0, 10))] def foo(): pass - task = WrappedCallableTask(foo, *args) + WrappedCallableTask(foo, *args) def test_allows_any_number_of_kwargs(self): kwargs = dict([("key%d" % i, i) for i in range(random.randint(0, 10))]) def foo(): pass - task = WrappedCallableTask(foo, **kwargs) + WrappedCallableTask(foo, **kwargs) def test_run_is_wrapped_callable(self): def foo(): pass diff --git a/tests/test_utils.py b/tests/test_utils.py index 91ce0c71..73fc5c07 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -28,19 +28,19 @@ def test_warn(): def test_indent(): - for description, input, output in ( + for description, input_, output_ in ( ("Sanity check: 1 line string", 'Test', ' Test'), ("List of strings turns in to strings joined by \\n", ["Test", "Test"], ' Test\n Test'), ): eq_.description = "indent(): %s" % description - yield eq_, indent(input), output + yield eq_, indent(input_), output_ del eq_.description def test_indent_with_strip(): - for description, input, output in ( + for description, input_ output_ in ( ("Sanity check: 1 line string", indent('Test', strip=True), ' Test'), ("Check list of strings", @@ -50,7 +50,7 @@ def test_indent_with_strip(): ' Test\n Test'), ): eq_.description = "indent(strip=True): %s" % description - yield eq_, input, output + yield eq_, input_ output_ del eq_.description @@ -171,7 +171,6 @@ def test_puts_without_prefix(): puts() shouldn't prefix output with env.host_string if show_prefix is False """ s = "my output" - h = "localhost" puts(s, show_prefix=False) eq_(sys.stdout.getvalue(), "%s" % (s + "\n"))