From 0d569a9d9879b478a1071d98eee2d8785f2b3799 Mon Sep 17 00:00:00 2001 From: "Richard Edgar (Microsoft)" Date: Sun, 5 May 2024 08:14:43 -0400 Subject: [PATCH] Drafting the fix for the JSON tests --- tests/library/test_json.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/library/test_json.py b/tests/library/test_json.py index 08f63410d..3c127a864 100644 --- a/tests/library/test_json.py +++ b/tests/library/test_json.py @@ -16,7 +16,21 @@ def _generate_and_check( # Sanity check what we're being asked validate(instance=target_obj, schema=schema_obj) - prepared_string = f"{_to_compact_json(target_obj)}" + # The next part is to prevent intermittent test failures + # when the temperature is non-zero + # The Mock model generates random characters once the + # supplied string has been exhausted. Sometimes + # these can also be valid according to the grammar + # (especially when generating numbers) which interferes + # with our round trip check. + # So append a 'stop' character which we don't + # use in any of our tests + + STOP_CHAR = "\g" + prepared_json = _to_compact_json(target_obj) + assert STOP_CHAR not in prepared_json, "STOP_CHAR in string" + + prepared_string = f"{prepared_json}{STOP_CHAR}" lm = models.Mock(prepared_string.encode()) # Run with the mock model