Coverage for vitriini/api.py: 56.67%

18 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-05 19:54:27 +00:00

1""""Showcase (Finnish: vitriini) some packaged content - guided by conventions - application programming interface.""" 

2 

3import argparse 

4from typing import no_type_check 

5 

6import msgspec 

7import vitriini.processor as pro 

8from vitriini import ( 

9 ENCODING, 

10) 

11 

12 

13@no_type_check 

14def load(path): 

15 """Load the data from the path to the file or fail miserably.""" 

16 with open(path, 'rt', encoding=ENCODING) as handle: 

17 return msgspec.json.decode(handle.read()) 

18 

19 

20@no_type_check 

21def dump(data, path): 

22 """Dump the data formatted to the file given by the path.""" 

23 with open(path, 'wt', encoding=ENCODING) as f: 

24 f.write(msgspec.json.format(msgspec.json.encode(data)).decode()) 

25 

26 

27@no_type_check 

28def process(options: argparse.Namespace): 

29 """Process the command line request.""" 

30 if not options: 

31 return 1 

32 

33 return pro.cess(options)