# 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
        self.assertRaises(Exception, utils.determine_project_name, None, {})



class TestLaTeX(unittest.TestCase):

    def setUp(self):
        utils._cache = {}

    def test_read_config(self):
        config = dedent("""
            [sumatra]
            label: foo
            project: MyProject
            record_store: /path/to/db
            digest: 0123456789abcdef
            [graphics]
            width: 0.9\textwidth
            """)
        test_file = "test_latex.config"
        with open(test_file, "w") as fp:
            fp.write(config)
        self.assertEqual(includefigure.read_config(test_file),
                         ({"label": "foo",
                           "project": "MyProject",
                           "record_store": "/path/to/db",
                           "digest": "0123456789abcdef"},
                          {"width": "0.9\textwidth"}))
        os.remove(test_file)


# 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

        self.assertRaises(Exception, utils.determine_project_name, None, {})



class TestLaTeX(unittest.TestCase):

    def setUp(self):
        utils._cache = {}

    def test_read_config(self):
        config = dedent("""
            [sumatra]
            label: foo
            project: MyProject
            record_store: /path/to/db
            digest: 0123456789abcdef
            [graphics]
            width: 0.9\textwidth
            """)
        test_file = "test_latex.config"
        with open(test_file, "w") as fp:
            fp.write(config)
        self.assertEqual(includefigure.read_config(test_file),
                         ({"label": "foo",
                           "project": "MyProject",
                           "record_store": "/path/to/db",
                           "digest": "0123456789abcdef"},
                          {"width": "0.9\textwidth"}))
        os.remove(test_file)


    @patch(utils, 'get_record_store', MockRecordStore)