|
14 | 14 |
|
15 | 15 | If a test class implements a class method with the signature `get_test_basename(cls, path: str) -> str`, |
16 | 16 | then this method will be called to create the base name for the test case at the given path. |
| 17 | +Otherwise, the file's basename will be used. |
17 | 18 |
|
18 | 19 | The expected output or any argument can reference the test's current temp or data dirs with `__TEMP_DIR__()` or `__DATA_DIR__()`, respectively. |
19 | 20 | An optional slash-separated path can be used as an argument to reference a path within those base directories. |
@@ -282,6 +283,32 @@ def replace_path_pattern(text: str, key: str, target_dir: str, normalize_path: b |
282 | 283 |
|
283 | 284 | return text |
284 | 285 |
|
| 286 | +def compute_ancestor_basename(path: str, cli_tests_dir: str) -> str: |
| 287 | + """ |
| 288 | + Get the test's name based off of its filename and location. |
| 289 | + A useful fuction to use in get_test_basename(). |
| 290 | + """ |
| 291 | + |
| 292 | + path = os.path.abspath(path) |
| 293 | + |
| 294 | + name = os.path.splitext(os.path.basename(path))[0] |
| 295 | + |
| 296 | + # Clean drive identifiers (for Windows). |
| 297 | + cli_tests_dir_path = os.path.splitdrive(os.path.abspath(cli_tests_dir))[1] |
| 298 | + path = os.path.splitdrive(path)[1] |
| 299 | + |
| 300 | + ancestors = os.path.dirname(path).replace(cli_tests_dir_path, '') |
| 301 | + prefix = ancestors.replace(os.sep, '_') |
| 302 | + |
| 303 | + if (prefix.startswith('_')): |
| 304 | + prefix = prefix.replace('_', '', 1) |
| 305 | + |
| 306 | + if (len(prefix) > 0): |
| 307 | + name = f"{prefix}_{name}" |
| 308 | + |
| 309 | + return name |
| 310 | + |
| 311 | + |
285 | 312 | def _get_test_method(test_name: str, path: str, data_dir: str) -> typing.Callable: |
286 | 313 | """ Get a test method that represents the test case at the given path. """ |
287 | 314 |
|
|
0 commit comments