Skip to content

Commit

Permalink
fixup! chore: other ruff lint manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
minijackson committed Dec 4, 2023
1 parent bdaa55a commit 476bd83
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 152 deletions.
16 changes: 5 additions & 11 deletions wetest/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@

# logger setup
logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(TERSE_FORMATTER)
logger.addHandler(stream_handler)
logger.addHandler(FILE_HANDLER)
## choose modules logging level
# print("\n".join(logging.Logger.manager.loggerDict)) # list loggers
logging.getLogger("wetest.gui.generator").setLevel(logging.ERROR)
logging.getLogger("wetest.gui.specific").setLevel(logging.ERROR)
logging.getLogger("wetest.gui.base").setLevel(logging.ERROR)
Expand Down Expand Up @@ -618,8 +615,6 @@ def start_gui_command_process(self):
target=self.gui_commands,
name="gui_commands",
)
# so that it can restart the runner and parser process
# self.p_gui_commands.daemon = True
self.p_gui_commands.start()
self.ns.pid_p_gui_commands = self.p_gui_commands.pid
logger.debug("pid_p_gui_commands: %s", self.ns.pid_p_gui_commands)
Expand Down Expand Up @@ -708,7 +703,7 @@ def run_and_report(self):

time.sleep(0.1) # Just enough to let the Queue finish
# https://stackoverflow.com/questions/36359528/broken-pipe-error-with-multiprocessing-queue.
# TODO is this solved now that Queue comes from a multiprocessing.Manager ?
# TODO(gohierf): is this solved now that Queue comes from a multiprocessing.Manager ?

logger.debug("Leave run_and_report (%d)", multiprocessing.current_process().pid)

Expand Down Expand Up @@ -789,7 +784,7 @@ def gui_commands(self):
break

else:
logger.critical("Unexpected gui command:\n%s" % cmd)
logger.critical("Unexpected gui command:\n%s", cmd)

logger.debug("Leave gui_commands (%d)", multiprocessing.current_process().pid)

Expand Down Expand Up @@ -889,17 +884,16 @@ def parse_output(self):
self.stop_runner()
if self.ns.no_gui:
break
else:
self.start_runner_process() # enable replay from GUI
self.start_runner_process() # enable replay from GUI

# check for no more tests
elif new_str == END_OF_TESTS:
logger.debug("=> No more test to run.")
self.queue_to_gui.put(END_OF_TESTS)
if self.ns.no_gui:
break
else:
self.start_runner_process() # enable replay from GUI

self.start_runner_process() # enable replay from GUI

# we should not reach here
else:
Expand Down
18 changes: 8 additions & 10 deletions wetest/gui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

"""Generic classes used in gui.specific and gui.generator."""

# Lots of callbacks here
# ruff: noqa: ARG002

import contextlib
import logging
Expand Down Expand Up @@ -247,7 +249,6 @@ def __init__(
self.text = text
self.widget.bind("<Enter>", self.on_enter)
self.widget.bind("<Leave>", self.on_leave)
# self.widget.bind("<ButtonPress>", self.onLeave)
self.bg = bg
self.pad = pad
self.id = None
Expand All @@ -271,9 +272,6 @@ def unschedule(self):
self.widget.after_cancel(id_)

def show(self):
# if self.text == "":
# return

def tip_pos_calculator(widget, label, tip_delta=(10, 5), pad=(5, 3, 5, 3)):
w = widget

Expand Down Expand Up @@ -365,7 +363,7 @@ class Icon(tk.Label):
"""

def __init__(self, master, images, dynamic=False, *args, **kargs) -> None:
tk.Label.__init__(self, master=master, *args, **kargs)
tk.Label.__init__(self, *args, **kargs, master=master)

# make images a list
if isinstance(images, list):
Expand Down Expand Up @@ -506,7 +504,7 @@ def start_animation(self, frame=None) -> None:
if frame is not None:
self.set_frame(frame)

self._master.after(self._delay, self._animate_GIF)
self._master.after(self._delay, self._animate_gif)
self._is_running = True

def stop_animation(self, frame=None) -> None:
Expand All @@ -523,7 +521,7 @@ def stop_animation(self, frame=None) -> None:

self._is_running = False

def _animate_GIF(self, idx=None):
def _animate_gif(self, idx=None):
"""Callback function for update with after."""
self._loc = (self._loc + 1) % self._last_index
self.update_attached(image=self._frames[self._loc])
Expand All @@ -532,12 +530,12 @@ def _animate_GIF(self, idx=None):
if self._repeat <= 0 or self._count < self._repeat:
if self._repeat > 0:
self._count += 1
self._callback_id = self._master.after(self._delay, self._animate_GIF)
self._callback_id = self._master.after(self._delay, self._animate_gif)
else:
self._callback_id = None
self._is_running = False
else:
self._callback_id = self._master.after(self._delay, self._animate_GIF)
self._callback_id = self._master.after(self._delay, self._animate_gif)


class PopUpMenu(tk.Menu):
Expand Down Expand Up @@ -594,7 +592,7 @@ def clip_generator(to_clip):
https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python.
"""

def clip(event=None):
def clip(event=None): # noqa: ARG001
r = tk.Tk()
r.withdraw()
r.clipboard_clear()
Expand Down
16 changes: 7 additions & 9 deletions wetest/gui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# icons from https://iconmonstr.com/
# gifs from https://ezgif.com/

# Lots of callbacks here
# ruff: noqa: ARG002

import copy
import logging
import multiprocessing
Expand Down Expand Up @@ -391,7 +394,7 @@ def __init__(
close_button = tk.Button(
self.buttons_frame,
text="Quit".center(BT_TXT_LEN),
command=self.quit,
command=self.quit_,
compound="left",
image=self.button_img["quit"],
state="normal",
Expand Down Expand Up @@ -488,7 +491,7 @@ def report(self):
logger.debug("report_path: %s", self.report_path)
subprocess.Popen([self.report_software, self.report_path])

def quit(self):
def quit_(self):
logger.debug("QUIT !")
self.master.destroy()

Expand Down Expand Up @@ -670,7 +673,6 @@ def __init__(

# prepare for status
self.status_frame = tk.Frame(self.top)
# self.status_frame.pack(fill="both", expand=1)
self.status_frame.pack(expand=1)

# display buttons
Expand All @@ -692,7 +694,6 @@ def __init__(
Tooltip(self.ok_button, text="Close PopUp")

# place window
# self.top.minsize(200, 140)
top_x = self.top.winfo_rootx()
if centered:
root_x = self.root.winfo_rootx()
Expand All @@ -701,7 +702,6 @@ def __init__(
root_w = self.root.winfo_width()
position = "+%d+%d" % (root_x + root_w / 2 - top_x / 2, root_y + root_h / 3)
self.top.geometry(position)
# msg.config(wraplength=top_x*0.9)

def add_status(self, status, text=None):
one_status_frame = tk.Frame(self.status_frame)
Expand Down Expand Up @@ -797,7 +797,7 @@ def __init__(self, root, gui, status=None) -> None:
close_button = tk.Button(
self.buttons_frame,
text="Quit".center(BT_TXT_LEN),
command=self.quit,
command=self.quit_,
compound="left",
image=self.gui.button_img["quit"],
)
Expand All @@ -813,7 +813,7 @@ def report(self):
self.gui.report()
self.top.destroy()

def quit(self):
def quit_(self):
"""Close GUI when clicking on close button."""
self.gui.master.destroy()

Expand Down Expand Up @@ -897,8 +897,6 @@ class Object:
"getter": None,
}

# app = GUIGenerator(suite=None, configs=[{'name': "scenario title"}])

GUIGenerator(
master=root,
suite=suite,
Expand Down
35 changes: 15 additions & 20 deletions wetest/gui/specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# - http://www.tcl.tk/man/tcl8.5/TkCmd/colors.htm
# - https://www.color-blindness.com/color-name-hue/

# Lots of callbacks here
# ruff: noqa: ARG002

import contextlib
import logging
Expand Down Expand Up @@ -402,11 +404,11 @@ def __init__(
self.images = self.status_images[self.status]
Icon.__init__(
self,
*args,
**kargs,
master=master,
images=self.images,
dynamic=dynamic,
*args,
**kargs,
)

self.tooltip = Tooltip(self, text=status)
Expand Down Expand Up @@ -578,7 +580,6 @@ def __init__(
options["relief"] = "raised"
if "borderwidth" not in options:
options["borderwidth"] = 1
# tk.Frame.__init__(self, parent, *args, **options)

# configure and display self
tk.Frame.__init__(self, parent, *args, **options)
Expand Down Expand Up @@ -636,7 +637,6 @@ def __init__(
)

# add infos to infos_frame
# infos = infos if infos is not None else [""]
self.infos_label = tk.Label(
self.infos_frame,
text="(i)",
Expand Down Expand Up @@ -849,15 +849,15 @@ def __init__(
# configure and display self
InfosStatusFrame.__init__(
self,
*args,
**options,
parent=parent_widget,
title=title,
infos=build_subtest_desc(st_id, self.test_data),
indent=" " * 6,
status=status,
dynamic=dynamic,
select=select,
*args,
**options,
)

# initalise toogle
Expand Down Expand Up @@ -1045,16 +1045,15 @@ def __init__(
# configure and display self
InfosStatusFrame.__init__(
self,
*args,
**options,
parent=parent_widget,
title="Test: " + title,
infos=infos,
indent=" " * 3,
status=status,
dynamic=dynamic,
*args,
**options,
)
# self.infos_children = self.status_children

# initalise toogle
self.subtests_show = tk.IntVar()
Expand Down Expand Up @@ -1173,11 +1172,11 @@ def check_selection(self):
super().check_selection()
self.parent_scenario.check_selection()

def add_traceback(self, status, id, traceback):
def add_traceback(self, status, id_, traceback):
"""Register the traceback and update status_icon tooltip."""
self.traceback.append(f"{status} {id}: {traceback}")
self.traceback.append(f"{status} {id_}: {traceback}")
self.update_icon_tooltip("\n".join(self.traceback))
self.parent_scenario.add_traceback(status, id, traceback)
self.parent_scenario.add_traceback(status, id_, traceback)


class ScenarioFrame(InfosStatusFrame):
Expand All @@ -1201,15 +1200,14 @@ def __init__(
# configure and display self
InfosStatusFrame.__init__(
self,
*args,
**options,
parent=parent_widget,
title="Scenario: " + title,
infos=infos,
status=status,
dynamic=dynamic,
*args,
**options,
)
# self.infos_children = self.status_children

# set type status
self.test_type_widget = tk.Label(
Expand All @@ -1224,7 +1222,6 @@ def __init__(
pady=PADDING_Y_LABEL,
padx=(PADDING_X_LABEL, 0),
)
# self.infos_label.pack(side="right", padx=(PADDING_X_LABEL,0))

# initalise toogle
self.subtests_show = tk.IntVar()
Expand Down Expand Up @@ -1346,9 +1343,9 @@ def update_status(self) -> None:
self.duration_color = BLACK
self.duration_label.config(fg=self.duration_color)

def add_traceback(self, status, id, traceback):
def add_traceback(self, status, id_, traceback):
"""Register the traceback and update status_icon tooltip."""
self.traceback.append(f"{status} {id}: {traceback}")
self.traceback.append(f"{status} {id_}: {traceback}")
self.update_icon_tooltip("\n".join(self.traceback))


Expand Down Expand Up @@ -1717,7 +1714,6 @@ def refresh_pvs(self):
# add new PVs if necessary or update values and tags
updated_sections = set()
for pv_name, pv in list(update_buffer.items()):
# pv = update_buffer[pv_name]
values = [
"connected" if pv.connected else "unreachable",
len(pv.setter_subtests),
Expand Down Expand Up @@ -1954,7 +1950,6 @@ def apply_selection(self):
"""
output = {SELECTED: [], SKIPPED: []}
for st_id, st in list(self.ids_handle.items()):
# st.select_label.config(state="disable")
if st.selected == SELECTED:
output[SELECTED].append(st_id)
st.reset(status=STATUS_WAIT)
Expand Down
2 changes: 1 addition & 1 deletion wetest/pvs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def register_pvs(self, suite=None, pv_list=None):

return all_connected, self.pvs_refs

def connection_callback(self, pvname=None, conn=None, **kws):
def connection_callback(self, pvname=None, conn=None, **_kws):
"""Update PV status in pvs_refs and put data in queue."""
if not conn:
logger.log(LVL_PV_DISCONNECTED, "PV changed to unreachable: %s", pvname)
Expand Down
6 changes: 3 additions & 3 deletions wetest/pvs/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ParsingError(WeTestError):
"""Failed to parse DB file."""


def parseDbFile(filepath):
def parse_db_file(filepath):
"""Parse the given EPICS DB file to extract records.
Args:
Expand Down Expand Up @@ -126,7 +126,7 @@ def dir2files(dirpath, prefix="", suffix=""):
return found_files


def prettyDict(input_dict, indent=0, print_function=print):
def pretty_dict(input_dict, indent=0, print_function=print):
"""Print a directory."""
for key, value in list(input_dict.items()):
print_function("\t" * indent + str(key) + " :\t" + str(value))
Expand All @@ -152,7 +152,7 @@ def pvs_from_path(path_list):
logger.info("Extracting PVs from DB files.")
for a_file in db_files:
logger.info("Processing file %s", a_file)
pvs_from_db += parseDbFile(a_file)
pvs_from_db += parse_db_file(a_file)

logger.info("Number of records found: %d", len(pvs_from_db))

Expand Down
Loading

0 comments on commit 476bd83

Please sign in to comment.