-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve tests for generic camera #63197
Improve tests for generic camera #63197
Conversation
"verify_ssl": True, | ||
}, | ||
) | ||
assert cam.frame_interval == pytest.approx(0.2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression is that the design standards are that it is preferred to have tests that exercise via APIs that are exposed rather than asserting on properties of entities -- though mocking out functions is OK.
However, I realize it looks like this is used as input into mjpeg sleep which is a little awkward to test.
Seems like that implies the preferred way to test this would be via mocking out the sleep call in the mpjeg cam?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@allenporter Yes, it's complex to test this fully.
I think that the API is well tested by the other tests. This one is literally to increase coverage for one line - to verify that frame_interval()
returns a valid value. So really, I suppose it's checking that these lines work:
self._frame_interval = 1 / device_info[CONF_FRAMERATE] |
core/homeassistant/components/generic/camera.py
Lines 119 to 122 in a2b611d
@property | |
def frame_interval(self): | |
"""Return the interval between frames of the mjpeg stream.""" | |
return self._frame_interval |
Whether that property does anything is useful or not is probably an extra test that could be added. But I would prefer to keep this PR simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah i also see attributes were introduced recently so maybe the code can just go away and be replaced by setting _attr_frame_interval
, then there is no coverage need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agreed, done.
"still_image_url": "https://example.com", | ||
"stream_source": 'http://example.com/{{ states.sensor.temp.state + "a" }}', | ||
"limit_refetch_to_url_change": True, | ||
with patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the rest of these patches still needed or can they also use response testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now replaced with respx.
Looks great, thanks @davet2001 👍🏼 👍🏼 |
Breaking change
Proposed change
Improve the test coverage for generic integration camera component.
Also use simulated valid images to test connections rather than text strings.
Bringing into this PR to make #52360 smaller.
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: