Coverage for src/somesy/json_wrapper.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-04 11:35 +0000

1"""Utility functions for somesy.""" 

2 

3import json 

4 

5import wrapt 

6 

7 

8@wrapt.decorator 

9def json_dump_wrapper(wrapped, instance, args, kwargs): 

10 """Wrap json.dump to write non-ascii characters with default indentation.""" 

11 # Ensure ensure_ascii is set to False 

12 kwargs["ensure_ascii"] = False 

13 # set indent to 2 if not set 

14 kwargs["indent"] = kwargs.get("indent", 2) 

15 result = wrapped(*args, **kwargs) 

16 (args[1] if len(args) > 1 else kwargs["fp"]).write("\n") 

17 return result 

18 

19 

20# Apply the wrapper 

21json.dump = json_dump_wrapper(json.dump)