1 # SPDX-License-Identifier: LGPL-3-or-later
2 # See Notices.txt for copyright information
4 from os
import PathLike
5 from typing
import Dict
, Tuple
, Union
8 from pathlib
import Path
12 __run_counts
: Dict
[str, int]
14 def __init__(self
) -> None:
15 self
.__run
_counts
= {}
17 def next(self
, k
: str) -> int:
18 retval
= self
.__run
_counts
.get(k
, 0)
19 self
.__run
_counts
[k
] = retval
+ 1
22 __RUN_COUNTERS
: Dict
[int, Tuple
[weakref
.ref
, "RunCounter"]] = {}
25 def get(obj
: object) -> "RunCounter":
27 t
= RunCounter
.__RUN
_COUNTERS
35 t
[k
] = weakref
.ref(obj
, on_finalize
), retval
39 _StrPath
= Union
[str, PathLike
]
42 def get_test_path(test_case
: unittest
.TestCase
, base_path
: _StrPath
) -> Path
:
43 count
= RunCounter
.get(test_case
).next(test_case
.id())
44 return Path(base_path
) / test_case
.id() / str(count
)