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

8 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-29 07:42 +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 return wrapped(*args, **kwargs) 

16 

17 

18# Apply the wrapper 

19json.dump = json_dump_wrapper(json.dump)