1 # SPDX-License-Identifier: LGPL-3-or-later
2 # Copyright 2021 Jacob Lifshay
4 # Funded by NLnet Assure Programme 2021-02-052, https://nlnet.nl/assure part
5 # of Horizon 2020 EU Programme 957073.
8 from pathlib
import Path
13 self
.__run
_counts
= {}
14 """dict mapping self.next() keys to the next int value returned by
18 """get a incrementing run counter for a `str` key `k`. returns an `int`."""
19 retval
= self
.__run
_counts
.get(k
, 0)
20 self
.__run
_counts
[k
] = retval
+ 1
24 """dict mapping object ids (int) to a tuple of a weakref.ref to that
25 object, and the corresponding RunCounter"""
30 t
= RunCounter
.__RUN
_COUNTERS
38 t
[k
] = weakref
.ref(obj
, on_finalize
), retval
42 def get_test_path(test_case
, base_path
):
43 """get the `Path` for a particular unittest.TestCase instance
44 (`test_case`). base_path is either a str or a path-like."""
45 count
= RunCounter
.get(test_case
).next(test_case
.id())
46 return Path(base_path
) / test_case
.id() / str(count
)