From ee2671a5f3b911f701e15d01ce9e099c3646dfe3 Mon Sep 17 00:00:00 2001 From: Andrew Senetar Date: Sat, 27 Jun 2020 01:08:12 -0500 Subject: [PATCH] More Test and Flake8 Cleanup - Allow flake8 to check more files as well. --- core/tests/base.py | 2 ++ hscommon/tests/conflict_test.py | 8 ++++- hscommon/tests/notify_test.py | 62 ++++++++++++++++----------------- hscommon/tests/path_test.py | 6 ++-- hscommon/tests/table_test.py | 4 +++ hscommon/tests/util_test.py | 26 +++++++++++++- run.py | 2 +- tox.ini | 2 +- 8 files changed, 74 insertions(+), 38 deletions(-) diff --git a/core/tests/base.py b/core/tests/base.py index c5bce92a..844c0653 100644 --- a/core/tests/base.py +++ b/core/tests/base.py @@ -147,6 +147,8 @@ def GetTestGroups(): class TestApp(TestAppBase): + __test__ = False + def __init__(self): def link_gui(gui): gui.view = self.make_logger() diff --git a/hscommon/tests/conflict_test.py b/hscommon/tests/conflict_test.py index 74f5f388..617a9f62 100644 --- a/hscommon/tests/conflict_test.py +++ b/hscommon/tests/conflict_test.py @@ -8,7 +8,13 @@ import pytest -from ..conflict import * +from ..conflict import ( + get_conflicted_name, + get_unconflicted_name, + is_conflicted, + smart_copy, + smart_move, +) from ..path import Path from ..testutil import eq_ diff --git a/hscommon/tests/notify_test.py b/hscommon/tests/notify_test.py index 4c5e9197..09ce8f43 100644 --- a/hscommon/tests/notify_test.py +++ b/hscommon/tests/notify_test.py @@ -28,8 +28,8 @@ class HelloRepeater(Repeater): def create_pair(): b = Broadcaster() - l = HelloListener(b) - return b, l + listener = HelloListener(b) + return b, listener def test_disconnect_during_notification(): @@ -60,53 +60,53 @@ def test_disconnect_during_notification(): def test_disconnect(): # After a disconnect, the listener doesn't hear anything. - b, l = create_pair() - l.connect() - l.disconnect() + b, listener = create_pair() + listener.connect() + listener.disconnect() b.notify("hello") - eq_(l.hello_count, 0) + eq_(listener.hello_count, 0) def test_disconnect_when_not_connected(): # When disconnecting an already disconnected listener, nothing happens. - b, l = create_pair() - l.disconnect() + b, listener = create_pair() + listener.disconnect() def test_not_connected_on_init(): # A listener is not initialized connected. - b, l = create_pair() + b, listener = create_pair() b.notify("hello") - eq_(l.hello_count, 0) + eq_(listener.hello_count, 0) def test_notify(): # The listener listens to the broadcaster. - b, l = create_pair() - l.connect() + b, listener = create_pair() + listener.connect() b.notify("hello") - eq_(l.hello_count, 1) + eq_(listener.hello_count, 1) def test_reconnect(): # It's possible to reconnect a listener after disconnection. - b, l = create_pair() - l.connect() - l.disconnect() - l.connect() + b, listener = create_pair() + listener.connect() + listener.disconnect() + listener.connect() b.notify("hello") - eq_(l.hello_count, 1) + eq_(listener.hello_count, 1) def test_repeater(): b = Broadcaster() r = HelloRepeater(b) - l = HelloListener(r) + listener = HelloListener(r) r.connect() - l.connect() + listener.connect() b.notify("hello") eq_(r.hello_count, 1) - eq_(l.hello_count, 1) + eq_(listener.hello_count, 1) def test_repeater_with_repeated_notifications(): @@ -124,15 +124,15 @@ def test_repeater_with_repeated_notifications(): b = Broadcaster() r = MyRepeater(b) - l = HelloListener(r) + listener = HelloListener(r) r.connect() - l.connect() + listener.connect() b.notify("hello") b.notify( "foo" ) # if the repeater repeated this notif, we'd get a crash on HelloListener eq_(r.hello_count, 1) - eq_(l.hello_count, 1) + eq_(listener.hello_count, 1) eq_(r.foo_count, 1) @@ -140,18 +140,18 @@ def test_repeater_doesnt_try_to_dispatch_to_self_if_it_cant(): # if a repeater doesn't handle a particular message, it doesn't crash and simply repeats it. b = Broadcaster() r = Repeater(b) # doesnt handle hello - l = HelloListener(r) + listener = HelloListener(r) r.connect() - l.connect() + listener.connect() b.notify("hello") # no crash - eq_(l.hello_count, 1) + eq_(listener.hello_count, 1) def test_bind_messages(): - b, l = create_pair() - l.bind_messages({"foo", "bar"}, l.hello) - l.connect() + b, listener = create_pair() + listener.bind_messages({"foo", "bar"}, listener.hello) + listener.connect() b.notify("foo") b.notify("bar") b.notify("hello") # Normal dispatching still work - eq_(l.hello_count, 3) + eq_(listener.hello_count, 3) diff --git a/hscommon/tests/path_test.py b/hscommon/tests/path_test.py index 658b9854..b87a7e81 100644 --- a/hscommon/tests/path_test.py +++ b/hscommon/tests/path_test.py @@ -51,7 +51,7 @@ def test_init_with_tuple_and_list(force_ossep): def test_init_with_invalid_value(force_ossep): try: - path = Path(42) + path = Path(42) # noqa: F841 assert False except TypeError: pass @@ -143,8 +143,8 @@ def test_path_slice(force_ossep): eq_((), foobar[:foobar]) abcd = Path("a/b/c/d") a = Path("a") - b = Path("b") - c = Path("c") + b = Path("b") # noqa: #F841 + c = Path("c") # noqa: #F841 d = Path("d") z = Path("z") eq_("b/c", abcd[a:d]) diff --git a/hscommon/tests/table_test.py b/hscommon/tests/table_test.py index f55ddf49..468675b4 100644 --- a/hscommon/tests/table_test.py +++ b/hscommon/tests/table_test.py @@ -11,6 +11,8 @@ from ..gui.table import Table, GUITable, Row class TestRow(Row): + __test__ = False + def __init__(self, table, index, is_new=False): Row.__init__(self, table) self.is_new = is_new @@ -28,6 +30,8 @@ class TestRow(Row): class TestGUITable(GUITable): + __test__ = False + def __init__(self, rowcount, viewclass=CallLogger): GUITable.__init__(self) self.view = viewclass() diff --git a/hscommon/tests/util_test.py b/hscommon/tests/util_test.py index 9e41637d..800780bb 100644 --- a/hscommon/tests/util_test.py +++ b/hscommon/tests/util_test.py @@ -12,7 +12,31 @@ from pytest import raises from ..testutil import eq_ from ..path import Path -from ..util import * +from ..util import ( + nonone, + tryint, + minmax, + first, + flatten, + dedupe, + stripfalse, + extract, + allsame, + trailiter, + format_time, + format_time_decimal, + format_size, + remove_invalid_xml, + multi_replace, + delete_if_empty, + open_if_filename, + FileOrPath, + iterconsume, + escape, + get_file_ext, + rem_file_ext, + pluralize, +) def test_nonone(): diff --git a/run.py b/run.py index 6ec6297c..76fd0cd0 100644 --- a/run.py +++ b/run.py @@ -16,7 +16,7 @@ from PyQt5.QtWidgets import QApplication from hscommon.trans import install_gettext_trans_under_qt from qtlib.error_report_dialog import install_excepthook from qtlib.util import setupQtLogging -from qt import dg_rc +from qt import dg_rc # noqa: F401 from qt.platform import BASE_PATH from core import __version__, __appname__ diff --git a/tox.ini b/tox.ini index 5d49c6ee..fb929642 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ commands = python package.py [flake8] -exclude = .tox,env,build,hscommon/tests,cocoalib,cocoa,help,./qt/dg_rc.py,qt/run_template.py,cocoa/run_template.py,./run.py,./pkg +exclude = .tox,env,build,cocoalib,cocoa,help,./qt/dg_rc.py,cocoa/run_template.py,./pkg max-line-length = 120 ignore = E731,E203,E501,W503