# Path: mfr/core/exceptions.py
# class RendererError(ExtensionError):
#     """The MFR related errors raised from a :class:`mfr.core.extension` and relating to rendering
#     should inherit from RendererError
#     """
# 
#     __TYPE = 'renderer'
# 
#     def __init__(self, message, *args, renderer_class: str='', **kwargs):
#         super().__init__(message, *args, **kwargs)
#         self.renderer_class = renderer_class
#         self.attr_stack.append([self.__TYPE, {'class': self.renderer_class}])
# 
# Path: mfr/core/provider.py
# class ProviderMetadata:
# 
#     def __init__(self, name, ext, content_type, unique_key, download_url, stable_id=None):
#         self.name = name
#         self.ext = ext
#         self.content_type = content_type
#         self.unique_key = unique_key
#         self.download_url = download_url
#         self.stable_id = stable_id
# 
#     def serialize(self):
#         return {
#             'name': self.name,
#             'ext': self.ext,
#             'content_type': self.content_type,
#             'unique_key': str(self.unique_key),
#             'download_url': str(self.download_url),
#             'stable_id': None if self.stable_id is None else str(self.stable_id),
#         }
# 
# Path: mfr/extensions/codepygments/settings.py
# MAX_SIZE = int(config.get('MAX_SIZE', 204800))  # 200kb
# 
# Path: mfr/extensions/codepygments/exceptions.py
# class FileTooLargeError(CodePygmentsRendererError):
#     """The codepygments related errors raised from a :class:`mfr.extentions.codepygments` and
#     relating to limit on size of file to display should inherit from FileTooLargeError
#     """
# 
#     __TYPE = 'codepygments_file_too_large'
# 
#     def __init__(self, message, *args, code: int=400, file_size: int=None, max_size: int=None,
#                  **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
# 
#         self.file_size = file_size
#         self.max_size = max_size
# 
#         self.attr_stack.append([self.__TYPE, {
#             'file_size': self.file_size,
#             'max_size': self.max_size
#         }])


import os
import pytest
from tempfile import NamedTemporaryFile
from mfr.core.exceptions import RendererError
from mfr.core.provider import ProviderMetadata
from mfr.extensions.codepygments import settings, CodePygmentsRenderer
from mfr.extensions.codepygments.exceptions import FileTooLargeError


@pytest.fixture
def assets_url():
    return 'http://mfr.osf.io/assets'


@pytest.fixture
def export_url():
    return 'http://mfr.osf.io/export?url=' + url()


@pytest.fixture
def extension():
    return '.mp3'


@pytest.fixture
def renderer(metadata, test_file_path, url, assets_url, export_url):
    return CodePygmentsRenderer(metadata, test_file_path, url, assets_url, export_url)


class TestCodePygmentsRenderer:

    def test_render_codepygments(self, renderer):
        body = renderer.render()
        assert '<div style="word-wrap: break-word;" class="mfrViewer">' in body

    def test_render_codepygments_invalid(self, metadata, invalid_file_path, url, assets_url, export_url):
        renderer = CodePygmentsRenderer(metadata, invalid_file_path, url, assets_url, export_url)

# Path: mfr/core/exceptions.py
# class RendererError(ExtensionError):
#     """The MFR related errors raised from a :class:`mfr.core.extension` and relating to rendering
#     should inherit from RendererError
#     """
# 
#     __TYPE = 'renderer'
# 
#     def __init__(self, message, *args, renderer_class: str='', **kwargs):
#         super().__init__(message, *args, **kwargs)
#         self.renderer_class = renderer_class
#         self.attr_stack.append([self.__TYPE, {'class': self.renderer_class}])
# 
# Path: mfr/core/provider.py
# class ProviderMetadata:
# 
#     def __init__(self, name, ext, content_type, unique_key, download_url, stable_id=None):
#         self.name = name
#         self.ext = ext
#         self.content_type = content_type
#         self.unique_key = unique_key
#         self.download_url = download_url
#         self.stable_id = stable_id
# 
#     def serialize(self):
#         return {
#             'name': self.name,
#             'ext': self.ext,
#             'content_type': self.content_type,
#             'unique_key': str(self.unique_key),
#             'download_url': str(self.download_url),
#             'stable_id': None if self.stable_id is None else str(self.stable_id),
#         }
# 
# Path: mfr/extensions/codepygments/settings.py
# MAX_SIZE = int(config.get('MAX_SIZE', 204800))  # 200kb
# 
# Path: mfr/extensions/codepygments/exceptions.py
# class FileTooLargeError(CodePygmentsRendererError):
#     """The codepygments related errors raised from a :class:`mfr.extentions.codepygments` and
#     relating to limit on size of file to display should inherit from FileTooLargeError
#     """
# 
#     __TYPE = 'codepygments_file_too_large'
# 
#     def __init__(self, message, *args, code: int=400, file_size: int=None, max_size: int=None,
#                  **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
# 
#         self.file_size = file_size
#         self.max_size = max_size
# 
#         self.attr_stack.append([self.__TYPE, {
#             'file_size': self.file_size,
#             'max_size': self.max_size
#         }])


# Path: tests/extensions/codepygments/test_renderer.py
import os
import pytest
from tempfile import NamedTemporaryFile
from mfr.core.exceptions import RendererError
from mfr.core.provider import ProviderMetadata
from mfr.extensions.codepygments import settings, CodePygmentsRenderer
from mfr.extensions.codepygments.exceptions import FileTooLargeError



@pytest.fixture
def assets_url():
    return 'http://mfr.osf.io/assets'


@pytest.fixture
def export_url():
    return 'http://mfr.osf.io/export?url=' + url()


@pytest.fixture
def extension():
    return '.mp3'


@pytest.fixture
def renderer(metadata, test_file_path, url, assets_url, export_url):
    return CodePygmentsRenderer(metadata, test_file_path, url, assets_url, export_url)


class TestCodePygmentsRenderer:

    def test_render_codepygments(self, renderer):
        body = renderer.render()
        assert '<div style="word-wrap: break-word;" class="mfrViewer">' in body

    def test_render_codepygments_invalid(self, metadata, invalid_file_path, url, assets_url, export_url):
        renderer = CodePygmentsRenderer(metadata, invalid_file_path, url, assets_url, export_url)

        with pytest.raises(RendererError):