# Path: palladium/interfaces.py
# def annotate(obj, metadata=None):
#     base_metadata = getattr(obj, '__metadata__', {})
#     if metadata is not None:
#         base_metadata.update(metadata)
#         obj.__metadata__ = base_metadata
#     return obj.__metadata__


import codecs
import copy
import gzip
import json
import os
import pickle
import posixpath
import requests_mock
import pytest
        import moto, boto3
        import moto, boto3
from threading import Thread
from unittest.mock import Mock
from unittest.mock import MagicMock
from unittest.mock import patch
from palladium.interfaces import annotate
        from palladium.persistence import UpgradeSteps
        from palladium.persistence import File
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium.persistence import File
        from palladium.persistence import Database
        from palladium.util import session_scope
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from sqlalchemy.pool import NullPool
        from sqlalchemy.pool import QueuePool
        from palladium.persistence import Rest
        from palladium.persistence import RestIO
        from palladium.persistence import DatabaseCLOB
        from palladium.persistence import CachedUpdatePersister
        from palladium.persistence import S3IO
        from palladium.persistence import S3
            ]

    def test_attachment_file_contents(self, persister, tmpdir):
        # Attachment data is written to files system decoded:
        with open(tmpdir + '/model-1-myatt.txt', 'rb') as f:
            assert f.read() == b'hey'
        with open(tmpdir + '/model-1-my2ndatt.txt', 'rb') as f:
            assert f.read() == b'ho'
        with open(tmpdir + '/model-2-myatt.txt', 'rb') as f:
            assert f.read() == b'ho'

    def test_attachment_not_in_metadata_file(self, persister, tmpdir):
        # Attachment data is not written to the metadata file:
        with open(tmpdir + '/model-metadata.json') as f:
            md = json.loads(f.read())
            assert len(md['models']) == 2
            for model_md in md['models']:
                assert 'attachments/myatt.txt' not in model_md

    def test_attachment_not_in_pickle(self, persister, tmpdir):
        # Attachment data is not pickled as part of the model:
        with open(tmpdir + '/model-1.pkl.gz', 'rb') as fh:
            with gzip.open(fh, 'rb') as f:
                model1 = pickle.load(f)
                assert 'attachments/myatt.txt' not in annotate(model1)

    def test_loaded_back_on_read(self, persister, tmpdir):
        # Attachment is read back from the file into metadata
        # dictionary on read:
        model1 = persister.read(version=1)

# Path: palladium/interfaces.py
# def annotate(obj, metadata=None):
#     base_metadata = getattr(obj, '__metadata__', {})
#     if metadata is not None:
#         base_metadata.update(metadata)
#         obj.__metadata__ = base_metadata
#     return obj.__metadata__


# Path: palladium/tests/test_persistence.py
import codecs
import copy
import gzip
import json
import os
import pickle
import posixpath
import requests_mock
import pytest
        import moto, boto3
        import moto, boto3
from threading import Thread
from unittest.mock import Mock
from unittest.mock import MagicMock
from unittest.mock import patch
from palladium.interfaces import annotate
        from palladium.persistence import UpgradeSteps
        from palladium.persistence import File
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium.persistence import File
        from palladium.persistence import Database
        from palladium.util import session_scope
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from palladium import __version__
        from sqlalchemy.pool import NullPool
        from sqlalchemy.pool import QueuePool
        from palladium.persistence import Rest
        from palladium.persistence import RestIO
        from palladium.persistence import DatabaseCLOB
        from palladium.persistence import CachedUpdatePersister
        from palladium.persistence import S3IO
        from palladium.persistence import S3

            ]

    def test_attachment_file_contents(self, persister, tmpdir):
        # Attachment data is written to files system decoded:
        with open(tmpdir + '/model-1-myatt.txt', 'rb') as f:
            assert f.read() == b'hey'
        with open(tmpdir + '/model-1-my2ndatt.txt', 'rb') as f:
            assert f.read() == b'ho'
        with open(tmpdir + '/model-2-myatt.txt', 'rb') as f:
            assert f.read() == b'ho'

    def test_attachment_not_in_metadata_file(self, persister, tmpdir):
        # Attachment data is not written to the metadata file:
        with open(tmpdir + '/model-metadata.json') as f:
            md = json.loads(f.read())
            assert len(md['models']) == 2
            for model_md in md['models']:
                assert 'attachments/myatt.txt' not in model_md

    def test_attachment_not_in_pickle(self, persister, tmpdir):
        # Attachment data is not pickled as part of the model:
        with open(tmpdir + '/model-1.pkl.gz', 'rb') as fh:
            with gzip.open(fh, 'rb') as f:
                model1 = pickle.load(f)
                assert 'attachments/myatt.txt' not in annotate(model1)

    def test_loaded_back_on_read(self, persister, tmpdir):
        # Attachment is read back from the file into metadata
        # dictionary on read:
        model1 = persister.read(version=1)

        assert annotate(model1)['attachments/myatt.txt'] == b'aGV5'