From 9b60d0af08b53c3c60126f7ef8b0d88265a80390 Mon Sep 17 00:00:00 2001 From: Ajimaru Date: Wed, 2 Dec 2026 13:04:34 +0100 Subject: [PATCH] chore: add pre-commit configuration and various linting settings for improved code quality --- .djlintrc | 6 ++ .editorconfig | 5 -- .github/workflows/ci.yml | 65 +++++++------------ .isort.cfg | 5 ++ .pre-commit-config.yaml | 48 ++++++++++++++ .prettierignore | 12 ++++ .prettierrc.yaml | 12 ++++ README.md | 4 +- octoprint_autoconnectplus/__init__.py | 51 +++++---------- .../static/js/autoconnectplus.js | 8 ++- .../templates/autoconnectplus_settings.jinja2 | 27 ++++---- pyproject.toml | 23 +------ ruff.toml | 28 ++++++++ tests/test_import_guard.py | 4 +- tests/test_plugin.py | 49 ++++---------- 15 files changed, 189 insertions(+), 158 deletions(-) create mode 100644 .djlintrc create mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml create mode 100644 .prettierignore create mode 100644 .prettierrc.yaml create mode 100644 ruff.toml diff --git a/.djlintrc b/.djlintrc new file mode 100644 index 0000000..84e566f --- /dev/null +++ b/.djlintrc @@ -0,0 +1,6 @@ +{ + "profile": "jinja", + "ignore": "H005,H007,H013,H019,H020,H021,H023,H026,H030,H036,H043,H047,H050,J018,T002", + "max_blank_lines": 1, + "use_gitignore": true +} diff --git a/.editorconfig b/.editorconfig index ad4ec7d..e7be252 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,11 +11,6 @@ insert_final_newline = true trim_trailing_whitespace = true max_line_length = 90 -# Python stays at 88 (black/isort default) until the linters move to 90 too; -# isort reads this value. -[*.py] -max_line_length = 88 - [*.{yml,yaml,json,less,md}] indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3be6e1..effce84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ env: TEST_DEPS: "" TEST_PATH: "" # "pre-commit" once the repo has a hook config, else "ruff" with RUFF_ARGS. - LINT: ruff + LINT: pre-commit RUFF_ARGS: "" # setup.py imports octoprint_setuptools, so those builds need OctoPrint installed. BUILD_ARGS: "" @@ -36,26 +36,6 @@ jobs: with: python-version: "3.13" - # Hooks with `language: system` need the node packages and ShellCheck 0.11. - - name: Set up Node.js - if: env.LINT == 'pre-commit' && hashFiles('package.json') != '' - uses: actions/setup-node@v7 - with: - node-version: "22" - - - name: Install node packages - if: env.LINT == 'pre-commit' && hashFiles('package.json') != '' - run: | - if [ -f package-lock.json ]; then npm ci --no-audit --no-fund - else npm install --no-audit --no-fund; fi - - - name: Install ShellCheck - if: env.LINT == 'pre-commit' && hashFiles('.githooks/shellcheck-hook.sh') != '' - run: | - url=https://github.com/koalaman/shellcheck/releases/download/v0.11.0/shellcheck-v0.11.0.linux.x86_64.tar.xz - curl -fsSL "$url" | tar -xJ -C "$RUNNER_TEMP" - sudo install "$RUNNER_TEMP/shellcheck-v0.11.0/shellcheck" /usr/local/bin/shellcheck - - name: Cache pre-commit hook environments if: env.LINT == 'pre-commit' uses: actions/cache@v6 @@ -65,9 +45,6 @@ jobs: - name: Run pre-commit if: env.LINT == 'pre-commit' - # The translations hook needs a local venv; the Translations job covers it. - env: - SKIP: check-translations run: | python -m pip install pre-commit pre-commit run --all-files --show-diff-on-failure @@ -88,20 +65,20 @@ jobs: matrix: include: # Every Python version each OctoPrint generation supports. - - { octoprint: "1.x", python: "3.9", runner: ubuntu-24.04 } - - { octoprint: "1.x", python: "3.10", runner: ubuntu-latest } - - { octoprint: "1.x", python: "3.11", runner: ubuntu-latest } - - { octoprint: "1.x", python: "3.12", runner: ubuntu-latest } - - { octoprint: "1.x", python: "3.13", runner: ubuntu-latest } - - { octoprint: "2.x", python: "3.9", runner: ubuntu-24.04 } - - { octoprint: "2.x", python: "3.10", runner: ubuntu-latest } - - { octoprint: "2.x", python: "3.11", runner: ubuntu-latest } - - { octoprint: "2.x", python: "3.12", runner: ubuntu-latest } - - { octoprint: "2.x", python: "3.13", runner: ubuntu-latest, coverage: true } - - { octoprint: "2.x", python: "3.14", runner: ubuntu-latest } - - { octoprint: "2.x", python: "3.15", runner: ubuntu-latest } + - {octoprint: "1.x", python: "3.9", runner: ubuntu-24.04} + - {octoprint: "1.x", python: "3.10", runner: ubuntu-latest} + - {octoprint: "1.x", python: "3.11", runner: ubuntu-latest} + - {octoprint: "1.x", python: "3.12", runner: ubuntu-latest} + - {octoprint: "1.x", python: "3.13", runner: ubuntu-latest} + - {octoprint: "2.x", python: "3.9", runner: ubuntu-24.04} + - {octoprint: "2.x", python: "3.10", runner: ubuntu-latest} + - {octoprint: "2.x", python: "3.11", runner: ubuntu-latest} + - {octoprint: "2.x", python: "3.12", runner: ubuntu-latest} + - {octoprint: "2.x", python: "3.13", runner: ubuntu-latest, coverage: true} + - {octoprint: "2.x", python: "3.14", runner: ubuntu-latest} + - {octoprint: "2.x", python: "3.15", runner: ubuntu-latest} env: - CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_API_TOKEN }} + CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }} steps: - uses: actions/checkout@v7 @@ -141,9 +118,15 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: false - # Skipped until the repo has a CODACY_API_TOKEN secret. + # Needs the Codacy account API token as CODACY_API_TOKEN; skipped without it. + # Like Codecov, a failed upload must not turn a passing test run red. - name: Upload coverage to Codacy - if: matrix.coverage && env.CODACY_PROJECT_TOKEN != '' + if: matrix.coverage && env.CODACY_API_TOKEN != '' + continue-on-error: true + env: + CODACY_ORGANIZATION_PROVIDER: gh + CODACY_USERNAME: ${{ github.repository_owner }} + CODACY_PROJECT_NAME: ${{ github.event.repository.name }} run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.xml build: @@ -153,8 +136,8 @@ jobs: fail-fast: false matrix: include: - - { octoprint: "1.x", python: "3.9", runner: ubuntu-24.04, disabled: false } - - { octoprint: "2.x", python: "3.13", runner: ubuntu-latest, disabled: false } + - {octoprint: "1.x", python: "3.9", runner: ubuntu-24.04, disabled: false} + - {octoprint: "2.x", python: "3.13", runner: ubuntu-latest, disabled: false} steps: - uses: actions/checkout@v7 diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..b4a0b9c --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,5 @@ +# Import order shared by all plugin repos; compatible with ruff format. +[settings] +profile = black +line_length = 90 +extend_skip_glob = **/vendor/*,3rdPartySoftware/*,archive/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4a4cbd3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,48 @@ +# Same hooks in every plugin repo, following OctoPrint core's setup. +# Set up once with `pre-commit install`; CI runs them on every push. +exclude: (^|/)(translations|vendor)/|^(docs|scripts|archive|3rdPartySoftware)/|\.(css|svg|map|gcode)$|\.min\.js$ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict + - id: check-json + - id: check-yaml + # mkdocs.yml uses custom tags; only the syntax is checked. + args: [--unsafe] + - id: check-toml + - id: check-merge-conflict + - repo: https://github.com/PyCQA/isort + rev: 9.0.2 + hooks: + - id: isort + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.17.6 + hooks: + - id: ruff-check + args: [--fix] + - id: ruff-format + - repo: https://github.com/djlint/djlint + rev: v1.54.2 + hooks: + - id: djlint-reformat-jinja + - id: djlint-jinja + - repo: https://github.com/rbubley/mirrors-prettier + rev: v3.10.1 + hooks: + - id: prettier + files: \.(js|json|less|ya?ml)$ + - repo: https://github.com/codespell-project/codespell + rev: v2.4.3 + hooks: + - id: codespell + # Identifiers, config keys and product names, not typos. + args: + - --ignore-words-list + - commitish,offsetp,colorfull,basf,paht,sme,unparseable,pre-selected + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.11.0.1-1 + hooks: + - id: shellcheck diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..5b11dbf --- /dev/null +++ b/.prettierignore @@ -0,0 +1,12 @@ +# Same scope as the prettier hook in .pre-commit-config.yaml. +*.md +*.css +*.min.js +**/package.json +**/package-lock.json +**/translations/ +**/vendor/ +docs/ +scripts/ +archive/ +3rdPartySoftware/ diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..b677871 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,12 @@ +# Prettier settings shared by all plugin repos, taken from OctoPrint core. +printWidth: 90 +tabWidth: 4 +semi: true +trailingComma: "none" +singleQuote: false +quoteProps: consistent +bracketSpacing: false +overrides: + - files: ["*.yaml", "*.yml", "*.json", "*.less"] + options: + tabWidth: 2 diff --git a/README.md b/README.md index 5bcdd37..2412277 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,9 @@ git clone https://github.com/ajimaru/OctoPrint-AutoConnectPlus.git cd OctoPrint-AutoConnectPlus python -m venv .venv && source .venv/bin/activate pip install "OctoPrint>=1.11" -e ".[dev]" +pre-commit install # lint and format hooks, the same ones CI runs -pytest # run the unit tests -ruff check . # lint +pytest # run the unit tests ``` The tests mock OctoPrint's printer and the connector framework, so they run against diff --git a/octoprint_autoconnectplus/__init__.py b/octoprint_autoconnectplus/__init__.py index 4a04a12..c7bb7d2 100644 --- a/octoprint_autoconnectplus/__init__.py +++ b/octoprint_autoconnectplus/__init__.py @@ -299,9 +299,7 @@ def do_auto_connect(self): if attempted: self._register_failure() except Exception: # pylint: disable=broad-exception-caught - self._logger.error( - f"Exception in do_auto_connect {get_exception_string()}" - ) + self._logger.error(f"Exception in do_auto_connect {get_exception_string()}") self._register_failure() def _connect_serial(self, profile: str) -> bool: @@ -315,9 +313,7 @@ def _connect_serial(self, profile: str) -> bool: self._logger.debug(f"Port {port} not present yet, waiting") return False - self._logger.info( - f"Attempting to connect to {port} with profile {profile}" - ) + self._logger.info(f"Attempting to connect to {port} with profile {profile}") self._printer.connect(port=port, profile=profile) return True @@ -379,8 +375,7 @@ def _connect_connector(self, connector: str, profile: str) -> bool: return False except Exception: # pylint: disable=broad-exception-caught self._logger.debug( - f"Precondition check for '{connector}' raised, " - f"attempting connect anyway" + f"Precondition check for '{connector}' raised, attempting connect anyway" ) # Connector preconditions only resolve the hostname, so a literal IP @@ -388,17 +383,13 @@ def _connect_connector(self, connector: str, profile: str) -> bool: # with "No route to host". Probe the TCP port first and just wait if # unreachable, keeping the retry quiet. if not self._host_reachable(connector, parameters): - self._logger.debug( - f"Host for '{connector}' not reachable yet, waiting" - ) + self._logger.debug(f"Host for '{connector}' not reachable yet, waiting") return False self._logger.info( f"Attempting to connect via '{connector}' with profile {profile}" ) - self._printer.connect( - connector=connector, parameters=parameters, profile=profile - ) + self._printer.connect(connector=connector, parameters=parameters, profile=profile) return True def _host_reachable(self, connector: str, parameters: dict) -> bool: @@ -420,9 +411,7 @@ def _host_reachable(self, connector: str, parameters: dict) -> bool: return True try: - with socket.create_connection( - (host, port), timeout=REACHABILITY_TIMEOUT - ): + with socket.create_connection((host, port), timeout=REACHABILITY_TIMEOUT): return True except OSError: return False @@ -442,9 +431,7 @@ def _portretry_plugins_enabled(self) -> list[str]: return [ name for identifier, name in plugin_names.items() - if plugin_manager.get_plugin_info( - identifier, require_enabled=True - ) + if plugin_manager.get_plugin_info(identifier, require_enabled=True) is not None ] except Exception: # pylint: disable=broad-exception-caught @@ -461,9 +448,13 @@ def _detected_connection(self) -> dict[str, Any]: if self._is_serial_connector(connector): target = self.serial_port or "" - warning = "" if target else ( - "No serial port detected yet; set one in OctoPrint's " - "connection dialog or configure a forced port below." + warning = ( + "" + if target + else ( + "No serial port detected yet; set one in OctoPrint's " + "connection dialog or configure a forced port below." + ) ) return { "label": label, @@ -483,9 +474,7 @@ def _detected_connection(self) -> dict[str, Any]: "No preferred connection stored. Connect once via OctoPrint's " "connection dialog so AutoConnectPlus knows what to reconnect." ) - elif ConnectedPrinter is not None and ( - ConnectedPrinter.find(connector) is None - ): + elif ConnectedPrinter is not None and (ConnectedPrinter.find(connector) is None): warning = ( f"Connector '{connector}' is not installed. Install the " "matching connector plugin." @@ -589,12 +578,9 @@ def on_settings_save(self, data) -> dict[Any, Any]: # Match the entry-point key so the runtime identifier is explicit (otherwise # defaults to the package name). __plugin_identifier__ = "autoconnectplus" -__plugin_author__ = ( - "ajimaru, based on work from vehystrix and hprombex" -) +__plugin_author__ = "ajimaru, based on work from vehystrix and hprombex" __plugin_description__ = ( - "Automatically reconnects the printer over serial, Moonraker or Bambu " - "connectors" + "Automatically reconnects the printer over serial, Moonraker or Bambu connectors" ) __plugin_url__ = "https://github.com/ajimaru/OctoPrint-AutoConnectPlus" __plugin_license__ = "AGPL-3.0-or-later" @@ -619,6 +605,5 @@ def __plugin_load__(): module_globals = globals() module_globals["__plugin_implementation__"] = plugin module_globals["__plugin_hooks__"] = { - "octoprint.plugin.softwareupdate.check_config": - plugin.get_update_information, + "octoprint.plugin.softwareupdate.check_config": plugin.get_update_information, } diff --git a/octoprint_autoconnectplus/static/js/autoconnectplus.js b/octoprint_autoconnectplus/static/js/autoconnectplus.js index 65ee5d7..91e3c31 100644 --- a/octoprint_autoconnectplus/static/js/autoconnectplus.js +++ b/octoprint_autoconnectplus/static/js/autoconnectplus.js @@ -18,11 +18,13 @@ $(function () { new PNotify({ title: "AutoConnectPlus error", - text: plugins.join(" and ") + " is also enabled. Disable " + + text: + plugins.join(" and ") + + " is also enabled. Disable " + "one of the reconnect plugins to prevent competing " + "reconnect attempts.", type: "error", - hide: false, + hide: false }); portRetryWarningShown = true; } @@ -69,6 +71,6 @@ $(function () { OCTOPRINT_VIEWMODELS.push({ construct: AutoConnectPlusViewModel, dependencies: ["settingsViewModel"], - elements: ["#settings_plugin_autoconnectplus"], + elements: ["#settings_plugin_autoconnectplus"] }); }); diff --git a/octoprint_autoconnectplus/templates/autoconnectplus_settings.jinja2 b/octoprint_autoconnectplus/templates/autoconnectplus_settings.jinja2 index f0244a8..2e54b93 100644 --- a/octoprint_autoconnectplus/templates/autoconnectplus_settings.jinja2 +++ b/octoprint_autoconnectplus/templates/autoconnectplus_settings.jinja2 @@ -1,7 +1,7 @@
- {{ _('AutoConnectPlus reconnects the printer using the connection you last configured in OctoPrint\'s connection dialog (serial, Moonraker, Bambu, ...). The connection parameters are taken from OctoPrint directly, so there is nothing to duplicate here.') }} + {{ _("AutoConnectPlus reconnects the printer using the connection you last configured in OctoPrint's connection dialog (serial, Moonraker, Bambu, ...). The connection parameters are taken from OctoPrint directly, so there is nothing to duplicate here.") }}
@@ -9,46 +9,49 @@ - {{ _('When disabled, AutoConnectPlus stays idle and never reconnects the printer.') }} + {{ _("When disabled, AutoConnectPlus stays idle and never reconnects the printer.") }}
- +
- — + — - {{ _('Read-only. Taken from OctoPrint\'s preferred connection.') }} + {{ _("Read-only. Taken from OctoPrint's preferred connection.") }}
- +
- - {{ _('How often to attempt a reconnect while the printer is disconnected.') }} + {{ _("How often to attempt a reconnect while the printer is disconnected.") }}
- +
- - {{ _('Serial connections only. Optional. Used only when OctoPrint\'s serial port is unset or AUTO.') }} + {{ _("Serial connections only. Optional. Used only when OctoPrint's serial port is unset or AUTO.") }}
diff --git a/pyproject.toml b/pyproject.toml index 5fdbdcc..d2d23bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [] [project.optional-dependencies] dev = [ "pytest", - "ruff", + "pre-commit", ] [tool.setuptools] @@ -46,24 +46,3 @@ Source = "https://github.com/ajimaru/OctoPrint-AutoConnectPlus" testpaths = ["tests"] # Import the plugin from the repository, not from an installed copy. pythonpath = ["."] - -[tool.ruff] -target-version = "py39" -# Match the IDE linters' (flake8/pycodestyle) default so all tools agree. -line-length = 79 -extend-exclude = ["dist", "extras"] - -[tool.ruff.lint] -select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "I", # import sorting - "B", # bugbear - "UP", # pyupgrade - "SIM", # simplifications -] - -[tool.ruff.lint.isort] -# Match the existing import grouping: OctoPrint after third-party. -known-first-party = ["octoprint_autoconnectplus"] diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..7e375e8 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,28 @@ +# Ruff settings shared by all plugin repos, following OctoPrint core. +# isort sorts the imports (see .isort.cfg), so ruff's "I" rules stay off. +line-length = 90 +target-version = "py39" +extend-exclude = ["**/vendor", "3rdPartySoftware", "archive"] + +[lint] +select = ["E", "W", "B", "F", "UP", "TID251"] +ignore = [ + "E203", + "E231", + "E265", + "E266", + "E402", + "E501", + "E731", + "E741", + "W605", + "UP031", + "UP032", + # peewee builds SQL from `field == None` and `field == True`. + "E711", + "E712", +] + +[lint.flake8-tidy-imports.banned-api] +"cgi".msg = "The cgi module is deprecated, see PEP 594." +"pkg_resources".msg = "pkg_resources was removed in setuptools 82." diff --git a/tests/test_import_guard.py b/tests/test_import_guard.py index 0eee065..4f5b086 100644 --- a/tests/test_import_guard.py +++ b/tests/test_import_guard.py @@ -71,7 +71,5 @@ def test_connector_framework_survives_a_fresh_import(): ), ) def test_octoprint_imports_connected_printer_without_the_workaround(): - result = _run_fresh( - "from octoprint.printer.connection import ConnectedPrinter" - ) + result = _run_fresh("from octoprint.printer.connection import ConnectedPrinter") assert result.returncode == 0, result.stderr diff --git a/tests/test_plugin.py b/tests/test_plugin.py index faf3194..318b981 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -143,9 +143,7 @@ def test_serial_port_not_cached(plugin): assert plugin.serial_port == "/dev/ttyUSB1" -def test_serial_port_reads_legacy_path_without_connector_framework( - plugin, monkeypatch -): +def test_serial_port_reads_legacy_path_without_connector_framework(plugin, monkeypatch): # OctoPrint 1.x: no printerConnection.preferred, serial.port is native. monkeypatch.setattr(octoprint_autoconnectplus, "ConnectedPrinter", None) plugin._settings.globals["serial"] = {"port": "/dev/ttyUSB0"} @@ -237,9 +235,7 @@ def test_connect_serial_connects_when_port_present(plugin): def test_connect_serial_waits_while_port_absent(plugin): set_preferred(plugin, "serial", {"port": "/dev/ttyUSB0"}) - with mock.patch( - "serial.tools.list_ports.comports", new=comports_returning() - ): + with mock.patch("serial.tools.list_ports.comports", new=comports_returning()): assert plugin._connect_serial("_default") is False plugin._printer.connect.assert_not_called() @@ -257,9 +253,7 @@ def test_serial_port_present_resolves_symlinks(plugin, tmp_path): def test_serial_port_present_optimistic_on_enumeration_error(plugin): - with mock.patch( - "serial.tools.list_ports.comports", side_effect=OSError("boom") - ): + with mock.patch("serial.tools.list_ports.comports", side_effect=OSError("boom")): assert plugin._serial_port_present("/dev/ttyUSB0") is True @@ -300,9 +294,7 @@ def test_connector_connects_when_reachable(plugin, connector_framework): ) -def test_connector_connects_despite_precondition_error( - plugin, connector_framework -): +def test_connector_connects_despite_precondition_error(plugin, connector_framework): connector_framework.registry["moonraker"] = FakeConnector FakeConnector.raise_on_preconditions = True set_preferred(plugin, "moonraker", {"host": "printer.local"}) @@ -342,10 +334,7 @@ def test_host_reachable_optimistic_without_host_or_port(plugin): with mock.patch("socket.create_connection") as create: assert plugin._host_reachable("moonraker", {}) is True assert plugin._host_reachable("unknown", {"host": "h"}) is True - assert ( - plugin._host_reachable("unknown", {"host": "h", "port": "nan"}) - is True - ) + assert plugin._host_reachable("unknown", {"host": "h", "port": "nan"}) is True create.assert_not_called() @@ -368,9 +357,7 @@ def test_do_auto_connect_backs_off_after_attempt(plugin): def test_do_auto_connect_backs_off_on_exception(plugin): - with mock.patch.object( - plugin, "_connect_serial", side_effect=RuntimeError("boom") - ): + with mock.patch.object(plugin, "_connect_serial", side_effect=RuntimeError("boom")): plugin.do_auto_connect() assert plugin._skip_ticks == 1 plugin._logger.error.assert_called_once() @@ -438,9 +425,7 @@ def test_detected_connection_warns_when_both_portretry_plugins_are_enabled( assert plugin_manager.get_plugin_info.call_count == 2 -def test_detected_connection_connector_with_default_port( - plugin, connector_framework -): +def test_detected_connection_connector_with_default_port(plugin, connector_framework): connector_framework.registry["moonraker"] = FakeConnector set_preferred(plugin, "moonraker", {"host": "printer.local"}) detected = plugin._detected_connection() @@ -449,17 +434,13 @@ def test_detected_connection_connector_with_default_port( assert detected["warning"] == "" -def test_detected_connection_warns_without_stored_host( - plugin, connector_framework -): +def test_detected_connection_warns_without_stored_host(plugin, connector_framework): set_preferred(plugin, "moonraker", {}) detected = plugin._detected_connection() assert "No preferred connection stored" in detected["warning"] -def test_detected_connection_warns_when_connector_missing( - plugin, connector_framework -): +def test_detected_connection_warns_when_connector_missing(plugin, connector_framework): set_preferred(plugin, "bambu", {"host": "printer.local"}) detected = plugin._detected_connection() assert "not installed" in detected["warning"] @@ -523,9 +504,7 @@ def do_save(changes): with mock.patch.object( octoprint.plugin.SettingsPlugin, "on_settings_save", - side_effect=lambda _self, data: plugin._settings.plugin.update( - data - ), + side_effect=lambda _self, data: plugin._settings.plugin.update(data), autospec=True, ): return plugin.on_settings_save(changes) @@ -541,9 +520,7 @@ def test_settings_save_disable_stops_timer(plugin, save_settings): assert plugin._timer is None -def test_settings_save_enable_starts_timer_when_disconnected( - plugin, save_settings -): +def test_settings_save_enable_starts_timer_when_disconnected(plugin, save_settings): plugin._settings.plugin["enabled"] = False with mock.patch("octoprint_autoconnectplus.RepeatedTimer") as timer_cls: save_settings({"enabled": True}) @@ -559,9 +536,7 @@ def test_settings_save_interval_change_restarts_timer(plugin, save_settings): timer_cls.return_value.start.assert_called_once() -def test_settings_save_interval_change_no_restart_while_connected( - plugin, save_settings -): +def test_settings_save_interval_change_no_restart_while_connected(plugin, save_settings): plugin._printer.is_closed_or_error.return_value = False old_timer = mock.Mock() plugin._timer = old_timer