From f115370c0b6a96c7698071e601089a4f28a84a68 Mon Sep 17 00:00:00 2001 From: Charles Ferguson Date: Wed, 15 Nov 2023 08:43:01 +0000 Subject: [PATCH] Fixes for flake8 reported whitespace problems. (#39) * Fixes for flake8 reported whitespace problems. Most of the whitespace problems are fixed by this change, just removing or adding lines or spaces around statements. * Update the flake8 and runtest runners to include shebang. No shebang line meant that these might not run properly. * Comma whitespace fix. A small fix that was missed in earlier changes. --- Hyper/utils.py | 8 +++---- flake8.sh | 3 ++- riscos_toolbox/__init__.py | 4 ++-- riscos_toolbox/_types.py | 2 +- runtest.sh | 1 + test/components/test_saveas.py | 8 ++++++- test/events/test_redraw_window.py | 7 +++--- test/fakeswi.py | 5 ++++- test/test_dispatcher.py | 5 +++++ test/test_toolbox.py | 2 +- toolbox_types.py | 37 +------------------------------ 11 files changed, 32 insertions(+), 50 deletions(-) diff --git a/Hyper/utils.py b/Hyper/utils.py index e2a1ccb..e14d4c3 100755 --- a/Hyper/utils.py +++ b/Hyper/utils.py @@ -19,17 +19,17 @@ def file_load(filename): size = header[1] buffer = (ctypes.c_byte * size)() - ws_size = swi.swi("Squash_Decompress", "II;I", 8, sq_size-20) + ws_size = swi.swi("Squash_Decompress", "II;I", 8, sq_size - 20) workspace = (ctypes.c_byte * ws_size)() swi.swi("Squash_Decompress", "iIIIII", 4, ctypes.addressof(workspace), - ctypes.addressof(squashed)+20, - sq_size-20, + ctypes.addressof(squashed) + 20, + sq_size - 20, ctypes.addressof(buffer), size) return buffer, size - + if __name__ == "__main__": print(file_load("underlay")) diff --git a/flake8.sh b/flake8.sh index 66c57c8..6fe899c 100755 --- a/flake8.sh +++ b/flake8.sh @@ -1 +1,2 @@ -python3 -m flake8 . --count --ignore=E221,E501 --show-source --statistics +#!/bin/bash +python3 -m flake8 . --count --ignore=E221,E501,E227 --show-source --statistics diff --git a/riscos_toolbox/__init__.py b/riscos_toolbox/__init__.py index 84c717a..a316950 100644 --- a/riscos_toolbox/__init__.py +++ b/riscos_toolbox/__init__.py @@ -108,8 +108,8 @@ def run(application): global _quit while not _quit: - reason,sender = swi.swi( - 'Wimp_Poll','II;I.I', + reason, sender = swi.swi( + 'Wimp_Poll', 'II;I.I', application.poll_flags, ctypes.addressof(poll_buffer)) diff --git a/riscos_toolbox/_types.py b/riscos_toolbox/_types.py index 66bd869..ea2f335 100644 --- a/riscos_toolbox/_types.py +++ b/riscos_toolbox/_types.py @@ -25,7 +25,7 @@ class IDBlock(ctypes.Structure): ] def __repr__(self): - return "Acestor: {} Parent: {} Self: {}".format(self.ancestor, self.parent, self.self) + return "Ancestor: {} Parent: {} Self: {}".format(self.ancestor, self.parent, self.self) class Point(ctypes.Structure): diff --git a/runtest.sh b/runtest.sh index 2bb0754..dfb8f28 100755 --- a/runtest.sh +++ b/runtest.sh @@ -1 +1,2 @@ +#!/bin/bash python -m unittest discover -s test diff --git a/test/components/test_saveas.py b/test/components/test_saveas.py index 779393f..33d18e4 100644 --- a/test/components/test_saveas.py +++ b/test/components/test_saveas.py @@ -10,11 +10,13 @@ import swi + TEST_OBJECT_ID = 0x1001 TEST_WINDOW_ID = 0x2001 TEST_TITLE = "Test Title" TEST_NAME = "Test" + class SwiMock: def __init__(self): self._expect = [] @@ -37,7 +39,7 @@ def argmatch(a, b): return True if not argmatch(exp, args): - raise RuntimeError("SWI call mismatch: got {} exp {}".format(args, exp)) + raise RuntimeError("SWI call mismatch: got {} exp {}".format(args, exp)) self._pos += 1 return ret @@ -50,6 +52,7 @@ def expect(self, exp, ret=None): def completed(self): return self._pos == len(self._expect) + class MockBlockString: def __init__(self, string): self.string = string @@ -60,13 +63,16 @@ def __call__(self, *args): def nullstring(self): return self.string + def expect_miscop(obj, op, ret): return (('Toolbox_ObjectMiscOp', 'III;I', 0, obj, op), ret) + def expect_miscop_string(swimock, obj, op, str): swimock.expect(('Toolbox_ObjectMiscOp', 'III00;....I', 0, obj, op), len(str)) swimock.expect(('Toolbox_ObjectMiscOp', 'IIIbI', 0, obj, op, None, len(str)), None) + class SaveAs(unittest.TestCase): def test_window_id(self): diff --git a/test/events/test_redraw_window.py b/test/events/test_redraw_window.py index f4f6929..74ca469 100755 --- a/test/events/test_redraw_window.py +++ b/test/events/test_redraw_window.py @@ -3,15 +3,16 @@ import unittest import struct + class RedrawWindow(unittest.TestCase): def test_from_init(self): rw = redraw_window.RedrawWindow() - assert(rw.event_id == 1) + assert (rw.event_id == 1) def test_from_block(self): rw = redraw_window.RedrawWindow.from_poll_block( struct.pack("i", 42) ) - assert(rw.event_id == 1) - assert(rw.window_handle == 42) + assert (rw.event_id == 1) + assert (rw.window_handle == 42) diff --git a/test/fakeswi.py b/test/fakeswi.py index aa177d3..7ce92f7 100644 --- a/test/fakeswi.py +++ b/test/fakeswi.py @@ -3,15 +3,19 @@ def swi(*args): pass + class block: def __init__(self, *args): pass + + import unittest import fakeswi import sys sys.modules['swi'] = fakeswi + """ import riscos_toolbox as toolbox import riscos_toolbox.objects.saveas @@ -92,4 +96,3 @@ def test_get_title(self): self.assertEqual(saveas.title, "Test Title") self.assertTrue(swimock.completed) """ - diff --git a/test/test_dispatcher.py b/test/test_dispatcher.py index b19ebc0..690ca9e 100644 --- a/test/test_dispatcher.py +++ b/test/test_dispatcher.py @@ -14,6 +14,7 @@ calls = [] + class TestClass01(toolbox.Object): def __init__(self, id): super().__init__(id, "test") @@ -22,6 +23,7 @@ def __init__(self, id): def event_c101(self, event, id_block, poll_block): calls.append((self.__class__.__name__, self.id, event, id_block, poll_block)) + class TestClass02(toolbox.Object): def __init__(self, id): super().__init__(id, "test") @@ -33,6 +35,7 @@ def __init__(self, id): def event_c102(self, event, id_block, poll_block): calls.append((self.__class__.__name__, self.id, event, id_block, poll_block)) + class TestClass03(toolbox.Object): def __init__(self, id): super().__init__(id, "test") @@ -41,10 +44,12 @@ def __init__(self, id): def event_c103(self, event, id_block, poll_block): calls.append((self.__class__.__name__, self.id, event, id_block, poll_block)) + @toolbox_handler(0xff01) def test_func(event, id_block, *args): calls.append((test_func.__name__, None, event, id_block, args)) + class ObjectDispatchTest(unittest.TestCase): def setUp(self): calls.clear() diff --git a/test/test_toolbox.py b/test/test_toolbox.py index 7b2cbcb..73757f4 100644 --- a/test/test_toolbox.py +++ b/test/test_toolbox.py @@ -6,7 +6,7 @@ import riscos_toolbox as toolbox + class ToolboxTest(unittest.TestCase): def test_one(self): self.assertEqual(0, 0) - diff --git a/toolbox_types.py b/toolbox_types.py index 3ddc9cd..ffcf122 100755 --- a/toolbox_types.py +++ b/toolbox_types.py @@ -2,6 +2,7 @@ Python constants. """ + class ActionbuttonConstants(object): # .Bits @@ -22,7 +23,6 @@ class ActionbuttonConstants(object): Class_ActionButton = 128 - class AdjusterConstants(object): # .Bits @@ -36,7 +36,6 @@ class AdjusterConstants(object): Class_Adjuster = 768 - class ButtonConstants(object): # .Bits @@ -47,7 +46,6 @@ class ButtonConstants(object): Class_Button = 960 - class ColourdboxConstants(object): # .Bits @@ -77,7 +75,6 @@ class ColourdboxConstants(object): Class_ColourDbox = 534976 - class ColourmenuConstants(object): # .Bits @@ -104,7 +101,6 @@ class ColourmenuConstants(object): Class_ColourMenu = 534912 - class DcsConstants(object): # .Bits @@ -130,7 +126,6 @@ class DcsConstants(object): Class_DCS = 535168 - class DdeutilsConstants(object): # .Bits @@ -157,7 +152,6 @@ class DdeutilsConstants(object): DDEUtils_ThrowbackProcessing = 0 - class DisplayfieldConstants(object): # Gadget_Flags @@ -168,7 +162,6 @@ class DisplayfieldConstants(object): Class_DisplayField = 448 - class DraganobjectConstants(object): # .Bits @@ -190,7 +183,6 @@ class DraganobjectConstants(object): DragAnObject_FunctionSVC = (1<<17) - class DraggableConstants(object): # .Bits @@ -220,7 +212,6 @@ class DraggableConstants(object): Class_Draggable = 640 - class FileinfoConstants(object): # .Bits @@ -253,7 +244,6 @@ class FileinfoConstants(object): Class_FileInfo = 535232 - class FontdboxConstants(object): # .Bits @@ -302,7 +292,6 @@ class FontdboxConstants(object): Class_FontDbox = 535040 - class FontmenuConstants(object): # .Bits @@ -325,7 +314,6 @@ class FontmenuConstants(object): Class_FontMenu = 535104 - class FrontendConstants(object): pass @@ -364,7 +352,6 @@ class GadgetConstants(object): Gadget_Faded = (1<<31) - class IconbarConstants(object): # .Bits @@ -401,14 +388,12 @@ class IconbarConstants(object): Class_Iconbar = 534784 - class KeyboardshortcutConstants(object): # KeyboardShortcut_Flags KeyboardShortcut_ShowAsMenu = (1<<0) - class LabelConstants(object): # .Bits @@ -420,7 +405,6 @@ class LabelConstants(object): Class_Label = 320 - class LabelledboxConstants(object): # Gadget_Flags @@ -431,7 +415,6 @@ class LabelledboxConstants(object): Class_LabelledBox = 256 - class MenuConstants(object): # .Bits @@ -480,7 +463,6 @@ class MenuConstants(object): Class_Menu = 534720 - class NumberrangeConstants(object): # .Bits @@ -516,7 +498,6 @@ class NumberrangeConstants(object): Class_NumberRange = 832 - class OptionbuttonConstants(object): # .Bits @@ -528,7 +509,6 @@ class OptionbuttonConstants(object): Class_OptionButton = 192 - class PopupConstants(object): # .Bits @@ -541,7 +521,6 @@ class PopupConstants(object): PopUp_Class = 704 - class PrintdboxConstants(object): # .Bits @@ -595,7 +574,6 @@ class PrintdboxConstants(object): PrintDbox_Percent = 137035792 - class ProginfoConstants(object): # .Bits @@ -637,7 +615,6 @@ class ProginfoConstants(object): Class_ProgInfo = 535360 - class QuitConstants(object): # .Bits @@ -659,7 +636,6 @@ class QuitConstants(object): Class_Quit = 535184 - class RadiobuttonConstants(object): # .Bits @@ -676,7 +652,6 @@ class RadiobuttonConstants(object): Class_RadioButton = 384 - class SaveasConstants(object): # .Bits @@ -720,7 +695,6 @@ class SaveasConstants(object): Class_SaveAs = 535488 - class ScaleConstants(object): # .Bits @@ -758,7 +732,6 @@ class ScaleConstants(object): Class_Scale = 535552 - class SliderConstants(object): # .Bits @@ -789,7 +762,6 @@ class SliderConstants(object): Class_Slider = 576 - class StringsetConstants(object): # .Bits @@ -817,7 +789,6 @@ class StringsetConstants(object): StringSet_Class = 896 - class ToolboxConstants(object): # .Bits @@ -893,7 +864,6 @@ class ToolboxConstants(object): Toolbox_ShowAsSubMenu = (1<<1) - class WindowConstants(object): # .Bits @@ -938,7 +908,6 @@ class WindowConstants(object): Window_ToolBarETL = (1<<3) - class WindowsupportexternalConstants(object): # .Int @@ -953,7 +922,6 @@ class WindowsupportexternalConstants(object): WindowSupportExternal_HandlerSetFocus = 10 - class WritablefieldConstants(object): # .Bits @@ -967,6 +935,3 @@ class WritablefieldConstants(object): # Toolbox_Class Class_WritableField = 512 - - -