From 1d3a4c56649e30eee68c70c3d32e7c2d3dc2d45d Mon Sep 17 00:00:00 2001 From: Charmi Kadi <68164274+charmikadi@users.noreply.github.com> Date: Sat, 4 Jul 2026 19:11:42 -0400 Subject: [PATCH] tests: update json_dump tests for BORG_JSON_INDENT --- .../testsuite/helpers/parseformat_test.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/borg/testsuite/helpers/parseformat_test.py b/src/borg/testsuite/helpers/parseformat_test.py index 0b6b0e9a0..e80dd626b 100644 --- a/src/borg/testsuite/helpers/parseformat_test.py +++ b/src/borg/testsuite/helpers/parseformat_test.py @@ -721,17 +721,25 @@ def test_invalid_chunkerparams(invalid_chunker_params): ChunkerParams(invalid_chunker_params) -def test_json_dump_compact(monkeypatch): +@pytest.mark.parametrize( + "env_value, expect_newlines", + [ + (None, True), # default indent=4 + ("none", False), # compact single-line + ("0", True), # newlines only, no spaces + ("4", True), # explicit pretty-print + ], +) +def test_json_dump_indent(monkeypatch, env_value, expect_newlines): from ...helpers.parseformat import json_dump obj = {"key": "value", "number": 42} + if env_value is not None: + monkeypatch.setenv("BORG_JSON_INDENT", env_value) - # 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 + if expect_newlines: + assert "\n" in result + else: + assert "\n" not in result assert json.loads(result) == obj