Coverage for jutil/management/commands/list_files.py: 92%

24 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-07 16:40 -0500

1import json 

2 

3from django.core.management.base import CommandParser 

4from jutil.command import SafeCommand 

5from jutil.files import list_files 

6 

7 

8class Command(SafeCommand): 

9 help = "Wrapper for testing list_files helper function output" 

10 

11 def add_arguments(self, parser: CommandParser): 

12 parser.add_argument("dir_name", type=str) 

13 parser.add_argument("--suffix", type=str) 

14 parser.add_argument("--ignore-case", action="store_true") 

15 parser.add_argument("--recurse", action="store_true") 

16 parser.add_argument("--json", action="store_true") 

17 parser.add_argument("--use-media-root", action="store_true") 

18 

19 def do(self, *args, **kw): 

20 dir_name = kw["dir_name"] 

21 suffix = kw["suffix"] or "" 

22 recurse = kw["recurse"] 

23 ignore_case = kw["ignore_case"] 

24 use_media_root = kw["use_media_root"] 

25 out = list_files(dir_name, suffix=suffix, ignore_case=ignore_case, use_media_root=use_media_root, recurse=recurse) 

26 if kw["json"]: 26 ↛ 30line 26 didn't jump to line 30, because the condition on line 26 was never false

27 json_str = json.dumps(out, indent=4) 

28 self.stdout.writelines([json_str]) 

29 else: 

30 self.stdout.writelines(out)