From 9a882e869198caff01ac769d7100ce40ed43a042 Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Sat, 4 Jul 2026 00:35:32 -0400 Subject: [PATCH] tests: add test for BORG_JSON_COMPACT env var --- src/borg/testsuite/helpers/parseformat_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/borg/testsuite/helpers/parseformat_test.py b/src/borg/testsuite/helpers/parseformat_test.py index 6c79e99fd..0b6b0e9a0 100644 --- a/src/borg/testsuite/helpers/parseformat_test.py +++ b/src/borg/testsuite/helpers/parseformat_test.py @@ -1,4 +1,5 @@ import base64 +import json import os import re @@ -718,3 +719,19 @@ def test_valid_chunkerparams(chunker_params, expected_return): def test_invalid_chunkerparams(invalid_chunker_params): with pytest.raises(ArgumentTypeError): ChunkerParams(invalid_chunker_params) + + +def test_json_dump_compact(monkeypatch): + from ...helpers.parseformat import json_dump + + obj = {"key": "value", "number": 42} + + # Default: pretty-printed (multi-line) + result = json_dump(obj) + assert "\n" in result + + # With BORG_JSON_COMPACT set: single-line + monkeypatch.setenv("BORG_JSON_COMPACT", "1") + result = json_dump(obj) + assert "\n" not in result + assert json.loads(result) == obj