From da1ddfdb62608f73957886bd02f6480b60ef0ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 6 Oct 2015 14:31:06 +0200 Subject: [PATCH] autopep8 style cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Autopep8 style cleanup + alphabetic import + import cleanup in avocado.core.{loader,test} and selftests.functional.test_basic. Signed-off-by: Lukáš Doktor --- avocado/core/loader.py | 48 +++++++++++++----------------- avocado/core/test.py | 34 +++++++++++---------- selftests/functional/test_basic.py | 29 +++++++++++------- 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/avocado/core/loader.py b/avocado/core/loader.py index 8973b6da..8677e0a4 100644 --- a/avocado/core/loader.py +++ b/avocado/core/loader.py @@ -17,33 +17,26 @@ Test loader module. """ +import ast import collections +import fnmatch import imp import inspect import os -import re -import sys import shlex -import fnmatch -import ast +import sys from . import data_dir from . import output from . import test -from . import exceptions -from .settings import settings from ..utils import path from ..utils import stacktrace - -try: - import cStringIO as StringIO -except ImportError: - import StringIO +from .settings import settings -DEFAULT = False # Show default tests (for execution) -AVAILABLE = None # Available tests (for listing purposes) -ALL = True # All tests (inicluding broken ones) +DEFAULT = False # Show default tests (for execution) +AVAILABLE = None # Available tests (for listing purposes) +ALL = True # All tests (inicluding broken ones) class LoaderError(Exception): @@ -134,12 +127,12 @@ class TestLoaderProxy(object): loaders = settings.get_value("plugins", "loaders", list, []) if '?' in loaders: raise LoaderError("Available loader plugins: %s" % _str_loaders()) - if "@DEFAULT" in loaders: # Replace @DEFAULT with unused loaders + if "@DEFAULT" in loaders: # Replace @DEFAULT with unused loaders idx = loaders.index("@DEFAULT") loaders = (loaders[:idx] + [plugin for plugin in supported_loaders if plugin not in loaders] + - loaders[idx+1:]) - while "@DEFAULT" in loaders: # Remove duplicite @DEFAULT entries + loaders[idx + 1:]) + while "@DEFAULT" in loaders: # Remove duplicite @DEFAULT entries loaders.remove("@DEFAULT") loaders = [_.split(':', 1) for _ in loaders] @@ -213,7 +206,7 @@ class TestLoaderProxy(object): tests.extend(_test) handled = True if not list_tests: - break # Don't process other plugins + break # Don't process other plugins except Exception, details: handle_exception(loader_plugin, details) if not handled: @@ -261,7 +254,7 @@ class TestLoader(object): Base for test loader classes """ - def __init__(self, args, extra_params): # pylint: disable=W0613 + def __init__(self, args, extra_params): # pylint: disable=W0613 self.args = args def get_extra_listing(self): @@ -432,7 +425,7 @@ class FileLoader(TestLoader): """ if url is None: if list_tests is DEFAULT: - return [] # Return empty set when not listing details + return [] # Return empty set when not listing details else: url = data_dir.get_test_dir() ignore_suffix = ('.data', '.pyc', '.pyo', '__init__.py', @@ -442,7 +435,7 @@ class FileLoader(TestLoader): subtests_filter = None if ':' in url: _url, _subtests_filter = url.split(':', 1) - if os.path.exists(_url): # otherwise it's ':' in the file name + if os.path.exists(_url): # otherwise it's ':' in the file name url = _url subtests_filter = _subtests_filter @@ -459,9 +452,9 @@ class FileLoader(TestLoader): """ Always return None """ return None - if list_tests: # ALL => include everything + if list_tests: # ALL => include everything onerror = add_test_from_exception - else: # DEFAULT, AVAILABLE => skip missing tests + else: # DEFAULT, AVAILABLE => skip missing tests onerror = skip_non_test for dirpath, _, filenames in os.walk(url, onerror=onerror): @@ -567,7 +560,8 @@ class FileLoader(TestLoader): for test_class, test_methods in tests.items(): if isinstance(test_class, str): for test_method in test_methods: - name = test_name + ':%s.%s' % (test_class, test_method) + name = test_name + \ + ':%s.%s' % (test_class, test_method) tst = (test_class, {'name': name, 'modulePath': test_path, 'methodName': test_method}) @@ -611,7 +605,7 @@ class FileLoader(TestLoader): # will not crash. except BaseException, details: # Ugly python files can raise any exc if isinstance(details, KeyboardInterrupt): - raise # Don't ignore ctrl+c + raise # Don't ignore ctrl+c if os.access(test_path, os.X_OK): # Module can't be imported, and it's executable. Let's try to # execute it. @@ -643,9 +637,9 @@ class FileLoader(TestLoader): """ Always return empty list """ return [] - if list_non_tests: # return broken test with params + if list_non_tests: # return broken test with params make_broken = self._make_test - else: # return empty set instead + else: # return empty set instead make_broken = ignore_broken test_name = test_path if os.path.exists(test_path): diff --git a/avocado/core/test.py b/avocado/core/test.py index b715e7de..69d66cd0 100644 --- a/avocado/core/test.py +++ b/avocado/core/test.py @@ -10,8 +10,8 @@ # # This code was inspired in the autotest project, # client/shared/test.py -# Authors: Martin J Bligh , Andy Whitcroft -import re +# Authors: Martin J Bligh , +# Andy Whitcroft """ Contains the base test implementation, used as a base for the actual @@ -22,25 +22,27 @@ import inspect import logging import os import pipes +import re import shutil import sys import time -if sys.version_info[:2] == (2, 6): - import unittest2 as unittest -else: - import unittest - from . import data_dir -from . import sysinfo from . import exceptions from . import multiplexer -from .version import VERSION +from . import sysinfo +from ..utils import data_structures from ..utils import genio from ..utils import path as utils_path from ..utils import process from ..utils import stacktrace -from ..utils import data_structures +from .version import VERSION + + +if sys.version_info[:2] == (2, 6): + import unittest2 as unittest +else: + import unittest class Test(unittest.TestCase): @@ -358,7 +360,7 @@ class Test(unittest.TestCase): except exceptions.TestNAError, details: stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') raise exceptions.TestNAError(details) - except: # Old-style exceptions are not inherited from Exception() + except: # Old-style exceptions are not inherited from Exception() stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') details = sys.exc_info()[1] raise exceptions.TestSetupFail(details) @@ -371,7 +373,7 @@ class Test(unittest.TestCase): 'must fix your test. Original skip exception: ' '%s' % details) raise exceptions.TestError(skip_illegal_msg) - except: # Old-style exceptions are not inherited from Exception() + except: # Old-style exceptions are not inherited from Exception() stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') details = sys.exc_info()[1] if not isinstance(details, Exception): # Avoid passing nasty exc @@ -387,7 +389,7 @@ class Test(unittest.TestCase): 'you must fix your test. Original skip ' 'exception: %s' % details) raise exceptions.TestError(skip_illegal_msg) - except: # avoid old-style exception failures + except: # avoid old-style exception failures stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') details = sys.exc_info()[1] cleanup_exception = exceptions.TestSetupFail(details) @@ -410,12 +412,14 @@ class Test(unittest.TestCase): try: self.check_reference_stdout() except Exception, details: - stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') + stacktrace.log_exc_info(sys.exc_info(), + logger='avocado.test') stdout_check_exception = details try: self.check_reference_stderr() except Exception, details: - stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test') + stacktrace.log_exc_info(sys.exc_info(), + logger='avocado.test') stderr_check_exception = details elif not job_standalone: if output_check_record in ['all', 'stdout']: diff --git a/selftests/functional/test_basic.py b/selftests/functional/test_basic.py index 8592ef3e..b32e44ee 100644 --- a/selftests/functional/test_basic.py +++ b/selftests/functional/test_basic.py @@ -245,7 +245,8 @@ class RunnerOperationTest(unittest.TestCase): Tests that the `latest` link to the latest job results is created early """ os.chdir(basedir) - cmd_line = ('./scripts/avocado run --sysinfo=off --job-results-dir %s examples/tests/passtest.py' % self.tmpdir) + cmd_line = ('./scripts/avocado run --sysinfo=off --job-results-dir %s ' + 'examples/tests/passtest.py' % self.tmpdir) avocado_process = process.SubProcess(cmd_line) avocado_process.start() link = os.path.join(self.tmpdir, 'latest') @@ -304,7 +305,8 @@ class RunnerHumanOutputTest(unittest.TestCase): self.assertEqual(result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) - self.assertIn('skiponsetup.py:SkipOnSetupTest.test_wont_be_executed: SKIP', result.stdout) + self.assertIn('skiponsetup.py:SkipOnSetupTest.test_wont_be_executed:' + ' SKIP', result.stdout) def tearDown(self): shutil.rmtree(self.tmpdir) @@ -319,15 +321,16 @@ class RunnerSimpleTest(unittest.TestCase): PASS_SCRIPT_CONTENTS, 'avocado_simpletest_functional') self.pass_script.save() - self.fail_script = script.TemporaryScript( - 'avocado_fail.sh', - FAIL_SCRIPT_CONTENTS, - 'avocado_simpletest_functional') + self.fail_script = script.TemporaryScript('avocado_fail.sh', + FAIL_SCRIPT_CONTENTS, + 'avocado_simpletest_' + 'functional') self.fail_script.save() def test_simpletest_pass(self): os.chdir(basedir) - cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off %s' % (self.tmpdir, self.pass_script.path) + cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off' + ' %s' % (self.tmpdir, self.pass_script.path)) result = process.run(cmd_line, ignore_status=True) expected_rc = 0 self.assertEqual(result.exit_status, expected_rc, @@ -336,7 +339,8 @@ class RunnerSimpleTest(unittest.TestCase): def test_simpletest_fail(self): os.chdir(basedir) - cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off %s' % (self.tmpdir, self.fail_script.path) + cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off' + ' %s' % (self.tmpdir, self.fail_script.path)) result = process.run(cmd_line, ignore_status=True) expected_rc = 1 self.assertEqual(result.exit_status, expected_rc, @@ -353,7 +357,8 @@ class RunnerSimpleTest(unittest.TestCase): """ os.chdir(basedir) one_hundred = 'failtest ' * 100 - cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off %s' % (self.tmpdir, one_hundred) + cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off' + ' %s' % (self.tmpdir, one_hundred)) initial_time = time.time() result = process.run(cmd_line, ignore_status=True) actual_time = time.time() - initial_time @@ -369,7 +374,8 @@ class RunnerSimpleTest(unittest.TestCase): """ os.chdir(basedir) sleep_fail_sleep = 'sleeptest ' + 'failtest ' * 100 + 'sleeptest' - cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off %s' % (self.tmpdir, sleep_fail_sleep) + cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off %s' % ( + self.tmpdir, sleep_fail_sleep) initial_time = time.time() result = process.run(cmd_line, ignore_status=True) actual_time = time.time() - initial_time @@ -602,7 +608,8 @@ class PluginsXunitTest(AbsPluginsTest, unittest.TestCase): def run_and_check(self, testname, e_rc, e_ntests, e_nerrors, e_nnotfound, e_nfailures, e_nskip): os.chdir(basedir) - cmd_line = './scripts/avocado run --job-results-dir %s --sysinfo=off --xunit - %s' % (self.tmpdir, testname) + cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off' + ' --xunit - %s' % (self.tmpdir, testname)) result = process.run(cmd_line, ignore_status=True) xml_output = result.stdout self.assertEqual(result.exit_status, e_rc, -- GitLab