Project Name: marshmallow-code+marshmallow
Language: Python
Statement Type: API

Source Code:
def test_decorated_processors(partial_val):
    class ExampleSchema(Schema):
        """Includes different ways to invoke decorators and set up methods"""

        TAG = "TAG"

        value = fields.Integer(as_string=True)

        # Implicit default raw, pre dump, static method.
        @pre_dump
        def increment_value(self, item, **kwargs):
            assert "many" in kwargs
            item["value"] += 1
            return item

        # Implicit default raw, post dump, class method.
        @post_dump
        def add_tag(self, item, **kwargs):
            assert "many" in kwargs
            item["value"] = self.TAG + item["value"]
            return item

        # Explicitly raw, post dump, instance method.
        @post_dump(pass_many=True)
        def add_envelope(self, data, many, **kwargs):
            key = self.get_envelope_key(many)
            return {key: data}

        # Explicitly raw, pre load, instance method.
        @pre_load(pass_many=True)
        def remove_envelope(self, data, many, partial, **kwargs):
            assert partial is partial_val
            key = self.get_envelope_key(many)
            return data[key]

        @staticmethod
        def get_envelope_key(many):
            return "data" if many else "datum"

        # Explicitly not raw, pre load, instance method.
        @pre_load(pass_many=False)
        def remove_tag(self, item, partial, **kwargs):
            assert partial is partial_val
            assert "many" in kwargs
            item["value"] = item["value"][len(self.TAG) :]
            return item

        # Explicit default raw, post load, instance method.
        @post_load()
        def decrement_value(self, item, partial, **kwargs):
            assert partial is partial_val
            assert "many" in kwargs
            item["value"] -= 1
            return item

    schema = ExampleSchema(partial=partial_val)

    # Need to re-create these because the processors will modify in place.
    make_item = lambda: {"value": 3}
    make_items = lambda: [make_item(), {"value": 5}]

    item_dumped = schema.dump(make_item())
    assert item_dumped == {"datum": {"value": "TAG4"}}
    item_loaded = schema.load(item_dumped)
    assert item_loaded == make_item()

    items_dumped = schema.dump(make_items(), many=True)
    assert items_dumped == {"data": [{"value": "TAG4"}, {"value": "TAG6"}]}
    items_loaded = schema.load(items_dumped, many=True)
    assert items_loaded == make_items()

test_decorated_processors(partial_val=True)

Selected Statement: items_loaded = schema.load(items_dumped, many=True)

Function Input:
partial_val: True

Variable Values Before Statement:
items_dumped: {'data': [{'value': 'TAG4'}, {'value': 'TAG6'}]}

Value After Statement Execution: 3, 5

Variable States During Runtime (line, value):
partial_val: 1
True
ExampleSchema: 2
<class 'tests.test_decorators.test_decorated_processors.<locals>.ExampleSchema'>
schema: 56
<ExampleSchema(many=False)>
make_item: 59
<function test_decorated_processors.<locals>.<lambda> at 0x7f27f9f7d310>
make_items: 60
<function test_decorated_processors.<locals>.<lambda> at 0x7f27f9158550>
item_dumped: 62
{'datum': {'value': 'TAG4'}}
64
{'datum': {'value': '4'}}
@py_assert2: 63
None
@py_assert1: 63
None
item_loaded: 64
value: 3
@py_assert3: 65
None
items_dumped: 67
{'data': [{'value': 'TAG4'}, {'value': 'TAG6'}]}
69
{'data': [{'value': '4'}, {'value': '6'}]}
items_loaded: 69
3, 5