History

docs: kdoc_yaml_file: use a better name for the tests

Instead of always using a name with a number on it, use the name of the object directly whenever possible. When the name is already used, append a number prefix at the end.

Mauro Carvalho Chehab committed 7 months ago

Commit e786fab1 parent 99ec67a1 file · +17 −6Browse files

Unified · Split

tools/lib/python/kdoc/kdoc_yaml_file.py+17−6
@@ -25,6 +25,7 @@ class KDocTestFile(): · 24 unmodified lines
2525 self.config = config
2626 self.test_file = os.path.expanduser(yaml_file)
2727 self.yaml_content = yaml_content
28+ self.test_names = set()
2829
2930 self.tests = []
3031
@@ -102,13 +103,10 @@ class KDocTestFile(): · 71 unmodified lines
102103 if not symbols:
103104 return
104105
105− base_name = "test_" + fname.replace(".", "_").replace("/", "_")
106106 expected_dict = {}
107107 start_line=1
108108
109− for i in range(0, len(symbols)):
110− arg = symbols[i]
111−
109+ for arg in symbols:
112110 source = arg.get("source", "")
113111
114112 if arg and "KdocItem" in self.yaml_content:
@@ -120,6 +118,21 @@ class KDocTestFile(): · 5 unmodified lines
120118
121119 expected_dict["kdoc_item"] = msg
122120
121+ base_name = arg.name
122+ if not base_name:
123+ base_name = fname
124+ base_name = base_name.lower().replace(".", "_").replace("/", "_")
125+
126+
127+ # Don't add duplicated names
128+ i = 0
129+ name = base_name
130+ while name in self.test_names:
131+ i += 1
132+ name = f"{base_name}_{i:03d}"
133+
134+ self.test_names.add(name)
135+
123136 for out_style in self.out_style:
124137 if isinstance(out_style, ManFormat):
125138 key = "man"
@@ -128,8 +141,6 @@ class KDocTestFile(): · 2 unmodified lines
128141
129142 expected_dict[key]= out_style.output_symbols(fname, [arg]).strip()
130143
131− name = f"{base_name}_{i:03d}"
132−
133144 test = {
134145 "name": name,
135146 "description": f"{fname} line {arg.declaration_start_line}",