From 0509e03d3f295862ca15986c004ae6c48917b15f Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Thu, 19 Mar 2020 12:24:34 +0100 Subject: Please the flake8 god --- test/data/module.py | 1 - test/data/noendingnewline.py | 3 --- test/test_cache.py | 2 +- test/test_configuration.py | 2 +- test/test_date.py | 1 - test/test_fileutils.py | 22 +++++++++++++++++----- test/test_interface.py | 2 +- test/test_pytest.py | 10 +++++++++- test/test_registry.py | 18 +++++++++++++----- test/test_shellutils.py | 12 ++++-------- test/test_table.py | 3 +-- test/test_taskqueue.py | 2 +- test/test_testlib.py | 4 +--- test/test_textutils.py | 5 +++-- test/test_tree.py | 45 +++++++++++++++++++++++++++++++++----------- test/test_ureports_html.py | 3 ++- test/utils.py | 19 +++++++++++-------- 17 files changed, 99 insertions(+), 55 deletions(-) (limited to 'test') diff --git a/test/data/module.py b/test/data/module.py index 3b83811..75904eb 100644 --- a/test/data/module.py +++ b/test/data/module.py @@ -5,7 +5,6 @@ from __future__ import print_function from logilab.common import modutils, Execute as spawn from logilab.common.astutils import * -import os.path MY_DICT = {} diff --git a/test/data/noendingnewline.py b/test/data/noendingnewline.py index f309715..d4310b5 100644 --- a/test/data/noendingnewline.py +++ b/test/data/noendingnewline.py @@ -16,15 +16,12 @@ class TestCase(unittest.TestCase): def xxx(self): if False: - pass print("a") if False: pass - pass if False: - pass print("rara") diff --git a/test/test_cache.py b/test/test_cache.py index 8e169c4..d094943 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with logilab-common. If not, see . -from logilab.common.testlib import TestCase, unittest_main, TestSuite +from logilab.common.testlib import TestCase, unittest_main from logilab.common.cache import Cache diff --git a/test/test_configuration.py b/test/test_configuration.py index d8d0a4b..a4f8ec0 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -141,7 +141,7 @@ class ConfigurationTC(TestCase): def test_load_configuration(self): cfg = self.cfg - args = cfg.load_configuration( + cfg.load_configuration( choice="ye", number="4", multiple="1,2,3", dothis="n", multiple_choice=("yo", "ya") ) self.assertEqual(cfg["dothis"], False) diff --git a/test/test_date.py b/test/test_date.py index cf09b11..f573e16 100644 --- a/test/test_date.py +++ b/test/test_date.py @@ -42,7 +42,6 @@ try: DateTime as mxDateTime, now as mxNow, RelativeDateTime, - RelativeDate, ) except ImportError: mxDate = mxDateTime = RelativeDateTime = mxNow = None diff --git a/test/test_fileutils.py b/test/test_fileutils.py index 49955cd..a2dd8b4 100644 --- a/test/test_fileutils.py +++ b/test/test_fileutils.py @@ -19,13 +19,24 @@ import doctest import io -import sys, os, tempfile, shutil +import sys +import os +import tempfile +import shutil from stat import S_IWRITE from os.path import join -from logilab.common.testlib import TestCase, unittest_main, unittest +from logilab.common.testlib import TestCase, unittest_main -from logilab.common.fileutils import * +from logilab.common.fileutils import ( + first_level_directory, + is_binary, + write_open_mode, + lines, + export, + exists, + ProtectedFile, +) DATA_DIR = join(os.path.abspath(os.path.dirname(__file__)), "data") NEWLINES_TXT = join(DATA_DIR, "newlines.txt") @@ -100,13 +111,14 @@ class ProtectedFileTC(TestCase): # test on non-writable file # self.assertTrue(not os.access(self.rpath, os.W_OK)) self.assertTrue(not os.stat(self.rpath).st_mode & S_IWRITE) - wp_file = ProtectedFile(self.rpath, "w") + # for some reason if you remove "wp_file =" the test fails + wp_file = ProtectedFile(self.rpath, "w") # noqa self.assertTrue(os.stat(self.rpath).st_mode & S_IWRITE) self.assertTrue(os.access(self.rpath, os.W_OK)) # test on writable-file self.assertTrue(os.stat(self.rwpath).st_mode & S_IWRITE) self.assertTrue(os.access(self.rwpath, os.W_OK)) - wp_file = ProtectedFile(self.rwpath, "w") + ProtectedFile(self.rwpath, "w") self.assertTrue(os.stat(self.rwpath).st_mode & S_IWRITE) self.assertTrue(os.access(self.rwpath, os.W_OK)) diff --git a/test/test_interface.py b/test/test_interface.py index a3c20bf..62447b6 100644 --- a/test/test_interface.py +++ b/test/test_interface.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with logilab-common. If not, see . from logilab.common.testlib import TestCase, unittest_main -from logilab.common.interface import * +from logilab.common.interface import Interface, extend class IFace1(Interface): diff --git a/test/test_pytest.py b/test/test_pytest.py index 02a34d4..fb95c23 100644 --- a/test/test_pytest.py +++ b/test/test_pytest.py @@ -15,9 +15,17 @@ # # You should have received a copy of the GNU Lesser General Public License along # with logilab-common. If not, see . +import sys + from os.path import join from logilab.common.testlib import TestCase, unittest_main -from logilab.common.pytest import * +from logilab.common.pytest import ( + this_is_a_testdir, + this_is_a_testfile, + replace_trace, + pause_trace, + nocoverage, +) class ModuleFunctionTC(TestCase): diff --git a/test/test_registry.py b/test/test_registry.py index 4d4104b..148bf77 100644 --- a/test/test_registry.py +++ b/test/test_registry.py @@ -19,17 +19,25 @@ import gc import logging -import os.path as osp import sys -from operator import eq, lt, le, gt from contextlib import contextmanager import warnings -logging.basicConfig(level=logging.ERROR) +from logilab.common.testlib import ( + TestCase, + unittest_main, +) -from logilab.common.testlib import TestCase, unittest_main +from logilab.common.registry import ( + Predicate, + AndPredicate, + OrPredicate, + wrap_predicates, + RegistryStore, + RegistrableInstance, +) -from logilab.common.registry import * +logging.basicConfig(level=logging.ERROR) class _1_(Predicate): diff --git a/test/test_shellutils.py b/test/test_shellutils.py index 8cb06ca..1d8b326 100644 --- a/test/test_shellutils.py +++ b/test/test_shellutils.py @@ -17,9 +17,7 @@ # with logilab-common. If not, see . """unit tests for logilab.common.shellutils""" -import sys, os, tempfile, shutil from os.path import join, dirname, abspath -import datetime, time from unittest.mock import patch from logilab.common.testlib import TestCase, unittest_main @@ -197,7 +195,6 @@ class ProgressBarTC(TestCase): expected_stream = StringIO() size = 20 pgb = ProgressBar(100, size, stream=pgb_stream) - last = 0 for dots in range(10, 105, 15): pgb.update(dots, exact=True) dots //= 5 @@ -209,7 +206,6 @@ class ProgressBarTC(TestCase): expected_stream = StringIO() size = 20 pgb = ProgressBar(100, size, stream=pgb_stream) - last = 0 for dots in range(5, 105, 5): pgb.update(5, exact=False) dots //= 5 @@ -259,13 +255,13 @@ class RawInputTC(TestCase): def test_ask_prompt(self): self.input_answer = "" - answer = self.qa.ask("text", ("yes", "no"), "yes") + self.qa.ask("text", ("yes", "no"), "yes") self.assertEqual(self.input_args[0], "text [Y(es)/n(o)]: ") - answer = self.qa.ask("text", ("y", "n"), "y") + self.qa.ask("text", ("y", "n"), "y") self.assertEqual(self.input_args[0], "text [Y/n]: ") - answer = self.qa.ask("text", ("n", "y"), "y") + self.qa.ask("text", ("n", "y"), "y") self.assertEqual(self.input_args[0], "text [n/Y]: ") - answer = self.qa.ask("text", ("yes", "no", "maybe", "1"), "yes") + self.qa.ask("text", ("yes", "no", "maybe", "1"), "yes") self.assertEqual(self.input_args[0], "text [Y(es)/n(o)/m(aybe)/1]: ") def test_ask_ambiguous(self): diff --git a/test/test_table.py b/test/test_table.py index 5c0ac19..e3736c1 100644 --- a/test/test_table.py +++ b/test/test_table.py @@ -21,7 +21,6 @@ Unittests for table management import sys -import os from logilab.common.compat import StringIO from logilab.common.testlib import TestCase, unittest_main @@ -379,7 +378,7 @@ class TableStyleTC(TestCase): """tests style's get and set by index methods""" for attrname, default_value in self._tested_attrs: getter = getattr(self.style, "get_%s" % attrname) - setter = getattr(self.style, "set_%s" % attrname) + getattr(self.style, "set_%s" % attrname) igetter = getattr(self.style, "get_%s_by_index" % attrname) isetter = getattr(self.style, "set_%s_by_index" % attrname) self.assertEqual(getter("__row_column__"), default_value) diff --git a/test/test_taskqueue.py b/test/test_taskqueue.py index 3e49ade..30b4757 100644 --- a/test/test_taskqueue.py +++ b/test/test_taskqueue.py @@ -17,7 +17,7 @@ # with logilab-common. If not, see . from logilab.common.testlib import TestCase, unittest_main -from logilab.common.tasksqueue import * +from logilab.common.tasksqueue import Task, PrioritizedTasksQueue, LOW, MEDIUM, HIGH class TaskTC(TestCase): diff --git a/test/test_testlib.py b/test/test_testlib.py index 8f95711..d2240ae 100644 --- a/test/test_testlib.py +++ b/test/test_testlib.py @@ -32,7 +32,6 @@ except NameError: from logilab.common.compat import StringIO from logilab.common.testlib import ( - unittest, TestSuite, unittest_main, Tags, @@ -443,7 +442,7 @@ class ExitFirstTC(TestCase): class TestLoaderTC(TestCase): - ## internal classes for test purposes ######## + # internal classes for test purposes ######## class FooTC(TestCase): def test_foo1(self): pass @@ -804,7 +803,6 @@ class DecoratorTC(TestCase): for module in modules: try: __import__(module) - pass except ImportError: decorator = require_module(module) self.assertNotEqual( diff --git a/test/test_textutils.py b/test/test_textutils.py index 8aa2ded..2f30905 100644 --- a/test/test_textutils.py +++ b/test/test_textutils.py @@ -21,6 +21,9 @@ unit tests for module textutils squeleton generated by /home/syt/cvs_work/logilab/pyreverse/py2tests.py on Sep 08 at 09:1:31 """ + +# flake8: noqa: E501 + import doctest import re from os import linesep @@ -30,8 +33,6 @@ from logilab.common.testlib import TestCase, unittest_main if linesep != "\n": - import re - LINE_RGX = re.compile(linesep) def ulines(string): diff --git a/test/test_tree.py b/test/test_tree.py index 58a8ba9..0faf079 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -21,7 +21,14 @@ squeleton generated by /home/syt/bin/py2tests on Jan 20 at 10:43:25 """ from logilab.common.testlib import TestCase, unittest_main -from logilab.common.tree import * +from logilab.common.tree import ( + Node, + NodeNotFound, + post_order_list, + PostfixedDepthFirstIterator, + pre_order_list, + PrefixedDepthFirstIterator, +) tree = ( "root", @@ -196,9 +203,17 @@ class post_order_list_FunctionTest(TestCase): create a list with tree nodes for which the function returned true in a post order foashion """ - L = ["child_2_1", "child_3_1", "child_2_2", "child_1_1", "child_2_3", "child_1_2", "root"] - l = [n.id for n in post_order_list(self.o)] - self.assertEqual(l, L, l) + L = [ + "child_2_1", + "child_3_1", + "child_2_2", + "child_1_1", + "child_2_3", + "child_1_2", + "root", + ] + li = [n.id for n in post_order_list(self.o)] + self.assertEqual(li, L, li) def test_known_values_post_order_list2(self): """ @@ -212,8 +227,8 @@ class post_order_list_FunctionTest(TestCase): return 1 L = ["child_2_1", "child_1_1", "child_2_3", "child_1_2", "root"] - l = [n.id for n in post_order_list(self.o, filter)] - self.assertEqual(l, L, l) + li = [n.id for n in post_order_list(self.o, filter)] + self.assertEqual(li, L, li) class PostfixedDepthFirstIterator_ClassTest(TestCase): @@ -246,9 +261,17 @@ class pre_order_list_FunctionTest(TestCase): create a list with tree nodes for which the function returned true in a pre order fashion """ - L = ["root", "child_1_1", "child_2_1", "child_2_2", "child_3_1", "child_1_2", "child_2_3"] - l = [n.id for n in pre_order_list(self.o)] - self.assertEqual(l, L, l) + L = [ + "root", + "child_1_1", + "child_2_1", + "child_2_2", + "child_3_1", + "child_1_2", + "child_2_3", + ] + li = [n.id for n in pre_order_list(self.o)] + self.assertEqual(li, L, li) def test_known_values_pre_order_list2(self): """ @@ -262,8 +285,8 @@ class pre_order_list_FunctionTest(TestCase): return 1 L = ["root", "child_1_1", "child_2_1", "child_1_2", "child_2_3"] - l = [n.id for n in pre_order_list(self.o, filter)] - self.assertEqual(l, L, l) + li = [n.id for n in pre_order_list(self.o, filter)] + self.assertEqual(li, L, li) class PrefixedDepthFirstIterator_ClassTest(TestCase): diff --git a/test/test_ureports_html.py b/test/test_ureports_html.py index 16300c9..e3c47bb 100644 --- a/test/test_ureports_html.py +++ b/test/test_ureports_html.py @@ -18,10 +18,11 @@ """unit tests for ureports.html_writer """ +# flake8: noqa: E501 from utils import WriterTC from logilab.common.testlib import TestCase, unittest_main -from logilab.common.ureports.html_writer import * +from logilab.common.ureports.html_writer import HTMLWriter class HTMLWriterTC(TestCase, WriterTC): diff --git a/test/utils.py b/test/utils.py index de9bc23..e77ccf8 100644 --- a/test/utils.py +++ b/test/utils.py @@ -23,6 +23,16 @@ from __future__ import print_function import sys from io import StringIO +from logilab.common.ureports.nodes import ( + Section, + Text, + Table, + VerbatimText, + List, + Paragraph, + Link, +) + buffers = [StringIO] if sys.version_info < (3, 0): from cStringIO import StringIO as cStringIO @@ -30,8 +40,6 @@ if sys.version_info < (3, 0): buffers += [cStringIO, pStringIO] -from logilab.common.ureports.nodes import * - class WriterTC: def _test_output(self, test_id, layout, msg=None): @@ -42,7 +50,7 @@ class WriterTC: expected = getattr(self, test_id) try: self.assertMultiLineEqual(got, expected) - except: + except Exception: print("**** using a %s" % buffer.__class__) print("**** got for %s" % test_id) print(got) @@ -90,8 +98,3 @@ class WriterTC: table.append(Link("http://www.perdu.com", "toi perdu ?")) table.append(Text("")) self._test_output("advanced_table", table) - - -## def test_image(self): -## layout = Verbatim('blablabla') -## self._test_output('verbatim_base', layout) -- cgit v1.2.1