Coverage for src\zapy\requests\context.py: 100%

1 from dataclasses import dataclass, field

2 from typing import Callable

3 from types import ModuleType

4

5 from zapy.base import ZapyAuto

6 from zapy.store import Store, use_store

7

8 from .file_loader import load_file

9 from .hooks import RequestHookBlueprint

10

11

12@dataclass

13 class ZapyRequestContext:

14

15 store: Store = field(default_factory=use_store)

16 hooks: RequestHookBlueprint = field(default_factory=RequestHookBlueprint)

17 logger: Callable = print

18

19 def load_file(self, path, mime=ZapyAuto):

20 return load_file(path, mime)

21

22 def auto(self):

23 return ZapyAuto

24

25

26 def build_context_module(ctx: ZapyRequestContext) -> ModuleType:

27 module_ctx = ModuleType('zapy.context')

28 ctx_attrs = (name for name in dir(ctx) if not name.startswith('_'))

29 for name in ctx_attrs:

30 value = getattr(ctx, name)

31 setattr(module_ctx, name, value)

32

33 return module_ctx