Coverage for src / ocarina / opinionated / infra / act_counter.py: 56.25%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-06-04 16:22 +0200

1"""ActCounter implementation proposal for TestSuites.""" 

2 

3from threading import local 

4from typing import Final 

5 

6from ocarina.infra.act_counter import ActCounter as _ActCounter 

7 

8_thread_local = local() 

9_COUNTER_KEY: Final[str] = "ocarina_counter" 

10 

11 

12class ActCounter(_ActCounter): 

13 """Tracks act() call count across a test execution.""" 

14 

15 def get(self) -> int: 

16 """Return current count.""" 

17 return getattr(_thread_local, _COUNTER_KEY, 0) 

18 

19 def reset(self) -> None: 

20 """Reset counter to zero.""" 

21 setattr(_thread_local, _COUNTER_KEY, 0) 

22 

23 def incr_act_call_count(self) -> None: 

24 """Increment counter.""" 

25 if not hasattr(_thread_local, _COUNTER_KEY): 

26 self.reset() 

27 setattr(_thread_local, _COUNTER_KEY, getattr(_thread_local, _COUNTER_KEY) + 1)