diff --git a/exe_setup.py b/exe_setup.py index 0d0f791..ed089e6 100644 --- a/exe_setup.py +++ b/exe_setup.py @@ -1,6 +1,6 @@ import sys -from cx_Freeze import Executable, setup # type: ignore +from cx_Freeze import Executable, setup # pyright: ignore[reportMissingTypeStubs, reportUnknownVariableType] build_exe = { "excludes": ["pytest", "PyQt6", "PyQt5", "cv2", "numpy", "mypy", "test", "email", "pydoc_data", "multiprocessing", "rubicon"], diff --git a/src/App.py b/src/App.py index fc94ddc..f76d2bd 100644 --- a/src/App.py +++ b/src/App.py @@ -17,14 +17,14 @@ class App(tkinter.Tk): - def __init__(self): + def __init__(self) -> None: super().__init__() maxWidth = self.winfo_screenwidth() width = 360 height = self.winfo_screenheight() self.geometry(f"{width}x{height}+{maxWidth - width}+0") self.title("AutoSMX") - self.attributes("-topmost", 1) # type: ignore + self.attributes("-topmost", 1) # pyright: ignore self.iconphoto(True, PhotoImage(file=pathlib.Path(_APPLICATION_PATH, "autosmx.png"))) self.columnconfigure(0, weight=1) @@ -50,7 +50,7 @@ def _frame(self) -> ttk.Frame: frame.columnconfigure(3, weight=1) return frame - def change_page(self, page: TPAGES): + def change_page(self, page: TPAGES) -> None: if self.current_page is not None: self.current_page.frame.grid_remove() for widget in self.current_page.frame.winfo_children(): @@ -61,7 +61,7 @@ def change_page(self, page: TPAGES): self.current_page.frame.grid(row=0, column=0, sticky="nsew") -def main(): +def main() -> None: App().mainloop() diff --git a/src/design/Job.py b/src/design/Job.py index 993ad05..e8282a6 100644 --- a/src/design/Job.py +++ b/src/design/Job.py @@ -21,7 +21,7 @@ class Job: tests: list[Test] = field(factory=list, init=False, hash=False, eq=False) test_breakdown: dict[str, int] = field(factory=dict, init=False, hash=False, eq=False) - def add_test(self, test: Test): + def add_test(self, test: Test) -> None: self.tests.append(test) self.test_breakdown[test.script.nickname] = self.test_breakdown.get(test.script.nickname, 0) + 1 diff --git a/src/design/Test.py b/src/design/Test.py index 6a1f523..a7dcb74 100644 --- a/src/design/Test.py +++ b/src/design/Test.py @@ -51,10 +51,10 @@ def determine_script(self) -> Script: raise ScriptError("No script found") - def add_testjob(self, testjob: TestJob): + def add_testjob(self, testjob: TestJob) -> None: self.testjobs.append(testjob) - def complete(self, comment: str, final_result: str, script_answers: list[str]): + def complete(self, comment: str, final_result: str, script_answers: list[str]) -> None: self.script_answers = ["" if a == " " else "N/A" if a == "" else a for a in script_answers] self.comment = comment.strip() self.final_result = final_result diff --git a/src/design/TestJobManager.py b/src/design/TestJobManager.py index 60dfee6..5303725 100644 --- a/src/design/TestJobManager.py +++ b/src/design/TestJobManager.py @@ -4,14 +4,14 @@ class TestJobManager: - def __init__(self): + def __init__(self) -> None: self.job_to_testjobs: dict[Job, list[TestJob]] = {} self.testjob_to_item: dict[TestJob, Item] = {} - def add_testjob(self, item: Item, job: Job, testjob: TestJob): + def add_testjob(self, item: Item, job: Job, testjob: TestJob) -> None: self.job_to_testjobs.setdefault(job, []).append(testjob) self.testjob_to_item[testjob] = item - def delete_testjob(self, job: Job, testjob: TestJob): + def delete_testjob(self, job: Job, testjob: TestJob) -> None: self.job_to_testjobs[job].pop() del self.testjob_to_item[testjob] diff --git a/src/design/__init__.py b/src/design/__init__.py index af5441e..417b0f6 100644 --- a/src/design/__init__.py +++ b/src/design/__init__.py @@ -1,6 +1,6 @@ # pyright: reportUnusedImport=false from design.Script import Script -from design.data import SCRIPTS +from design.data import SCRIPTS, SCRIPT_DOWNS from design.Item import Item from design.Job import Job from design.Test import Test, ScriptError, TEST_RESULTS diff --git a/src/gui/automations.py b/src/gui/automations.py index c3b447d..298f778 100644 --- a/src/gui/automations.py +++ b/src/gui/automations.py @@ -4,7 +4,7 @@ try: import pyautogui - import pyperclip # type: ignore + import pyperclip # pyright: ignore from pynput import mouse except KeyError: pyautogui = None @@ -18,9 +18,9 @@ def _automation_wrapper(default: Any | None = None) -> Callable[[Callable[..., Any]], Any]: # testing decorator for printing, delaying, and returning default values - def decorator(func: Callable[..., Any]): + def decorator(func: Callable[..., Any]): # type: ignore[no-untyped-def] @functools.wraps(func) - def wrapper(*args: Any, **kwargs: Any): + def wrapper(*args: Any, **kwargs: Any) -> Any | None: if _DELAY: pyautogui.sleep(_DELAY) # pyright: ignore[reportOptionalMemberAccess] @@ -36,23 +36,23 @@ def wrapper(*args: Any, **kwargs: Any): @_automation_wrapper() -def click_key(*keys: str, times: int = 1): +def click_key(*keys: str, times: int = 1) -> None: for _ in range(times): pyautogui.hotkey(*keys) # pyright: ignore[reportOptionalMemberAccess] @_automation_wrapper() -def wait(seconds: float): +def wait(seconds: float) -> None: pyautogui.sleep(seconds) # pyright: ignore[reportOptionalMemberAccess] @_automation_wrapper() -def type(text: str): +def type(text: str) -> None: pyautogui.typewrite(text) # pyright: ignore[reportOptionalMemberAccess] @_automation_wrapper() -def click(position: tuple[int, int], /, *, times: int = 1): +def click(position: tuple[int, int], /, *, times: int = 1) -> None: for _ in range(times): pyautogui.click(position) # pyright: ignore[reportOptionalMemberAccess] @@ -61,13 +61,13 @@ def click(position: tuple[int, int], /, *, times: int = 1): def get_click_position() -> tuple[int, int]: position: tuple[int, int] = -1, -1 - def on_click(x: float, y: float, button: mouse.Button, pressed: bool): - if button == mouse.Button.left and pressed: + def on_click(x: float, y: float, button: mouse.Button, pressed: bool) -> Literal[False] | None: # type: ignore + if button == mouse.Button.left and pressed: # pyright: ignore[reportOptionalMemberAccess] nonlocal position position = int(x), int(y) return False - listener = mouse.Listener(on_click=on_click) + listener = mouse.Listener(on_click=on_click) # pyright: ignore listener.start() listener.join() @@ -75,10 +75,10 @@ def on_click(x: float, y: float, button: mouse.Button, pressed: bool): @_automation_wrapper("selected text") -def get_selected_text(): - old = pyperclip.paste() +def get_selected_text() -> str: + old = pyperclip.paste() # pyright: ignore[reportOptionalMemberAccess] pyautogui.hotkey("ctrl" if os.name == "nt" else "command", "c", interval=0.05) # pyright: ignore[reportOptionalMemberAccess] pyautogui.sleep(0.01) # pyright: ignore[reportOptionalMemberAccess] - selected = pyperclip.paste() - pyperclip.copy(old) # type: ignore + selected: str = pyperclip.paste() # pyright: ignore[reportOptionalMemberAccess] + pyperclip.copy(old) # pyright: ignore return selected diff --git a/src/pages/CalibrationPage.py b/src/pages/CalibrationPage.py index ec8810c..8f5cf13 100644 --- a/src/pages/CalibrationPage.py +++ b/src/pages/CalibrationPage.py @@ -7,7 +7,7 @@ class CalibrationPage(Page): - def setup(self): + def setup(self) -> None: if self.shared.storage.calibrated: return self.change_page("JOB") self.positions_set = 0 diff --git a/src/pages/JobPage.py b/src/pages/JobPage.py index 322fbd9..f536283 100644 --- a/src/pages/JobPage.py +++ b/src/pages/JobPage.py @@ -7,7 +7,7 @@ class JobPage(Page): - def setup(self): + def setup(self) -> None: # top row ttk.Label(self.frame, text="Jobs").grid(column=0, row=0, columnspan=1) ttk.Button(self.frame, text="+", width=1, command=self.add_tests).grid(column=1, row=0, columnspan=1) @@ -18,7 +18,7 @@ def setup(self): # tree setup tree = ttk.Treeview(self.frame, columns=("text", "number"), show="tree headings", height=10, selectmode="browse") style = ttk.Style(self.frame) - style.configure("Treeview", rowheight=60) # type: ignore + style.configure("Treeview", rowheight=60) # pyright: ignore tree.column("#0", width=0) tree.column("text", anchor=tkinter.W) tree.column("number", width=10, anchor=tkinter.CENTER) @@ -48,7 +48,7 @@ def setup(self): tree.insert(test_node, tkinter.END, values=(f"{script_name}", value)) # completing tree setup - scrollbar = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore + scrollbar = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore tree.configure(yscroll=scrollbar.set) # type: ignore scrollbar.grid(row=row, column=4, sticky=tkinter.NS) tree.grid(row=row, column=0, columnspan=4, sticky=tkinter.EW) @@ -62,7 +62,7 @@ def setup(self): tree.bind("<>", lambda _: self.on_first_select(tree, button1, button2)) - def on_first_select(self, tree: ttk.Treeview, *buttons: ttk.Button): + def on_first_select(self, tree: ttk.Treeview, *buttons: ttk.Button) -> None: for button in buttons: button.configure(state="normal") tree.unbind("<>") diff --git a/src/pages/Page.py b/src/pages/Page.py index c7eca13..4612d3f 100644 --- a/src/pages/Page.py +++ b/src/pages/Page.py @@ -26,5 +26,5 @@ def __init__(self, frame: ttk.Frame, change_page: Callable[[TPAGES], None], shar self.shared = shared @abstractmethod - def setup(self): + def setup(self) -> None: ... diff --git a/src/pages/TestPage.py b/src/pages/TestPage.py index ff0acdb..39d448b 100644 --- a/src/pages/TestPage.py +++ b/src/pages/TestPage.py @@ -18,7 +18,7 @@ class TestPage(Page): - def setup(self): + def setup(self) -> None: ttk.Button(self.frame, text="< Jobs", command=lambda: self.change_page("JOB")).grid(column=0, row=0, sticky="w") ttk.Label(self.frame, text="Item Number").grid(column=0, row=1, columnspan=2) @@ -38,12 +38,12 @@ def setup(self): item_number.trace_add("write", lambda _, __, ___: self.edit_button_reconfigure(item_number)) - def edit_button_reconfigure(self, item_number: StringVar): + def edit_button_reconfigure(self, item_number: StringVar) -> None: tested = item_number.get() in self.shared.item_number_to_description self.edit_button.configure(state=("normal" if tested else "disabled")) def get_items(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script: bool = False, editing: bool = False) -> None: - item_entry.state(["disabled"]) # type: ignore + item_entry.state(["disabled"]) # pyright: ignore self.frame.focus() assert self.shared.job @@ -81,7 +81,7 @@ def get_test(self, item: Item, *, choose_script: bool = False) -> None: script_popup.protocol("WM_DELETE_WINDOW", lambda: self.reset_page(item.number)) script_popup.mainloop() - def display_test(self, script: Script, test: Test): + def display_test(self, script: Script, test: Test) -> None: test.script = script self.test = test self.choose_button.destroy() @@ -157,19 +157,19 @@ def display_test(self, script: Script, test: Test): save.bind("", lambda _: self.save_test([s.get() for s in actual_answers], result.get())) row += 1 - def add_testjob(self): + def add_testjob(self) -> None: assert self.shared.job is not None testjob_popup = TestJobPopup(self.frame, self.shared.job.department, self.shared.job.company, self.save_testjob) testjob_popup.mainloop() - def save_testjob(self, testjob: TestJob): + def save_testjob(self, testjob: TestJob) -> None: self.comment.insert(tkinter.END, testjob.test_comment + "\n\n") self.test.add_testjob(testjob) self.shared.testjob_manager.add_testjob(self.test.item, cast(Job, self.shared.job), testjob) self.add_job_button.configure(text=f"Add Job ({len(self.test.testjobs)})") self.delete_job_button.grid(column=3, row=self.add_job_button.grid_info()["row"], sticky="e") - def delete_test_job(self): + def delete_test_job(self) -> None: testjob = self.test.testjobs.pop() self.shared.testjob_manager.delete_testjob(cast(Job, self.shared.job), testjob) current_comment = self.comment.get("1.0", tkinter.END).strip() @@ -183,7 +183,7 @@ def delete_test_job(self): add_job_text += f" ({len(self.test.testjobs)})" self.add_job_button.configure(text=add_job_text) - def save_test(self, script_answers: list[str], result: str): + def save_test(self, script_answers: list[str], result: str) -> None: assert self.shared.job # must have created a job by now turn_off_capslock() comment = self.comment.get("1.0", tkinter.END) @@ -214,7 +214,7 @@ def reset_page(self, item_number: str) -> None: self.shared.previous_item_number = item_number self.change_page("TEST") - def update_storage(self, actual_script_answers: list[str]): + def update_storage(self, actual_script_answers: list[str]) -> None: if self.saved_script_answers == actual_script_answers: return @@ -226,9 +226,9 @@ def update_storage(self, actual_script_answers: list[str]): storage.item_model_to_script_answers[self.test.item_model] = actual_script_answers def failsafe(self, current_item_number: str) -> None: - messagebox.showerror("Process Aborted", "Fail safe activated") # type: ignore + messagebox.showerror("Process Aborted", "Fail safe activated") # pyright: ignore self.reset_page(current_item_number) def item_not_found(self, current_item_number: str) -> None: - messagebox.showerror("Not Found", f"Item number '{current_item_number}' not tested yet") # type: ignore + messagebox.showerror("Not Found", f"Item number '{current_item_number}' not tested yet") # pyright: ignore self.reset_page(current_item_number) diff --git a/src/pages/TutorialPage.py b/src/pages/TutorialPage.py index 548a3a0..02044ea 100644 --- a/src/pages/TutorialPage.py +++ b/src/pages/TutorialPage.py @@ -53,7 +53,7 @@ class TutorialPage(Page): - def setup(self): + def setup(self) -> None: if self.shared.storage.tutorial_complete: return self.change_page("CALIBRATION") @@ -65,7 +65,7 @@ def setup(self): # tree setup tree = ttk.Treeview(self.frame, columns=("#1"), show="tree", height=15, selectmode=tkinter.NONE) style = ttk.Style(self.frame) - style.configure("Treeview", rowheight=60) # type: ignore + style.configure("Treeview", rowheight=60) # pyright: ignore[reportUnknownMemberType] tree.column("#0", width=0) column = tree.column(tree["columns"][0]) assert column @@ -79,12 +79,12 @@ def setup(self): text.write(line + ("\n" if i != len(group) - 1 else "")) tree.insert(section_node, tkinter.END, values=(text.getvalue(),)) - scrollbar_y = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore + scrollbar_y = ttk.Scrollbar(self.frame, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore tree.configure(yscroll=scrollbar_y.set) # type: ignore scrollbar_y.grid(row=2, column=4, sticky=tkinter.NS) tree.grid(row=2, column=0, columnspan=4, sticky=tkinter.EW) - def adjust_newlines(self, val: str, width: int): + def adjust_newlines(self, val: str, width: int) -> list[str]: font = Font(font="TkDefaultFont") words = val.split() lines: list[str] = [""] @@ -97,7 +97,7 @@ def adjust_newlines(self, val: str, width: int): return lines - def end_tutorial(self): + def end_tutorial(self) -> None: with self.shared.storage.edit() as storage: storage.tutorial_complete = True self.change_page("CALIBRATION") diff --git a/src/popups/CalibrationHelpPopup.py b/src/popups/CalibrationHelpPopup.py index 47447c7..5e0741b 100644 --- a/src/popups/CalibrationHelpPopup.py +++ b/src/popups/CalibrationHelpPopup.py @@ -16,8 +16,8 @@ def __init__(self, master: Misc | None, image_name: str): img = Image.open(f"{_APPLICATION_PATH}/img/{image_name}.png") img = img.resize((width, 500), resample=Image.LANCZOS) - img = ImageTk.PhotoImage(img) # type: ignore - panel = ttk.Label(self, image=img) # type: ignore + img = ImageTk.PhotoImage(img) + panel = ttk.Label(self, image=img) panel.image = img # type: ignore panel.grid(column=0, row=0, sticky="nsew") diff --git a/src/popups/OptionSelectPopup.py b/src/popups/OptionSelectPopup.py index 86f39df..1e4f9fd 100644 --- a/src/popups/OptionSelectPopup.py +++ b/src/popups/OptionSelectPopup.py @@ -15,7 +15,7 @@ def __init__(self, master: Misc | None, options: list[_T], callback: Callable[[_ for row, option in enumerate(options): tree.insert("", tkinter.END, f"{row}", text=display(option), open=row == 0) - scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore + scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] tree.configure(yscroll=scrollbar.set) # type: ignore scrollbar.grid(row=0, column=2, sticky=tkinter.NS) tree.grid(row=0, column=0, columnspan=2, sticky=tkinter.EW) diff --git a/src/popups/Popup.py b/src/popups/Popup.py index 7244c60..3ede7f8 100644 --- a/src/popups/Popup.py +++ b/src/popups/Popup.py @@ -12,11 +12,11 @@ def __init__(self, master: tkinter.Misc | None, title: str, /, *, width: int = 3 start_height = (max_height - height) // 2 self.geometry(f"{width}x{height}+{max_width - width}+{start_height}") - self.attributes("-topmost", 2) # type: ignore + self.attributes("-topmost", 2) # pyright: ignore self.resizable(False, False) for i in range(columns): self.columnconfigure(i, weight=1) - def grid_remove(self): # ensure it gets cleaned up + def grid_remove(self) -> None: # ensure it gets cleaned up self.destroy() diff --git a/src/popups/ScriptSelectionPopup.py b/src/popups/ScriptSelectionPopup.py index 8e0c53c..28ea75f 100644 --- a/src/popups/ScriptSelectionPopup.py +++ b/src/popups/ScriptSelectionPopup.py @@ -7,12 +7,12 @@ class ScriptSelectionPopup(Popup): - def __init__(self, master: Misc | None, master_select_script: Callable[[Script], None]): + def __init__(self, master: Misc | None, master_select_script: Callable[[Script], None]) -> None: super().__init__(master, "Select Script", columns=2) self.master_select_script = master_select_script for i, script in enumerate(SCRIPTS.values()): ttk.Button(self, text=script.name, command=lambda script=script: self._select_script(script)).grid(column=0, row=i, columnspan=2, sticky="w") # type: ignore[misc] - def _select_script(self, script: Script): + def _select_script(self, script: Script) -> None: self.master_select_script(script) self.destroy() diff --git a/src/popups/TestJobPopup.py b/src/popups/TestJobPopup.py index 77a7489..064d5cc 100644 --- a/src/popups/TestJobPopup.py +++ b/src/popups/TestJobPopup.py @@ -25,6 +25,6 @@ def __init__(self, master: Misc | None, default_dept: str, default_contact: str, ttk.Button(self, text="Save", command=lambda: self._save_testjob(department.get(), contact.get(), comment.get("1.0", END))).grid(column=0, row=4, columnspan=2) - def _save_testjob(self, department: str, contact: str, comment: str): + def _save_testjob(self, department: str, contact: str, comment: str) -> None: self.master_save_testjob(TestJob(department, contact, comment)) self.destroy() diff --git a/src/storage/Storage.py b/src/storage/Storage.py index 52c638b..3f9a6b1 100644 --- a/src/storage/Storage.py +++ b/src/storage/Storage.py @@ -1,13 +1,14 @@ import json +from collections.abc import KeysView from contextlib import contextmanager from pathlib import Path -from typing import Mapping, Sequence +from typing import Any, Generator, Mapping, cast from attrs import asdict, define, field -def _tuple_converter(value: Sequence[int] | None) -> tuple[int, ...] | None: - return tuple(value) if value is not None else value +def _tuple_converter(value: tuple[int, int] | None) -> tuple[int, int] | None: + return cast(tuple[int, int], tuple(value)) if value is not None else value @define(repr=False, eq=False) @@ -21,11 +22,11 @@ class Positions: sm_incident_tab: tuple[int, int] | None = field(default=None, converter=_tuple_converter) @classmethod - def keys(cls): + def keys(cls) -> KeysView[Any]: return cls.__annotations__.keys() @classmethod - def from_dict(cls, data: Mapping[str, Sequence[int]]): + def from_dict(cls, data: Mapping[str, tuple[int, int]]) -> 'Positions': return cls(**data) @@ -60,7 +61,7 @@ def _save(self) -> None: json.dump(data, file, indent=4) @contextmanager - def edit(self): + def edit(self) -> Generator['Storage', None, None]: try: yield self finally: diff --git a/testing/design/test_item.py b/testing/design/test_item.py index 498a87b..a42ecef 100644 --- a/testing/design/test_item.py +++ b/testing/design/test_item.py @@ -2,7 +2,7 @@ from design.Item import Item -def test_item_creation_and_properties(): +def test_item_creation_and_properties() -> None: item = Item("123", "Test Item", "Model123", "Test Manufacturer", "ABC456", "RM1", "2019") assert item.number == "123" @@ -14,13 +14,13 @@ def test_item_creation_and_properties(): assert item.last_update == "2019" -def test_item_string_representation(): +def test_item_string_representation() -> None: item = Item("789", "Another Item", "Model789", "Another Manufacturer", "DEF789", "RM1", "2019") assert str(item) == "789 - Another Item" -def test_item_hashing_and_eq(): +def test_item_hashing_and_eq() -> None: item1 = Item("111", "Item A", "ModelA", "ManufacturerA", "AAA111", "RM1", "2019") item2 = Item("222", "Item B", "ModelB", "ManufacturerB", "BBB222", "RM1", "2019") item3 = Item("111", "Item C", "ModelC", "ManufacturerC", "CCC333", "RM1", "2019") diff --git a/testing/design/test_job.py b/testing/design/test_job.py index 7bf7bbc..15e4e88 100644 --- a/testing/design/test_job.py +++ b/testing/design/test_job.py @@ -7,7 +7,7 @@ Test.__test__ = False # type: ignore -def test_job_creation_and_properties(): +def test_job_creation_and_properties() -> None: job = Job("CAMPEYN - ABLE VICTORIA", "CampusA", "DepartmentY", "123") assert job.company == "ABLE" @@ -16,7 +16,7 @@ def test_job_creation_and_properties(): assert len(job.tests) == 0 -def test_job_add_test(): +def test_job_add_test() -> None: job = Job("CompanyX", "CampusA", "DepartmentY", "123") test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019")) @@ -53,8 +53,7 @@ def test_job_remove_test() -> None: assert "Custom1" not in job.test_breakdown - -def test_job_string_representation(): +def test_job_string_representation() -> None: job1 = Job("CAMPEYN - YOORALLA", "CampusA", "DepartmentY", "123") job2 = Job("BENETAS - ST PAULS", "CampusA", "DepartmentY", "123") job3 = Job("JEWISH ST KILDA", "CampusA", "DepartmentY", "123") @@ -64,7 +63,7 @@ def test_job_string_representation(): assert str(job3) == "CampusA\nJEWISH CARE\n123" -def test_job_hashing_and_eq(): +def test_job_hashing_and_eq() -> None: job1 = Job("CompanyX", "CampusA", "DepartmentY", "123") job2 = Job("CompanyY", "CampusB", "DepartmentZ", "123") job3 = Job("CompanyZ", "CampusA", "DepartmentZ", "123") diff --git a/testing/design/test_script.py b/testing/design/test_script.py index 46215c7..bf297f1 100644 --- a/testing/design/test_script.py +++ b/testing/design/test_script.py @@ -4,7 +4,7 @@ from design.Script import Script, ScriptTest -def test_script_creation(): +def test_script_creation() -> None: script = Script("Nick", "Script Name") assert script.nickname == "Nick" assert script.name == "Script Name" @@ -12,7 +12,7 @@ def test_script_creation(): assert script.search_terms == ["Nick"] -def test_script_creation_with_tests(): +def test_script_creation_with_tests() -> None: test1 = ScriptTest("Test 1", "Pass", "Fail") test2 = ScriptTest("Test 2", "N/A", "Yes", "No") script = Script("Nickname", "Test Script", (test1, test2)) @@ -22,7 +22,7 @@ def test_script_creation_with_tests(): assert script.search_terms == ["Nickname"] -def test_script_creation_with_extra_terms(): +def test_script_creation_with_extra_terms() -> None: script = Script("UniqueNick", "Unique Script", search_terms=["tag1", "tag2"]) assert script.nickname == "UniqueNick" assert script.name == "Unique Script" @@ -40,17 +40,17 @@ def test_script_creation_with_extra_terms(): ("Different", False), ], ) -def test_script_matches(match_description: str, expected: bool): +def test_script_matches(match_description: str, expected: bool) -> None: script = Script("Tester", "Matching Script", search_terms=["tag3"]) assert script.is_for(match_description) == expected -def test_script_to_string(): +def test_script_to_string() -> None: script = Script("MyNick", "Awesome Script") assert str(script) == "Awesome Script" -def test_hash_and_eq(): +def test_hash_and_eq() -> None: script1 = Script("Nick1", "Script 1") script2 = Script("Nick2", "Script 2") script3 = Script("Nick3", "Script 1") diff --git a/testing/design/test_script_test.py b/testing/design/test_script_test.py index 6207e21..92daeb1 100644 --- a/testing/design/test_script_test.py +++ b/testing/design/test_script_test.py @@ -1,28 +1,28 @@ from design.Script import ScriptTest -def test_script_test_creation(): +def test_script_test_creation() -> None: test = ScriptTest("Test Name") assert test.name == "Test Name" assert test.selected == "" assert test.options == [] -def test_script_test_with_options(): +def test_script_test_with_options() -> None: test = ScriptTest("Test Name", "Fail", "Pass", "N/A") assert test.name == "Test Name" assert test.selected == "Fail" assert test.options == ["Pass", "N/A", "Fail"] -def test_script_test_with_no_options(): +def test_script_test_with_no_options() -> None: test = ScriptTest("Another Test") assert test.name == "Another Test" assert test.selected == "" assert test.options == [] -def test_script_test_sorting(): +def test_script_test_sorting() -> None: test = ScriptTest("Sorting Test", "1", "Pass", "0", "N/A", " ") assert test.name == "Sorting Test" assert test.selected == "1" diff --git a/testing/design/test_test.py b/testing/design/test_test.py index 81d2124..a42a0ac 100644 --- a/testing/design/test_test.py +++ b/testing/design/test_test.py @@ -10,7 +10,7 @@ TestJob.__test__ = False # type: ignore -def test_test_creation_and_properties(): +def test_test_creation_and_properties() -> None: item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) @@ -24,7 +24,7 @@ def test_test_creation_and_properties(): assert test.final_result == "" -def test_test_determine_script(): +def test_test_determine_script() -> None: item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) @@ -39,7 +39,7 @@ def test_test_determine_script(): assert test.item_model == "Custom Script -> ModelX" -def test_test_add_testjob(): +def test_test_add_testjob() -> None: item = Item("001", "SLING 123", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) @@ -53,7 +53,7 @@ def test_test_add_testjob(): assert test.testjobs[0] == testjob -def test_test_complete_and_full_info(): +def test_test_complete_and_full_info() -> None: item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) @@ -73,7 +73,7 @@ def test_test_complete_and_full_info(): assert str(test) == "001 - Test Item - Pass" -def test_test_item_model_property(): +def test_test_item_model_property() -> None: item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) test.script = Script("CustomScript", "Custom Script") diff --git a/testing/design/test_test_job.py b/testing/design/test_test_job.py index 0c9f037..3371439 100644 --- a/testing/design/test_test_job.py +++ b/testing/design/test_test_job.py @@ -5,7 +5,7 @@ TestJob.__test__ = False # type: ignore -def test_test_job_creation_and_string_representation(): +def test_test_job_creation_and_string_representation() -> None: test_job = TestJob("Quality Control", "John Doe", "Performing\ntesting on\nnew batch.") assert test_job.department == "Quality Control" @@ -18,7 +18,7 @@ def test_test_job_creation_and_string_representation(): @pytest.mark.parametrize("comment", ("C\nD\nE\n1 X 12345\n", "C\nD\nE\n1 x 12345\n\n")) -def test_test_job_test_comment(comment: str): +def test_test_job_test_comment(comment: str) -> None: test_job = TestJob("A", "B", comment) assert test_job.comment == comment.strip() @@ -28,7 +28,7 @@ def test_test_job_test_comment(comment: str): @pytest.mark.parametrize("comment", ("C\nD\nE\na X 12345\n ", "C\nD\nE\n2 a 12345 \n")) -def test_test_job_invalid_last_line(comment: str): +def test_test_job_invalid_last_line(comment: str) -> None: test_job = TestJob("A", "B", comment) assert test_job.comment == test_job.test_comment == comment.strip() diff --git a/testing/design/test_test_job_manager.py b/testing/design/test_test_job_manager.py index fedde05..83ce627 100644 --- a/testing/design/test_test_job_manager.py +++ b/testing/design/test_test_job_manager.py @@ -7,7 +7,7 @@ TestJobManager.__test__ = False # type: ignore -def test_test_job_manager_multiple_testjobs(): +def test_test_job_manager_multiple_testjobs() -> None: manager = TestJobManager() item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "R1", "2019") @@ -28,7 +28,7 @@ def test_test_job_manager_multiple_testjobs(): assert manager.testjob_to_item[testjob2] == item1 -def test_test_job_manager_multiple_items(): +def test_test_job_manager_multiple_items() -> None: manager = TestJobManager() item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") diff --git a/testing/storage/test_positions.py b/testing/storage/test_positions.py index e7c04ff..ba778d4 100644 --- a/testing/storage/test_positions.py +++ b/testing/storage/test_positions.py @@ -2,10 +2,18 @@ from storage.Storage import Positions -_POSITIONS_DATA: dict[str, tuple[int, int]] = {"testing_tab": (1, 2), "assets_tab": (3, 4), "show_all_script": (5, 6), "comment_box": (7, 8), "window": (9, 10), "track_weight_field": (11, 12), "sm_incident_tab": (13, 14)} - - -def test_positions_initialization(): +_POSITIONS_DATA: dict[str, tuple[int, int]] = { + "testing_tab": (1, 2), + "assets_tab": (3, 4), + "show_all_script": (5, 6), + "comment_box": (7, 8), + "window": (9, 10), + "track_weight_field": (11, 12), + "sm_incident_tab": (13, 14), +} + + +def test_positions_initialization() -> None: positions = Positions(**_POSITIONS_DATA) assert positions.testing_tab == (1, 2) assert positions.assets_tab == (3, 4) @@ -16,7 +24,7 @@ def test_positions_initialization(): assert positions.sm_incident_tab == (13, 14) -def test_positions_from_dict(): +def test_positions_from_dict() -> None: positions = Positions.from_dict(_POSITIONS_DATA) assert positions.testing_tab == (1, 2) assert positions.assets_tab == (3, 4) @@ -27,12 +35,12 @@ def test_positions_from_dict(): assert positions.sm_incident_tab == (13, 14) -def test_positions_keys(): +def test_positions_keys() -> None: expected_keys = {"testing_tab", "assets_tab", "show_all_script", "comment_box", "window", "track_weight_field", "sm_incident_tab"} assert set(Positions.keys()) == expected_keys -def test_positions_slots(): +def test_positions_slots() -> None: positions = Positions(**_POSITIONS_DATA) with pytest.raises(AttributeError): positions.x = 1 # type: ignore diff --git a/testing/storage/test_storage.py b/testing/storage/test_storage.py index 784e8a3..8f5837b 100644 --- a/testing/storage/test_storage.py +++ b/testing/storage/test_storage.py @@ -1,10 +1,10 @@ import json import os -from typing import Any, Callable, cast +from typing import Any, Callable, Generator, cast import pytest -from storage import Positions, Storage # type: ignore +from storage import Positions, Storage # type: ignore _EMPTY_DATA: dict[str, Any] = { "total_tests": 0, @@ -25,12 +25,12 @@ @pytest.fixture -def get_file_for_testing(): +def get_file_for_testing() -> Generator[Callable[..., str], None, None]: original_file_content: dict[str, Any] | str = {} file_name = "" file_exists = True - def _get_file(name: str): + def _get_file(name: str) -> str: name = f"testing/storage/{name}" nonlocal file_name file_name = name @@ -52,14 +52,14 @@ def _get_file(name: str): if not file_exists: return os.remove(file_name) with open(file_name, "w") as file: - if isinstance(original_file_content, dict): # type: ignore + if isinstance(original_file_content, dict): # pyright: ignore[reportUnnecessaryIsInstance] json.dump(original_file_content, file, indent=4) else: file.write(original_file_content) @pytest.mark.parametrize("file_name", ["empty.json", "storage.json", "invalid.json", "missing.json"]) -def test_empty_missing_invalid_json(file_name: str, get_file_for_testing: Callable[[str], str]): +def test_empty_missing_invalid_json(file_name: str, get_file_for_testing: Callable[[str], str]) -> None: file_name = get_file_for_testing(file_name) _EMPTY_DATA["_json_file_path"] = file_name storage = Storage(file_name) @@ -76,7 +76,7 @@ def test_empty_missing_invalid_json(file_name: str, get_file_for_testing: Callab assert data == _EMPTY_DATA -def test_storage_edit_and_save(get_file_for_testing: Callable[[str], str]): +def test_storage_edit_and_save(get_file_for_testing: Callable[[str], str]) -> None: file = get_file_for_testing("storage.json") storage = Storage(file) @@ -105,7 +105,7 @@ def test_storage_edit_and_save(get_file_for_testing: Callable[[str], str]): "comment_box": [4, 4], "window": [5, 5], "track_weight_field": [6, 6], - "sm_incident_tab": [7, 7] + "sm_incident_tab": [7, 7], } assert data["calibrated"] assert data["tutorial_complete"]