Skip to content

New test and handling for maybe_compare_idx==None; fixes TypeError causing Pynguin to abort. #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pynguin/instrumentation/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _instrument_cond_jump(
Returns:
The id that was assigned to the predicate.
"""
maybe_compare = block[maybe_compare_idx] # type: ignore[index]
maybe_compare = None if maybe_compare_idx is None else block[maybe_compare_idx] # type: ignore[index]
if (
maybe_compare is not None
and isinstance(maybe_compare, Instr)
Expand Down
20 changes: 20 additions & 0 deletions tests/instrumentation/test_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,26 @@ def func():
assert {0: 0.0} == tracer.get_trace().false_distances


def test_jump_if_true_or_pop():
tracer = ExecutionTracer()

def func(string, inttype=int):
return ((
hasattr(string, "is_integer") or hasattr(string, "__array__")
)
or (
isinstance(string, (bytes, str))
)
)

adapter = BranchCoverageInstrumentation(tracer)
transformer = InstrumentationTransformer(tracer, [adapter])
func.__code__ = transformer.instrument_module(func.__code__)

# FIXME execute func()
# FIXME add any appropriate exceptions


def test_tracking_covered_statements_explicit_return(simple_module):
tracer = ExecutionTracer()

Expand Down