File: t_ResourceMap_missing.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (105 lines) | stat: -rwxr-xr-x 3,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python

import openturns as ot
from pathlib import Path
import re

ot.TESTPREAMBLE()

# find all keys
resourcemap_file = (
    Path(__file__)
    .parents[2]
    .joinpath("lib")
    .joinpath("src")
    .joinpath("Base")
    .joinpath("Common")
    .joinpath("ResourceMap.cxx")
)
resourcemap_lines = []
with open(resourcemap_file) as f:
    resourcemap_lines += f.read().splitlines()
resourcemap_content = {}
for line in resourcemap_lines:
    match = re.search(r'addAs(\w+)\("([\w\-]+)",[ ]*([\w\d\.\-\"]+)[\),]', line)
    if match is not None:
        key, vtype, value = match.group(2), match.group(1), match.group(3)
        print(key, vtype, value)
        if key == "SymbolicParser-Backend":
            continue
        if vtype == "Scalar":
            resourcemap_content[key] = float(value)
        elif vtype == "UnsignedInteger":
            resourcemap_content[key] = int(value)
        elif vtype == "Bool":
            resourcemap_content[key] = {"true": True, "false": False}[value]
        elif vtype.startswith("String"):
            resourcemap_content[key] = value.strip('"')
        else:
            raise ValueError(f"got {key}")
print(f"resourcemap: {len(resourcemap_content)} keys")

conf_file = (
    Path(__file__)
    .parents[2]
    .joinpath("lib")
    .joinpath("etc")
    .joinpath("openturns.conf.in")
)
conf_lines = []
with open(conf_file) as f:
    conf_lines += f.read().splitlines()
conf_content = {}
for line in conf_lines:
    match = re.search(r'^[ ]+<([\w\-]+)[ ]+value_(\w+)="([\w\d\.\-]+)"', line)
    if match is not None:
        key, vtype, value = match.group(1), match.group(2), match.group(3)
        if vtype == "float":
            conf_content[key] = float(value)
        elif vtype == "int":
            conf_content[key] = int(value)
        elif vtype == "bool":
            assert value in ["true", "false"], f"value should be true|false got {value}"
            conf_content[key] = value == "true"
        elif vtype == "str":
            conf_content[key] = value
        else:
            raise ValueError(f"got {vtype}")
print(f"config: {len(conf_content)} keys")

# check missing keys in config wrt resourcemap
for key in resourcemap_content:
    if key in conf_content:
        if resourcemap_content[key] != conf_content[key]:
            raise ValueError(
                f"key={key} RM={resourcemap_content[key]} CONF={conf_content[key]}"
            )
    else:
        raise ValueError(f"missing {key} in rm")

# check extra keys in config wrt resourcemap
for key in conf_content:
    if key not in resourcemap_content:
        raise ValueError(f"extra {key} in config")

# find all docstring files
docstring_files = Path(__file__).parents[1].joinpath("src").glob("*_doc.i")
docstring_lines = []
for docstring_file in docstring_files:
    with open(docstring_file, errors="replace") as f:
        docstring_lines += f.read().splitlines()

# count undocumented keys
undoc_keys = dict(resourcemap_content)
for key in resourcemap_content:
    for line in docstring_lines:
        if key in line:
            del undoc_keys[key]
            break

for key in undoc_keys:
    print(key)
n_undoc_keys = len(undoc_keys)
n_keys = len(resourcemap_content)
print(f"found {n_undoc_keys} undocumented keys out of {n_keys}")
assert n_undoc_keys < 475, "too much undocumented resourcemap keys"