Coverage for tests/utils.py: 89%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.4, created at 2024-01-20 18:02 +0000

1import json 

2import sys 

3from pathlib import Path 

4 

5from django.core.management.color import no_style 

6 

7DJANGO_PARAMETER_LOG_FILE = Path(__file__).parent / "dj_params.json" 

8 

9 

10def log_django_parameters(django_command, **extra): 

11 if DJANGO_PARAMETER_LOG_FILE.exists(): 

12 DJANGO_PARAMETER_LOG_FILE.unlink() 

13 

14 from django.conf import settings 

15 

16 with open(DJANGO_PARAMETER_LOG_FILE, "w") as f: 

17 json.dump( 

18 { 

19 "settings": settings.SETTINGS_FILE, 

20 "python_path": sys.path, 

21 "no_color": django_command.style == no_style(), 

22 **extra, 

23 }, 

24 f, 

25 indent=4, 

26 ) 

27 

28 

29def read_django_parameters(): 

30 try: 

31 with open(DJANGO_PARAMETER_LOG_FILE) as f: 

32 return json.load(f) 

33 except FileNotFoundError: 

34 return {} 

35 finally: 

36 if DJANGO_PARAMETER_LOG_FILE.exists(): 36 ↛ exitline 36 didn't return from function 'read_django_parameters', because the return on line 32 wasn't executed or the return on line 34 wasn't executed

37 DJANGO_PARAMETER_LOG_FILE.unlink()