def test_program_start_property(): identifiers = IdentifierManager.from_dict({ ScopedName.from_string('some.main.__start__'): LabelDefinition(3), }) reference_manager = ReferenceManager() main_scope = ScopedName.from_string('some.main') # The label __start__ is in identifiers. program = Program(prime=0, data=[], hints={}, builtins=[], main_scope=main_scope, identifiers=identifiers, reference_manager=reference_manager) assert program.start == 3 # The label __start__ is not in identifiers. program = Program(prime=0, data=[], hints={}, builtins=[], main_scope=main_scope, identifiers=IdentifierManager(), reference_manager=reference_manager) assert program.start == 0
def test_unparsed(): identifier_values = { scope('x'): LabelDefinition(10), } context = VmConstsContext( identifiers=IdentifierManager.from_dict(identifier_values), evaluator=dummy_evaluator, reference_manager=ReferenceManager(), flow_tracking_data=FlowTrackingDataActual(ap_tracking=RegTrackingData()), memory={}, pc=0) consts = VmConsts(context=context, accessible_scopes=[scope('')]) with pytest.raises(IdentifierError, match="Unexpected '.' after 'x' which is label."): consts.x.z
def test_label(): identifier_values = { scope('x'): LabelDefinition(10), scope('x.y'): ConstDefinition(1), scope('y'): ConstDefinition(2), } context = VmConstsContext( identifiers=IdentifierManager.from_dict(identifier_values), evaluator=dummy_evaluator, reference_manager=ReferenceManager(), flow_tracking_data=FlowTrackingDataActual(ap_tracking=RegTrackingData()), memory={}, pc=0) consts = VmConsts(context=context, accessible_scopes=[ScopedName()]) assert consts.x.instruction_offset_ == 10 assert consts.y == 2 assert consts.x.y == 1
def test_identifier_manager_field_serialization(): @marshmallow_dataclass.dataclass class Foo: identifiers: IdentifierManager = field(metadata=dict( marshmallow_field=IdentifierManagerField())) Schema = marshmallow_dataclass.class_schema(Foo) foo = Foo(identifiers=IdentifierManager.from_dict({ scope('aa.b'): LabelDefinition(pc=1000), })) serialized = Schema().dump(foo) assert serialized == { 'identifiers': { 'aa.b': { 'pc': 1000, 'type': 'label' } } } assert Schema().load(serialized) == foo