Skip to content

Commit ed7c6a8

Browse files
Add missing function call and assertions
1 parent 7725c33 commit ed7c6a8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/pynguin/instrumentation/instrumentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def _instrument_cond_jump( # noqa: PLR0917
411411
Returns:
412412
The id that was assigned to the predicate.
413413
"""
414-
maybe_compare = None if maybe_compare_idx is None else block[maybe_compare_idx] # type: ignore[index]
414+
maybe_compare = None if maybe_compare_idx is None else block[maybe_compare_idx]
415415
if (
416416
maybe_compare is not None
417417
and isinstance(maybe_compare, Instr)

tests/instrumentation/test_instrumentation.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# SPDX-License-Identifier: MIT
66
#
7+
import contextlib
78
import importlib
89
import os
910
import threading
@@ -495,20 +496,20 @@ def test_jump_if_true_or_pop():
495496
tracer = ExecutionTracer()
496497

497498
def func(string, inttype=int):
498-
return ((
499-
hasattr(string, "is_integer") or hasattr(string, "__array__")
500-
)
501-
or (
502-
isinstance(string, (bytes, str))
503-
)
499+
return (hasattr(string, "is_integer") or hasattr(string, "__array__")) or (
500+
isinstance(string, (bytes, str))
504501
)
505-
502+
506503
adapter = BranchCoverageInstrumentation(tracer)
507504
transformer = InstrumentationTransformer(tracer, [adapter])
508505
func.__code__ = transformer.instrument_module(func.__code__)
509-
510-
# FIXME execute func()
511-
# FIXME add any appropriate exceptions
506+
tracer.current_thread_identifier = threading.current_thread().ident
507+
with contextlib.nullcontext():
508+
func("123")
509+
assert OrderedSet([0]) == tracer.get_trace().executed_code_objects
510+
assert {0: 1, 1: 1} == tracer.get_trace().executed_predicates
511+
assert {0: 1.0, 1: 1.0} == tracer.get_trace().true_distances
512+
assert {0: 0.0, 1: 0.0} == tracer.get_trace().false_distances
512513

513514

514515
def test_tracking_covered_statements_explicit_return(simple_module):

0 commit comments

Comments
 (0)