-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix a NPE bug. #111
Fix a NPE bug. #111
Conversation
Can you add a test for this? |
7ec3aff
to
e2fd91a
Compare
I added a test. Also fixed an issue I ran into with the watering reports. It looks like Hydrawise does not strictly honor the start time and end time provided to the call. Hence we need to filter out events that happen before and after the provided time range. I updated the tests to cover this case as well. |
Please split this into two PRs. |
e2fd91a
to
261cb0a
Compare
tests/test_client.py
Outdated
@@ -503,18 +504,26 @@ async def test_get_sensors( | |||
assert "sensors {" in query | |||
|
|||
|
|||
@pytest.mark.parametrize("scenario", [pytest.param("present"), pytest.param("missing")]) |
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.
I think the way pytest intends you to do this is to use Indirect parametrization. Something like this:
@fixture
def flow_summary_json(param):
if param:
yield {"valid": "json"}
else:
yield None
@pytest.mark.parametrize("flow_summary_json", (True, False), indirect=True)
def test_get_water_flow_summary(..., flow_summary_json):
...
mock_session.execute.return_value = {"controller": {"sensors": [flow_sensor_json | {"flowSummary": flow_summary_json}]}}
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.
Didn't know that. Thanks. Fixed.
To address a potential NullPointerException (NPE), this fix handles cases where the flowSummary() method returns an empty result.
The code now explicitly checks for an empty result from
flowSummary()
. If an empty result is detected, an emptySensorFlowSummary
object is created and returned instead.