Add code quality tooling and improve test fixtures#34
Add code quality tooling and improve test fixtures#34raman325 wants to merge 10 commits intokoush:mainfrom
Conversation
- Add GitHub Actions workflows (hacs, hassfest, pytest with codecov) - Add pre-commit configuration with ruff, pylint, yamllint, mypy - Add devcontainer for development within Home Assistant instance - Refactor test fixtures to use unittest.mock.patch instead of monkeypatch - Add pyproject.toml with consolidated tool configuration - Split requirements into lint, test, and dev files - Fix pylint errors (raise-from, file context managers, shadowed builtins) - Add .editorconfig for consistent formatting - Update README with development setup instructions No functional changes to the integration itself. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
raman325
left a comment
There was a problem hiding this comment.
Self-review: Explaining the code changes made in this PR. All changes are linter-driven and don't affect functionality.
raman325
left a comment
There was a problem hiding this comment.
Additional comment for unused variable removal.
raman325
left a comment
There was a problem hiding this comment.
Additional comment for import and test changes.
Removed .codex and .ha from the .gitignore file.
- Upgrade pre-commit hook for markdownlint-cli (fix hook id) - Add .markdownlint.json config file - Add separate markdownlint.yaml workflow for markdown linting - Fix markdown formatting in README.md, TODO.md, and bug_report.md - Fix pydocstyle errors (blank lines after docstrings) - Fix mypy errors (use dict literals for type inference) - Apply ruff formatting to Python files - Remove unused __init__ in ScryptedConfigFlow - Rename panelconf to panel_conf for snake_case consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add comprehensive tests for custom_components/scrypted/http.py (~600 lines) - Tests for retrieve_token() function - Tests for ScryptedView class and URL creation - Tests for helper functions (_is_websocket, _response_header, _init_header) - Tests for static file serving and WebSocket handling - Add shared test constants in tests/const.py to reduce duplication - Add JSON fixture files for login responses: - login_success.json - login_error_not_logged_in.json - login_error_incorrect_password.json - Refactor conftest.py: - Add load_fixture() helper and fixture loading functions - Add HTTP module fixtures (mock_web_request, scrypted_view, etc.) - Replace _register_scrypted_flow with auto_enable_custom_integrations - Modernize http.py: - Use pathlib.Path instead of os.path for file operations - Extract magic strings to constants (DEFAULT_SCRYPTED_PORT, filenames) - Use asyncio.get_running_loop() instead of session.loop - Clean up unused parameters: - Remove unused token param from _async_unregister_lovelace_resource() - Rename unused config_entry to _config_entry in async_get_options_flow() - Update coverage configuration: - Move fail_under threshold to .coveragerc (80%) - Remove --cov-fail-under from pytest addopts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ements * upstream/main: Add frontend dependency to ensure proper initialization order (koush#37)
|
I successfully tested:
Couldn't think of anything else to test. I added a review comment for every "code change" (anything beyond a formatting change) in the integration in case you are curious why any of those changes were made. The majority of the PR is related to tests, pre-commit/CI, and reformatting/addressing pre-commit failures |
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive code quality tooling and testing infrastructure with no functional changes to the Scrypted integration. It establishes CI/CD workflows, linting standards, pre-commit hooks, and a complete development environment setup via devcontainer.
Key changes include:
- Added GitHub Actions workflows for testing (pytest with Codecov), linting (ruff), Home Assistant validation (hassfest, HACS), and markdown linting
- Migrated from monkeypatch to unittest.mock.patch for better async test support and added ~600 lines of new HTTP module tests
- Consolidated tool configuration in pyproject.toml with coverage threshold set to 80%
- Refactored code to use modern Python patterns (pathlib, proper exception chaining, context managers)
Reviewed changes
Copilot reviewed 38 out of 40 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/*.yaml |
Added CI workflows for pytest, linting, HACS/hassfest validation, and markdown linting |
.github/.codecov.yaml |
Codecov configuration with 70-100% coverage range |
.devcontainer/* |
Complete devcontainer setup with debugpy support and auto-configuration |
.pre-commit-config.yaml |
Pre-commit hooks for ruff, pydocstyle, yamllint, mypy, actionlint, markdownlint |
pyproject.toml |
Consolidated configuration for ruff, mypy, pylint, and pytest |
tests/conftest.py |
Refactored from monkeypatch to unittest.mock with reusable fixture library |
tests/test_http.py |
New comprehensive test suite (~600 lines) for HTTP module |
tests/fixtures/*.json |
JSON fixtures for login response testing |
tests/const.py |
Shared test constants to reduce duplication |
tests/test_*.py |
Updated to use new fixtures and removed @pytest.mark.asyncio decorators |
custom_components/scrypted/__init__.py |
Removed unused variables, improved exception handling, renamed panelconf to panel_conf |
custom_components/scrypted/http.py |
Modernized with pathlib, extracted constants, improved file handling |
custom_components/scrypted/config_flow.py |
Fixed shadowed builtin (type→selector_type), improved import scoping |
custom_components/scrypted/const.py |
Added DEFAULT_SCRYPTED_PORT and filename constants |
requirements_*.txt |
Split into test, lint, and dev requirements |
README.md |
Added development setup instructions |
TODO.md |
Reformatted with proper markdown headings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This is a code quality PR with no functional changes to the integration itself. All changes focus on improving development workflow, code maintainability, and CI/CD.
Changes Made
GitHub Actions Workflows
hacs.yaml- HACS validation workflowhassfest.yaml- Home Assistant integration validationpytest.yaml- Test runner with coverage reporting to Codecovlint.yaml- Linting via ruffmarkdownlint.yaml- Markdown linting workflow.codecov.yaml- Codecov configurationPre-commit & Linting
.pre-commit-config.yamlwith ruff, pydocstyle, yamllint, mypy, actionlint, markdownlintpyproject.tomlwith consolidated tool configuration.markdownlint.jsonfor markdown linting configurationrequirements_lint.txt,requirements_test.txt,requirements_dev.txtDevelopment Environment
devcontainerconfiguration for developing within a Home Assistant instance which sets integration log level to debug and enables thedebugpyintegration by defaultkeesschollaart.vscode-home-assistant) to devcontainer.editorconfigfor consistent formattingTest Infrastructure Improvements
http.pymodule (~600 lines of new tests)retrieve_token()functionScryptedViewclass and URL creation_is_websocket,_response_header,_init_header)tests/const.pyto reduce duplicationlogin_success.json,login_error_*.json)conftest.pywith reusable fixtures:load_fixture()helper and fixture loading functionsmock_web_request,scrypted_view, etc.)_register_scrypted_flowwithauto_enable_custom_integrationsunittest.mock.patchcontext managers for better async supportasyncio_mode = "auto"to eliminate@pytest.mark.asynciodecoratorsimport custom_components.scrypted as scryptedtofrom custom_components import scryptedper PEP 8.coveragercCode Modernization (linter-driven, no functional changes)
http.pyto usepathlib.Pathinstead ofos.pathDEFAULT_SCRYPTED_PORT, filenames)asyncio.get_running_loop()instead of deprecatedsession.looptokenparameter from_async_unregister_lovelace_resource()created_resourcevariable that was assigned but never readconfig_entryto_config_entryinasync_get_options_flow()raise-missing-frompylint errors - changed from genericexcept Exceptionwith isinstance check to specificexcept ClientConnectorErrorwithfrom efor proper exception chaining per PEP 3134with open(..., encoding="utf-8"))typeparameter renamed toselector_type)config_flow.py- directly import specific classes fromhomeassistant.helpers.selectorsubmodules__init__in ScryptedConfigFlowpanelconftopanel_conffor snake_case consistencyNote for @koush
GitHub Actions: The CI workflows require GitHub Actions to be enabled on the repository. Go to Settings → Actions → General and ensure "Allow all actions and reusable workflows" is selected.
Codecov: The pytest workflow uses Codecov for coverage reporting. To enable this:
koush/ha_scryptedrepositoryCODECOV_TOKENin GitHub repository settingsThe workflow will still run without the token (coverage upload will just be skipped).
Test Plan
🤖 Generated with Claude Code