# Path: test/unittests/utils.py
# class patch(object):
#     """
#     Decorator for replacing a function or class by a mock version for the
#     duration of a test, then replacing the original afterwards.
#     """
#     
#     def __init__(self, module, obj_name, mock_obj):
#         self.module = module
#         self.obj_name = obj_name
#         self.mock_obj = mock_obj
#         self.orig_obj = getattr(module, obj_name)
#         
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             setattr(self.module, self.obj_name, self.mock_obj)
#             f(*args, **kwargs)
#             setattr(self.module, self.obj_name, self.orig_obj)
#         wrapped_f.__name__ = f.__name__
#         return wrapped_f


from builtins import object
from io import StringIO
from textwrap import dedent
from datetime import datetime
    from docutils.core import publish_string
from sumatra.publishing import utils
from sumatra.publishing.latex import includefigure
    from sumatra.publishing.sphinxext import sumatra_rst
from sumatra.datastore import DataKey
from .utils import patch
import unittest
import sys
import os
import shutil
            """)
        config = dedent("""
            [general]
            sumatra_record_store: /path/to/db
            sumatra_project: MyProject
            sumatra_link_icon: icon_info.png
            """)
        with open("docutils.conf", "w") as fp:
            fp.write(config)
        output = publish_string(source, writer_name='pseudoxml',
                                settings_overrides={'output_encoding': 'unicode'})
        self.assertEqual("\n" + output,
                         dedent("""
                            <document source="<string>">
                                <image align="center" alt="Data file generated by computation foo" digest="0123456789abcdef" uri="smt_images/bar.jpg">
                            """))



    @patch(utils, 'get_record_store', MockRecordStore)
    def test_full_build_http_store(self):
        source = dedent("""
            .. smtimage:: foo
               :digest: 0123456789abcdef
               :align: center
            """)
        config = dedent("""
            [general]
            sumatra_record_store: http://smt.example.com/
            sumatra_project: MyProject

# Path: test/unittests/utils.py
# class patch(object):
#     """
#     Decorator for replacing a function or class by a mock version for the
#     duration of a test, then replacing the original afterwards.
#     """
#     
#     def __init__(self, module, obj_name, mock_obj):
#         self.module = module
#         self.obj_name = obj_name
#         self.mock_obj = mock_obj
#         self.orig_obj = getattr(module, obj_name)
#         
#     def __call__(self, f):
#         def wrapped_f(*args, **kwargs):
#             setattr(self.module, self.obj_name, self.mock_obj)
#             f(*args, **kwargs)
#             setattr(self.module, self.obj_name, self.orig_obj)
#         wrapped_f.__name__ = f.__name__
#         return wrapped_f


# Path: test/unittests/test_publishing.py
from builtins import object
from io import StringIO
from textwrap import dedent
from datetime import datetime
    from docutils.core import publish_string
from sumatra.publishing import utils
from sumatra.publishing.latex import includefigure
    from sumatra.publishing.sphinxext import sumatra_rst
from sumatra.datastore import DataKey
from .utils import patch
import unittest
import sys
import os
import shutil

            """)
        config = dedent("""
            [general]
            sumatra_record_store: /path/to/db
            sumatra_project: MyProject
            sumatra_link_icon: icon_info.png
            """)
        with open("docutils.conf", "w") as fp:
            fp.write(config)
        output = publish_string(source, writer_name='pseudoxml',
                                settings_overrides={'output_encoding': 'unicode'})
        self.assertEqual("\n" + output,
                         dedent("""
                            <document source="<string>">
                                <image align="center" alt="Data file generated by computation foo" digest="0123456789abcdef" uri="smt_images/bar.jpg">
                            """))



    @patch(utils, 'get_record_store', MockRecordStore)
    def test_full_build_http_store(self):
        source = dedent("""
            .. smtimage:: foo
               :digest: 0123456789abcdef
               :align: center
            """)
        config = dedent("""
            [general]
            sumatra_record_store: http://smt.example.com/
            sumatra_project: MyProject

            sumatra_link_icon: icon_info.png