Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/presets/searchable_test/definitions.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-21 21:08 -0600

1"""Searchable Snapshot Test Built-in Plan""" 

2 

3import typing as t 

4import logging 

5from pathlib import Path 

6from json import loads 

7from es_client.utils import get_yaml 

8from .scenarios import Scenarios 

9 

10logger = logging.getLogger(__name__) 

11 

12 

13def baseplan() -> dict: 

14 """Return the base plan object from plan.yml""" 

15 return get_yaml((modpath() / "plan.yml")) 

16 

17 

18def buildlist() -> list: 

19 """Return the list of index build schemas from buildlist.yml""" 

20 return get_yaml((modpath() / "buildlist.yml")) 

21 

22 

23def get_plan(scenario: t.Optional[str] = None) -> dict: 

24 """Return the plan dict based on scenario""" 

25 retval = baseplan() 

26 retval.update(buildlist()) 

27 if scenario: 

28 retval["uniq"] = f"scenario-{scenario}" 

29 scenarios = Scenarios() 

30 newvals = getattr(scenarios, scenario) 

31 ilm = newvals.pop("ilm", {}) 

32 if ilm: 

33 retval["ilm"].update(ilm) 

34 retval.update(newvals) 

35 return retval 

36 

37 

38def mappings() -> dict: 

39 """Return the index mappings from mappings.json""" 

40 return loads((modpath() / "mappings.json").read_text(encoding="UTF-8")) 

41 

42 

43def modpath() -> Path: 

44 """Return the local file path""" 

45 return Path(__file__).parent.resolve() 

46 

47 

48def settings() -> dict: 

49 """Return the index settings from settings.json""" 

50 return loads((modpath() / "settings.json").read_text(encoding="UTF-8"))