Skip to content

Commit b32b0b1

Browse files
author
Hamish Downer
committed
Test RunReport (de)serialize can go via JSON
1 parent f0e23ac commit b32b0b1

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

tests/test_utils.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import re
34
from typing import ClassVar
@@ -467,7 +468,9 @@ def test_run_report_with_error_deserialisation(self):
467468
report = RunReport()
468469
report.add_error(SelectionError("Something went wrong"))
469470
serialised_form = report.serialize()
470-
deserialised_report = RunReport.deserialize(serialised_form)
471+
json_report = json.dumps(serialised_form)
472+
from_json = json.loads(json_report)
473+
deserialised_report = RunReport.deserialize(from_json)
471474

472475
# Check the error is preserved
473476
assert deserialised_report.last_error() is not None
@@ -484,7 +487,9 @@ def test_run_report_with_non_fatal_error_deserialisation(self):
484487
report = RunReport()
485488
report.add_error(SelectionError("Minor issue"), is_fatal=False)
486489
serialised_form = report.serialize()
487-
deserialised_report = RunReport.deserialize(serialised_form)
490+
json_report = json.dumps(serialised_form)
491+
from_json = json.loads(json_report)
492+
deserialised_report = RunReport.deserialize(from_json)
488493

489494
# Verify is_fatal is preserved
490495
assert str(deserialised_report.last_error()) == "Minor issue"
@@ -501,7 +506,9 @@ def test_run_report_with_multiline_error_deserialisation(self):
501506
error = SelectionMultilineError(["Error line 1", "Error line 2", "Error line 3"])
502507
report.add_error(error)
503508
serialised_form = report.serialize()
504-
deserialised_report = RunReport.deserialize(serialised_form)
509+
json_report = json.dumps(serialised_form)
510+
from_json = json.loads(json_report)
511+
deserialised_report = RunReport.deserialize(from_json)
505512

506513
# Check the error is preserved with all lines
507514
assert deserialised_report.last_error() is not None
@@ -517,6 +524,8 @@ def test_run_report_with_infeasible_quotas_error_serialisation(self):
517524
serialised_form = report.serialize()
518525
assert "_data" in serialised_form
519526
assert len(serialised_form["_data"]) == 1
527+
json_form = json.dumps(serialised_form)
528+
assert '"_data"' in json_form
520529

521530
def test_run_report_with_infeasible_quotas_error_deserialisation(self):
522531
report = RunReport()
@@ -525,7 +534,9 @@ def test_run_report_with_infeasible_quotas_error_deserialisation(self):
525534
features["feat1"]["value1"] = FeatureValueMinMax(min=2, max=4)
526535
report.add_error(InfeasibleQuotasError(features=features, output=["line1", "line2"]))
527536
serialised_form = report.serialize()
528-
deserialised_report = RunReport.deserialize(serialised_form)
537+
json_report = json.dumps(serialised_form)
538+
from_json = json.loads(json_report)
539+
deserialised_report = RunReport.deserialize(from_json)
529540

530541
# Check the error is preserved with all lines and features
531542
deserialised_error = deserialised_report.last_error()
@@ -544,7 +555,9 @@ def test_run_report_with_mixed_content_serialisation_deserialisation(self):
544555

545556
# Round trip
546557
serialised_form = report.serialize()
547-
deserialised_report = RunReport.deserialize(serialised_form)
558+
json_report = json.dumps(serialised_form)
559+
from_json = json.loads(json_report)
560+
deserialised_report = RunReport.deserialize(from_json)
548561

549562
# Verify the text and HTML output is the same (we can't use == because Exception doesn't define equality)
550563
assert deserialised_report.as_text() == report.as_text()

0 commit comments

Comments
 (0)