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.
Showing the changes to tools/lib/python (1 of 1 file). Show all
Unified · Split
| @@ -25,6 +25,7 @@ class KDocTestFile(): · 24 unmodified lines | |||
| 25 | self.config = config | 25 | self.config = config |
| 26 | self.test_file = os.path.expanduser(yaml_file) | 26 | self.test_file = os.path.expanduser(yaml_file) |
| 27 | self.yaml_content = yaml_content | 27 | self.yaml_content = yaml_content |
| 28 | self.test_names = set() | ||
| 28 | 29 | ||
| 29 | self.tests = [] | 30 | self.tests = [] |
| 30 | 31 | ||
| @@ -102,13 +103,10 @@ class KDocTestFile(): · 71 unmodified lines | |||
| 102 | if not symbols: | 103 | if not symbols: |
| 103 | return | 104 | return |
| 104 | 105 | ||
| 105 | base_name = "test_" + fname.replace(".", "_").replace("/", "_") | ||
| 106 | expected_dict = {} | 106 | expected_dict = {} |
| 107 | start_line=1 | 107 | start_line=1 |
| 108 | 108 | ||
| 109 | for i in range(0, len(symbols)): | 109 | for arg in symbols: |
| 110 | arg = symbols[i] | ||
| 111 | |||
| 112 | source = arg.get("source", "") | 110 | source = arg.get("source", "") |
| 113 | 111 | ||
| 114 | if arg and "KdocItem" in self.yaml_content: | 112 | if arg and "KdocItem" in self.yaml_content: |
| @@ -120,6 +118,21 @@ class KDocTestFile(): · 5 unmodified lines | |||
| 120 | 118 | ||
| 121 | expected_dict["kdoc_item"] = msg | 119 | expected_dict["kdoc_item"] = msg |
| 122 | 120 | ||
| 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 | |||
| 123 | for out_style in self.out_style: | 136 | for out_style in self.out_style: |
| 124 | if isinstance(out_style, ManFormat): | 137 | if isinstance(out_style, ManFormat): |
| 125 | key = "man" | 138 | key = "man" |
| @@ -128,8 +141,6 @@ class KDocTestFile(): · 2 unmodified lines | |||
| 128 | 141 | ||
| 129 | expected_dict[key]= out_style.output_symbols(fname, [arg]).strip() | 142 | expected_dict[key]= out_style.output_symbols(fname, [arg]).strip() |
| 130 | 143 | ||
| 131 | name = f"{base_name}_{i:03d}" | ||
| 132 | |||
| 133 | test = { | 144 | test = { |
| 134 | "name": name, | 145 | "name": name, |
| 135 | "description": f"{fname} line {arg.declaration_start_line}", | 146 | "description": f"{fname} line {arg.declaration_start_line}", |