Skip to content

Test pymodbus#49053

Merged
balloob merged 10 commits intohome-assistant:devfrom
janiversen:test_pymodbus
Apr 20, 2021
Merged

Test pymodbus#49053
balloob merged 10 commits intohome-assistant:devfrom
janiversen:test_pymodbus

Conversation

@janiversen
Copy link
Copy Markdown
Member

@janiversen janiversen commented Apr 11, 2021

Breaking change

Proposed change

This is a major rewrite of the low level modbus test harness (pymodbus library), tests now include:

  • test of exceptions
  • test of write
  • test of modbus services.

This PR allows all modbus platforms to mock class modbusHub (our class) and thus avoid thinking about the pymodbus library. The PR is also helpful in the coming pymodbus upgrade (2.5.1).

Care have been used to ensure the tests do not use the internals of HA.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Just run pytest.

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @adamchengtkc, @vzahradnik, mind taking a look at this pull request as its been labeled with an integration (modbus) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@janiversen
Copy link
Copy Markdown
Member Author

I think this is not a modbus problem, let us try again to see if it is a fluke

@janiversen
Copy link
Copy Markdown
Member Author

Changed mock(_logger) to caplog, as @MartinHjelmare suggested in #48829. I will update the other test (if needed) when providing PR´s for the rest of the outstanding issues. Target is to have most issues solved in 2021.5

Comment thread tests/components/modbus/test_modbus.py Outdated
Comment thread tests/components/modbus/test_modbus.py Outdated
Comment thread tests/components/modbus/test_modbus.py Outdated
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I had a few tiny comments.

@janiversen
Copy link
Copy Markdown
Member Author

@balloob I think all your issues are solved (hopefully to your liking). Lets see if the checks are ok too.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no public interface to the ModbusHub class yet, so then we should avoid accessing it in tests. Or is the plan to make it a public interface, ie public so that other integrations can use the hub instance directly?

Comment thread tests/components/modbus/test_modbus.py Outdated
Comment thread tests/components/modbus/test_modbus.py Outdated
@janiversen
Copy link
Copy Markdown
Member Author

Just searched in tests/components and it seems all test suites access hass.data, so adding a get_domain function to hass might be a very good idea.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This is to some extent being tested with the platform tests.
@janiversen
Copy link
Copy Markdown
Member Author

This is hopefully a glitch (I am not going to contact security as advised).

@balloob balloob merged commit d24b3e0 into home-assistant:dev Apr 20, 2021
@janiversen janiversen deleted the test_pymodbus branch April 20, 2021 18:33
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants