| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9989d0f commit 1ba5c73
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,6 +229,13 @@ async def _handle_response_lists( | |||
| 229 | 229 | iterate_list_pages=False, | |
| 230 | 230 | ) | |
| 231 | 231 | next_batch = response[method] | |
| 232 | + # In case the device returns empty lists avoid infinite looping | ||
| 233 | + if not next_batch[response_list_name]: | ||
| 234 | + _LOGGER.error( | ||
| 235 | + f"Device {self._host} returned empty " | ||
| 236 | + + f"results list for method {method}" | ||
| 237 | + ) | ||
| 238 | + break | ||
| 232 | 239 | response_result[response_list_name].extend(next_batch[response_list_name]) | |
| 233 | 240 | ||
| 234 | 241 | def _handle_response_error_code(self, resp_dict: dict, method, raise_on_error=True): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,8 @@ def pytest_configure(): | |||
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | 60 | def pytest_sessionfinish(session, exitstatus): | |
| 61 | + if not pytest.fixtures_missing_methods: | ||
| 62 | + return | ||
| 61 | 63 | msg = "\n" | |
| 62 | 64 | for fixture, methods in sorted(pytest.fixtures_missing_methods.items()): | |
| 63 | 65 | method_list = ", ".join(methods) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,8 @@ def __init__( | |||
| 28 | 28 | *, | |
| 29 | 29 | list_return_size=10, | |
| 30 | 30 | component_nego_not_included=False, | |
| 31 | + warn_fixture_missing_methods=True, | ||
| 32 | + fix_incomplete_fixture_lists=True, | ||
| 31 | 33 | ): | |
| 32 | 34 | super().__init__( | |
| 33 | 35 | config=DeviceConfig( | |
@@ -46,6 +48,8 @@ def __init__( | |||
| 46 | 48 | for comp in self.info["component_nego"]["component_list"] | |
| 47 | 49 | } | |
| 48 | 50 | self.list_return_size = list_return_size | |
| 51 | + self.warn_fixture_missing_methods = warn_fixture_missing_methods | ||
| 52 | + self.fix_incomplete_fixture_lists = fix_incomplete_fixture_lists | ||
| 49 | 53 | ||
| 50 | 54 | @property | |
| 51 | 55 | def default_port(self): | |
@@ -220,6 +224,18 @@ def _send_request(self, request_dict: dict): | |||
| 220 | 224 | if (params and (start_index := params.get("start_index"))) | |
| 221 | 225 | else 0 | |
| 222 | 226 | ) | |
| 227 | + # Fixtures generated before _handle_response_lists was implemented | ||
| 228 | + # could have incomplete lists. | ||
| 229 | + if ( | ||
| 230 | + len(result[list_key]) < result["sum"] | ||
| 231 | + and self.fix_incomplete_fixture_lists | ||
| 232 | + ): | ||
| 233 | + result["sum"] = len(result[list_key]) | ||
| 234 | + if self.warn_fixture_missing_methods: | ||
| 235 | + pytest.fixtures_missing_methods.setdefault( | ||
| 236 | + self.fixture_name, set() | ||
| 237 | + ).add(f"{method} (incomplete '{list_key}' list)") | ||
| 238 | + | ||
| 223 | 239 | result[list_key] = result[list_key][ | |
| 224 | 240 | start_index : start_index + self.list_return_size | |
| 225 | 241 | ] | |
@@ -244,9 +260,10 @@ def _send_request(self, request_dict: dict): | |||
| 244 | 260 | "method": method, | |
| 245 | 261 | } | |
| 246 | 262 | # Reduce warning spam by consolidating and reporting at the end of the run | |
| 247 | - if self.fixture_name not in pytest.fixtures_missing_methods: | ||
| 248 | - pytest.fixtures_missing_methods[self.fixture_name] = set() | ||
| 249 | - pytest.fixtures_missing_methods[self.fixture_name].add(method) | ||
| 263 | + if self.warn_fixture_missing_methods: | ||
| 264 | + pytest.fixtures_missing_methods.setdefault( | ||
| 265 | + self.fixture_name, set() | ||
| 266 | + ).add(method) | ||
| 250 | 267 | return retval | |
| 251 | 268 | elif method in ["set_qs_info", "fw_download"]: | |
| 252 | 269 | return {"error_code": 0} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + import logging | ||
| 2 | + | ||
| 1 | 3 | import pytest | |
| 2 | 4 | ||
| 3 | 5 | from ..credentials import Credentials | |
@@ -242,3 +244,49 @@ async def test_smart_protocol_lists_multiple_request(mocker, list_sum, batch_siz | |||
| 242 | 244 | ) | |
| 243 | 245 | assert query_spy.call_count == expected_count | |
| 244 | 246 | assert resp == response | |
| 247 | + | ||
| 248 | + | ||
| 249 | + async def test_incomplete_list(mocker, caplog): | ||
| 250 | + """Test for handling incomplete lists returned from queries.""" | ||
| 251 | + info = { | ||
| 252 | + "get_preset_rules": { | ||
| 253 | + "start_index": 0, | ||
| 254 | + "states": [ | ||
| 255 | + { | ||
| 256 | + "brightness": 50, | ||
| 257 | + }, | ||
| 258 | + { | ||
| 259 | + "brightness": 100, | ||
| 260 | + }, | ||
| 261 | + ], | ||
| 262 | + "sum": 7, | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + caplog.set_level(logging.ERROR) | ||
| 266 | + transport = FakeSmartTransport( | ||
| 267 | + info, | ||
| 268 | + "dummy-name", | ||
| 269 | + component_nego_not_included=True, | ||
| 270 | + warn_fixture_missing_methods=False, | ||
| 271 | + ) | ||
| 272 | + protocol = SmartProtocol(transport=transport) | ||
| 273 | + resp = await protocol.query({"get_preset_rules": None}) | ||
| 274 | + assert resp | ||
| 275 | + assert resp["get_preset_rules"]["sum"] == 2 # FakeTransport fixes sum | ||
| 276 | + assert caplog.text == "" | ||
| 277 | + | ||
| 278 | + # Test behaviour without FakeTranport fix | ||
| 279 | + transport = FakeSmartTransport( | ||
| 280 | + info, | ||
| 281 | + "dummy-name", | ||
| 282 | + component_nego_not_included=True, | ||
| 283 | + warn_fixture_missing_methods=False, | ||
| 284 | + fix_incomplete_fixture_lists=False, | ||
| 285 | + ) | ||
| 286 | + protocol = SmartProtocol(transport=transport) | ||
| 287 | + resp = await protocol.query({"get_preset_rules": None}) | ||
| 288 | + assert resp["get_preset_rules"]["sum"] == 7 | ||
| 289 | + assert ( | ||
| 290 | + "Device 127.0.0.123 returned empty results list for method get_preset_rules" | ||
| 291 | + in caplog.text | ||
| 292 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,6 +57,7 @@ pytest-mock = "*" | |||
| 57 | 57 | codecov = "*" | |
| 58 | 58 | xdoctest = "*" | |
| 59 | 59 | coverage = {version = "*", extras = ["toml"]} | |
| 60 | + pytest-timeout = "^2" | ||
| 60 | 61 | ||
| 61 | 62 | [tool.poetry.extras] | |
| 62 | 63 | docs = ["sphinx", "sphinx_rtd_theme", "sphinxcontrib-programoutput", "myst-parser", "docutils"] | |
@@ -89,6 +90,7 @@ markers = [ | |||
| 89 | 90 | "requires_dummy: test requires dummy data to pass, skipped on real devices", | |
| 90 | 91 | ] | |
| 91 | 92 | asyncio_mode = "auto" | |
| 93 | + timeout = 10 | ||
| 92 | 94 | ||
| 93 | 95 | [tool.doc8] | |
| 94 | 96 | paths = ["docs"] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments