|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from sortition_algorithms.errors import SelectionError, SelectionMultilineError |
| 8 | +from sortition_algorithms.errors import InfeasibleQuotasError, SelectionError, SelectionMultilineError |
| 9 | +from sortition_algorithms.features import FeatureValueMinMax |
9 | 10 | from sortition_algorithms.utils import ReportLevel, RunReport, get_cell_name |
10 | 11 |
|
11 | 12 |
|
@@ -506,6 +507,32 @@ def test_run_report_with_multiline_error_deserialisation(self): |
506 | 507 | assert str(deserialised_report.last_error()) == "Error line 1\nError line 2\nError line 3" |
507 | 508 | assert isinstance(deserialised_report.last_error(), SelectionMultilineError) |
508 | 509 |
|
| 510 | + def test_run_report_with_infeasible_quotas_error_serialisation(self): |
| 511 | + report = RunReport() |
| 512 | + report.add_error( |
| 513 | + InfeasibleQuotasError( |
| 514 | + features={"feat1": {"value1": FeatureValueMinMax(min=2, max=4)}}, output=["line1", "line2"] |
| 515 | + ) |
| 516 | + ) |
| 517 | + serialised_form = report.serialize() |
| 518 | + assert "_data" in serialised_form |
| 519 | + assert len(serialised_form["_data"]) == 1 |
| 520 | + |
| 521 | + def test_run_report_with_infeasible_quotas_error_deserialisation(self): |
| 522 | + report = RunReport() |
| 523 | + error = InfeasibleQuotasError( |
| 524 | + features={"feat1": {"value1": FeatureValueMinMax(min=2, max=4)}}, output=["line1", "line2"] |
| 525 | + ) |
| 526 | + report.add_error(error) |
| 527 | + serialised_form = report.serialize() |
| 528 | + deserialised_report = RunReport.deserialize(serialised_form) |
| 529 | + |
| 530 | + # Check the error is preserved with all lines and features |
| 531 | + deserialised_error = deserialised_report.last_error() |
| 532 | + assert isinstance(deserialised_error, InfeasibleQuotasError) |
| 533 | + assert str(deserialised_error) == "The quotas are infeasible:\nline1\nline2" |
| 534 | + assert deserialised_error.features == {"feat1": {"value1": FeatureValueMinMax(min=2, max=4)}} |
| 535 | + |
509 | 536 | def test_run_report_with_mixed_content_serialisation_deserialisation(self): |
510 | 537 | """Test round-trip with lines, tables, and errors mixed together""" |
511 | 538 | report = RunReport() |
|
0 commit comments