RangeManager: additional testing of `set_selection()` method: change only higher or lower boundaries of the selection.
(qtbot, full_range, selection, new_range, value_type)
| 431 | ]) |
| 432 | # fmt: on |
| 433 | def test_RangeManager_5(qtbot, full_range, selection, new_range, value_type): |
| 434 | """ |
| 435 | RangeManager: additional testing of `set_selection()` method: |
| 436 | change only higher or lower boundaries of the selection. |
| 437 | """ |
| 438 | slider_steps = 1000 |
| 439 | selection_to_range_min = 0.01 |
| 440 | |
| 441 | rman = RangeManager(slider_steps=slider_steps, selection_to_range_min=selection_to_range_min) |
| 442 | qtbot.addWidget(rman) |
| 443 | rman.show() |
| 444 | |
| 445 | def _verify_selection(sel, rng): |
| 446 | # Verify that selection is set correctly |
| 447 | npt.assert_array_almost_equal(rman.get_selection(), sel, err_msg="Selection is set incorrectly") |
| 448 | # Verify that selection is displayed correctly |
| 449 | assert rman.le_min_value.text() == f"{sel[0]:.8g}", "Lower boundary is displayed incorrectly" |
| 450 | assert rman.le_max_value.text() == f"{sel[1]:.8g}", "Upper boundary is displayed incorrectly" |
| 451 | # Check positions of the sliders |
| 452 | step = (rng[1] - rng[0]) / slider_steps |
| 453 | assert rman.sld_min_value.value() == slider_steps - round( |
| 454 | (sel[0] - rng[0]) / step |
| 455 | ), "Slider position (min. value) is incorrect" |
| 456 | assert rman.sld_max_value.value() == round( |
| 457 | (sel[1] - rng[0]) / step |
| 458 | ), "Slider position (max. value) is incorrect" |
| 459 | |
| 460 | def _verify_range(rng): |
| 461 | # Verify that selection is set correctly |
| 462 | npt.assert_array_almost_equal(rman.get_range(), rng, err_msg="Range is set incorrectly") |
| 463 | |
| 464 | # Set the range and verify that the selection was scaled correctly |
| 465 | rman.set_range(full_range[0], full_range[1]) |
| 466 | rman.set_selection(value_low=selection[0], value_high=selection[1]) |
| 467 | _verify_selection(selection, full_range) |
| 468 | _verify_range(full_range) |
| 469 | |
| 470 | def _scale_selection(val, old_rng, new_rng): |
| 471 | """ |
| 472 | Scale the selection boundary. Reproduces computations performed by |
| 473 | RangeManager when changing the range |
| 474 | """ |
| 475 | val -= old_rng[0] |
| 476 | val *= (new_rng[1] - new_rng[0]) / (old_rng[1] - old_rng[0]) |
| 477 | val += new_rng[0] |
| 478 | return val |
| 479 | |
| 480 | def _clip_selection(sel, rng, selection_to_range_min): |
| 481 | """ |
| 482 | Clip the selection values to compute the expected selection. |
| 483 | Reproduces the clipping performed by the RangeManager. |
| 484 | """ |
| 485 | sel = [max(min(_, rng[1]), rng[0]) for _ in sel] |
| 486 | if value_type == "float": |
| 487 | min_diff = (rng[1] - rng[0]) * selection_to_range_min |
| 488 | else: |
| 489 | min_diff = 1 |
| 490 | if sel[1] - sel[0] < min_diff: |
nothing calls this directly
no test coverage detected