3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-07 17:40:54 +00:00

python: make Statistics doctests robust to optional ":time" counter (#9729)

The doctests for Statistics.__len__ and Statistics.__getitem__ in
src/api/python/z3/z3.py asserted a fixed counter count (len(st) == 7).
This is fragile because the ":time" entry is only added to statistics
when the elapsed wall-clock time of check() is non-zero (see
collect_timer_stats in src/solver/check_sat_result.h). On fast native
builds, ":time" rounds to 0 and is omitted; under slow environments
(e.g. riscv64 under qemu emulation), it becomes non-zero and is
included, changing len(st).

Fix this by checking the presence of statistics rather than an exact
count.

Signed-off-by: Julien Stephan <jstephan@baylibre.com>
This commit is contained in:
Julien Stephan 2026-06-06 22:24:19 +02:00 committed by GitHub
parent 2f280a7baf
commit cf58fa027d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7396,8 +7396,8 @@ class Statistics:
>>> s.check()
sat
>>> st = s.statistics()
>>> len(st)
7
>>> len(st) > 0
True
"""
return int(Z3_stats_size(self.ctx.ref(), self.stats))
@ -7410,8 +7410,8 @@ class Statistics:
>>> s.check()
sat
>>> st = s.statistics()
>>> len(st)
7
>>> len(st) > 0
True
>>> st[0]
('nlsat propagations', 2)
>>> st[1]