In the lifter we use type() to determine the correct handler for the given instruction. However, this prevents us to use mock classes (e.g., unittest.mock.Mock) to test parser functionality: instructions can't be lifted.
Changing handler selection in the lifter, to select by expression.__class__ would allow lifting of mocked instructions.
Since we add instruction patching (jmp / edges) to the parser, proper testing would be nice :)
Approach
def lift(self, expression: T, **kwargs) -> V:
"""Lift the given expression based on the registered handlers."""
- handler = self.HANDLERS.get(type(expression), self.lift_unknown)
+ handler = self.HANDLERS.get(expression.__class__, self.lift_unknown)
return handler(expression)
use unittest.mock.Mock and simplify tests for the parser.
Proposal
In the lifter we use
type()
to determine the correct handler for the given instruction. However, this prevents us to use mock classes (e.g.,unittest.mock.Mock
) to test parser functionality: instructions can't be lifted.Changing handler selection in the lifter, to select by
expression.__class__
would allow lifting of mocked instructions.Since we add instruction patching (jmp / edges) to the parser, proper testing would be nice :)
Approach
use
unittest.mock.Mock
and simplify tests for the parser.