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