sphinxcontrib-blockdiag-1.5.0/0000755000076600000240000000000012420126515017123 5ustar tkomiyastaff00000000000000sphinxcontrib-blockdiag-1.5.0/AUTHORS0000644000076600000240000000004512022072632020170 0ustar tkomiyastaff00000000000000Takeshi KOMIYA sphinxcontrib-blockdiag-1.5.0/LICENSE0000644000076600000240000000261212022072632020127 0ustar tkomiyastaff00000000000000If not otherwise noted, the extensions in this package are licensed under the following license. Copyright (c) 2009 by the contributors (see AUTHORS file). All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sphinxcontrib-blockdiag-1.5.0/MANIFEST.in0000644000076600000240000000010112022072632020647 0ustar tkomiyastaff00000000000000include AUTHORS include LICENSE include README include CHANGES.* sphinxcontrib-blockdiag-1.5.0/PKG-INFO0000644000076600000240000000320112420126515020214 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-blockdiag Version: 1.5.0 Summary: Sphinx "blockdiag" extension Home-page: http://bitbucket.org/birkenfeld/sphinx-contrib Author: Takeshi KOMIYA Author-email: i.tkomiya@gmail.com License: BSD Download-URL: http://pypi.python.org/pypi/sphinxcontrib-blockdiag Description: ======================= sphinxcontrib-blockdiag ======================= A sphinx extension for embedding block diagram using blockdiag_. This extension enables you to insert block diagrams into your document. Following code is an example:: .. blockdiag:: diagram { A -> B -> C; B -> D; } .. _blockdiag: http://bitbucket.org/blockdiag/blockdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/blockdiag/sphinxcontrib.html Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-blockdiag-1.5.0/README.rst0000644000076600000240000000103412420126336020611 0ustar tkomiyastaff00000000000000======================= sphinxcontrib-blockdiag ======================= A sphinx extension for embedding block diagram using blockdiag_. This extension enables you to insert block diagrams into your document. Following code is an example:: .. blockdiag:: diagram { A -> B -> C; B -> D; } .. _blockdiag: http://bitbucket.org/blockdiag/blockdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/blockdiag/sphinxcontrib.html sphinxcontrib-blockdiag-1.5.0/setup.cfg0000644000076600000240000000046512420126515020751 0ustar tkomiyastaff00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 [build] build-base = _build [sdist] formats = gztar [wheel] universal = 1 [aliases] release = check -r -s register sdist bdist_wheel upload [check] strict = 1 restructuredtext = 1 [flake8] max-line-length = 120 ignore = _ exclude = tests/docs/ sphinxcontrib-blockdiag-1.5.0/setup.py0000644000076600000240000000245112420126464020642 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- from setuptools import setup, find_packages requires = ['blockdiag>=1.4.1', 'Sphinx>=0.6', 'setuptools'] setup( name='sphinxcontrib-blockdiag', version='1.5.0', url='http://bitbucket.org/birkenfeld/sphinx-contrib', download_url='http://pypi.python.org/pypi/sphinxcontrib-blockdiag', license='BSD', author='Takeshi KOMIYA', author_email='i.tkomiya@gmail.com', description='Sphinx "blockdiag" extension', long_description=open("README.rst").read(), zip_safe=False, classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Console', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Topic :: Documentation', 'Topic :: Utilities', ], platforms='any', packages=find_packages(), include_package_data=True, install_requires=requires, namespace_packages=['sphinxcontrib'], ) sphinxcontrib-blockdiag-1.5.0/sphinxcontrib/0000755000076600000240000000000012420126515022015 5ustar tkomiyastaff00000000000000sphinxcontrib-blockdiag-1.5.0/sphinxcontrib/__init__.py0000644000076600000240000000055512251072275024140 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ sphinxcontrib ~~~~~~~~~~~~~ This package is a namespace package that contains all extensions distributed in the ``sphinx-contrib`` distribution. :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ __import__('pkg_resources').declare_namespace(__name__) sphinxcontrib-blockdiag-1.5.0/sphinxcontrib/blockdiag.py0000644000076600000240000002477612420117654024332 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ blockdiag.sphinx_ext ~~~~~~~~~~~~~~~~~~~~ Allow blockdiag-formatted diagrams to be included in Sphinx-generated documents inline. :copyright: Copyright 2010 by Takeshi Komiya. :license: BSDL. """ from __future__ import absolute_import import os import re import traceback from collections import namedtuple from docutils import nodes from sphinx import addnodes from sphinx.util.osutil import ensuredir import blockdiag.utils.rst.nodes import blockdiag.utils.rst.directives from blockdiag.utils.bootstrap import detectfont from blockdiag.utils.compat import u, string_types from blockdiag.utils.fontmap import FontMap # fontconfig; it will be initialized on `builder-inited` event. fontmap = None class blockdiag_node(blockdiag.utils.rst.nodes.blockdiag): def to_drawer(self, image_format, builder, **kwargs): if 'filename' in kwargs: filename = kwargs.pop('filename') else: filename = self.get_abspath(image_format, builder) antialias = builder.config.blockdiag_antialias transparency = builder.config.blockdiag_transparency image = super(blockdiag_node, self).to_drawer(image_format, filename, fontmap, antialias=antialias, transparency=transparency, **kwargs) for node in image.diagram.traverse_nodes(): node.href = resolve_reference(builder, node.href) return image def get_relpath(self, image_format, builder): options = dict(antialias=builder.config.blockdiag_antialias, fontpath=builder.config.blockdiag_fontpath, fontmap=builder.config.blockdiag_fontmap, format=image_format) outputdir = getattr(builder, 'imgpath', builder.outdir) return os.path.join(outputdir, self.get_path(**options)) def get_abspath(self, image_format, builder): options = dict(antialias=builder.config.blockdiag_antialias, fontpath=builder.config.blockdiag_fontpath, fontmap=builder.config.blockdiag_fontmap, format=image_format) if hasattr(builder, 'imagedir'): # Sphinx (>= 1.3.x) outputdir = os.path.join(builder.outdir, builder.imagedir) elif hasattr(builder, 'imgpath'): # Sphinx (<= 1.2.x) and HTML writer outputdir = os.path.join(builder.outdir, '_images') else: outputdir = builder.outdir path = os.path.join(outputdir, self.get_path(**options)) ensuredir(os.path.dirname(path)) return path class Blockdiag(blockdiag.utils.rst.directives.BlockdiagDirective): node_class = blockdiag_node def node2image(self, node, diagram): return node def resolve_reference(builder, href): if href is None: return None pattern = re.compile(u("^:ref:`(.+?)`"), re.UNICODE) matched = pattern.search(href) if matched is None: return href else: refid = matched.group(1) domain = builder.env.domains['std'] node = addnodes.pending_xref(refexplicit=False) xref = domain.resolve_xref(builder.env, builder.current_docname, builder, 'ref', refid, node, node) if xref: if 'refid' in xref: return "#" + xref['refid'] else: return xref['refuri'] else: builder.warn('undefined label: %s' % refid) return None def html_render_svg(self, node): image = node.to_drawer('SVG', self.builder, filename=None, nodoctype=True) image.draw() if 'align' in node['options']: align = node['options']['align'] self.body.append('
' % (align, align)) self.context.append('
\n') else: self.body.append('
') self.context.append('
\n') # reftarget for node_id in node['ids']: self.body.append('' % node_id) # resize image size = image.pagesize().resize(**node['options']) self.body.append(image.save(size)) self.context.append('') def html_render_clickablemap(self, image, width_ratio, height_ratio): href_nodes = [node for node in image.nodes if node.href] if not href_nodes: return self.body.append('' % id(image)) for node in href_nodes: x1, y1, x2, y2 = image.metrics.cell(node) x1 *= width_ratio x2 *= width_ratio y1 *= height_ratio y2 *= height_ratio areatag = '' % (x1, y1, x2, y2, node.href) self.body.append(areatag) self.body.append('') def html_render_png(self, node): image = node.to_drawer('PNG', self.builder) if not os.path.isfile(image.filename): image.draw() image.save() # align if 'align' in node['options']: align = node['options']['align'] self.body.append('
' % (align, align)) self.context.append('
\n') else: self.body.append('
') self.context.append('
') # link to original image relpath = node.get_relpath('PNG', self.builder) if 'width' in node['options'] or 'height' in node['options'] or 'scale' in node['options']: self.body.append('' % relpath) self.context.append('') else: self.context.append('') # tag original_size = image.pagesize() resized = original_size.resize(**node['options']) img_attr = dict(src=relpath, width=resized.width, height=resized.height) if any(node.href for node in image.nodes): img_attr['usemap'] = "#map_%d" % id(image) width_ratio = float(resized.width) / original_size.width height_ratio = float(resized.height) / original_size.height html_render_clickablemap(self, image, width_ratio, height_ratio) if 'alt' in node['options']: img_attr['alt'] = node['options']['alt'] self.body.append(self.starttag(node, 'img', '', empty=True, **img_attr)) def html_visit_blockdiag(self, node): try: image_format = get_image_format_for(self.builder) if image_format.upper() == 'SVG': html_render_svg(self, node) else: html_render_png(self, node) except UnicodeEncodeError: if self.builder.config.blockdiag_debug: traceback.print_exc() msg = ("blockdiag error: UnicodeEncodeError caught " "(check your font settings)") self.builder.warn(msg) raise nodes.SkipNode except Exception as exc: if self.builder.config.blockdiag_debug: traceback.print_exc() self.builder.warn('dot code %r: %s' % (node['code'], str(exc))) raise nodes.SkipNode def html_depart_blockdiag(self, node): self.body.append(self.context.pop()) self.body.append(self.context.pop()) def get_image_format_for(builder): if builder.format == 'html': image_format = builder.config.blockdiag_html_image_format.upper() elif builder.format == 'latex': if builder.config.blockdiag_tex_image_format: image_format = builder.config.blockdiag_tex_image_format.upper() else: image_format = builder.config.blockdiag_latex_image_format.upper() else: image_format = 'PNG' if image_format.upper() not in ('PNG', 'PDF', 'SVG'): raise ValueError('unknown format: %s' % image_format) if image_format.upper() == 'PDF': try: import reportlab # NOQA: importing test except ImportError: raise ImportError('Could not output PDF format. Install reportlab.') return image_format def on_builder_inited(self): # show deprecated message if self.builder.config.blockdiag_tex_image_format: self.builder.warn('blockdiag_tex_image_format is deprecated. Use blockdiag_latex_image_format.') # initialize fontmap global fontmap try: fontmappath = self.builder.config.blockdiag_fontmap fontmap = FontMap(fontmappath) except: fontmap = FontMap(None) try: fontpath = self.builder.config.blockdiag_fontpath if isinstance(fontpath, string_types): fontpath = [fontpath] if fontpath: config = namedtuple('Config', 'font')(fontpath) fontpath = detectfont(config) fontmap.set_default_font(fontpath) except: pass def on_doctree_resolved(self, doctree, docname): if self.builder.format == 'html': return try: image_format = get_image_format_for(self.builder) except Exception as exc: if self.builder.config.blockdiag_debug: traceback.print_exc() self.builder.warn('blockdiag error: %s' % exc) for node in doctree.traverse(blockdiag_node): node.parent.remove(node) return for node in doctree.traverse(blockdiag_node): try: relfn = node.get_relpath(image_format, self.builder) image = node.to_drawer(image_format, self.builder) if not os.path.isfile(image.filename): image.draw() image.save() image = nodes.image(uri=image.filename, candidates={'*': relfn}, **node['options']) node.parent.replace(node, image) except Exception as exc: if self.builder.config.blockdiag_debug: traceback.print_exc() self.builder.warn('dot code %r: %s' % (node['code'], str(exc))) node.parent.remove(node) def setup(app): app.add_node(blockdiag_node, html=(html_visit_blockdiag, html_depart_blockdiag)) app.add_directive('blockdiag', Blockdiag) app.add_config_value('blockdiag_fontpath', None, 'html') app.add_config_value('blockdiag_fontmap', None, 'html') app.add_config_value('blockdiag_antialias', False, 'html') app.add_config_value('blockdiag_transparency', True, 'html') app.add_config_value('blockdiag_debug', False, 'html') app.add_config_value('blockdiag_html_image_format', 'PNG', 'html') app.add_config_value('blockdiag_tex_image_format', None, 'html') # backward compatibility for 1.3.1 app.add_config_value('blockdiag_latex_image_format', 'PNG', 'html') app.connect("builder-inited", on_builder_inited) app.connect("doctree-resolved", on_doctree_resolved) sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/0000755000076600000240000000000012420126515025506 5ustar tkomiyastaff00000000000000sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/dependency_links.txt0000644000076600000240000000000112420126507031555 0ustar tkomiyastaff00000000000000 sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/namespace_packages.txt0000644000076600000240000000001612420126507032037 0ustar tkomiyastaff00000000000000sphinxcontrib sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/not-zip-safe0000644000076600000240000000000112051437475027746 0ustar tkomiyastaff00000000000000 sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/PKG-INFO0000644000076600000240000000320112420126507026600 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-blockdiag Version: 1.5.0 Summary: Sphinx "blockdiag" extension Home-page: http://bitbucket.org/birkenfeld/sphinx-contrib Author: Takeshi KOMIYA Author-email: i.tkomiya@gmail.com License: BSD Download-URL: http://pypi.python.org/pypi/sphinxcontrib-blockdiag Description: ======================= sphinxcontrib-blockdiag ======================= A sphinx extension for embedding block diagram using blockdiag_. This extension enables you to insert block diagrams into your document. Following code is an example:: .. blockdiag:: diagram { A -> B -> C; B -> D; } .. _blockdiag: http://bitbucket.org/blockdiag/blockdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/blockdiag/sphinxcontrib.html Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/requires.txt0000644000076600000240000000005012420126507030102 0ustar tkomiyastaff00000000000000blockdiag>=1.4.1 Sphinx>=0.6 setuptools sphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/SOURCES.txt0000644000076600000240000000104012420126510027360 0ustar tkomiyastaff00000000000000AUTHORS LICENSE MANIFEST.in README.rst setup.cfg setup.py sphinxcontrib/__init__.py sphinxcontrib/blockdiag.py sphinxcontrib_blockdiag.egg-info/PKG-INFO sphinxcontrib_blockdiag.egg-info/SOURCES.txt sphinxcontrib_blockdiag.egg-info/dependency_links.txt sphinxcontrib_blockdiag.egg-info/namespace_packages.txt sphinxcontrib_blockdiag.egg-info/not-zip-safe sphinxcontrib_blockdiag.egg-info/requires.txt sphinxcontrib_blockdiag.egg-info/top_level.txt tests/__init__.py tests/test_basic.py tests/test_errors.py tests/test_html.py tests/test_latex.pysphinxcontrib-blockdiag-1.5.0/sphinxcontrib_blockdiag.egg-info/top_level.txt0000644000076600000240000000002412420126507030235 0ustar tkomiyastaff00000000000000sphinxcontrib tests sphinxcontrib-blockdiag-1.5.0/tests/0000755000076600000240000000000012420126515020265 5ustar tkomiyastaff00000000000000sphinxcontrib-blockdiag-1.5.0/tests/__init__.py0000644000076600000240000000000012251072275022371 0ustar tkomiyastaff00000000000000sphinxcontrib-blockdiag-1.5.0/tests/test_basic.py0000644000076600000240000000133212417455577023001 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- from sphinx_testing import with_app @with_app(buildername='html', srcdir='tests/docs/basic/') def test_build_html(app, status, warning): app.builder.build_all() @with_app(buildername='singlehtml', srcdir='tests/docs/basic/') def test_build_singlehtml(app, status, warning): app.builder.build_all() @with_app(buildername='latex', srcdir='tests/docs/basic/') def test_build_latex(app, status, warning): app.builder.build_all() @with_app(buildername='epub', srcdir='tests/docs/basic/') def test_build_epub(app, status, warning): app.builder.build_all() @with_app(buildername='json', srcdir='tests/docs/basic/') def test_build_json(app, status, warning): app.builder.build_all() sphinxcontrib-blockdiag-1.5.0/tests/test_errors.py0000644000076600000240000000411212417512703023214 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- from mock import patch from sphinx_testing import with_app from blockdiag.utils.compat import u import sys if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest class TestSphinxcontribBlockdiagErrors(unittest.TestCase): @with_app(srcdir='tests/docs/basic', write_docstring=True) def test_parse_error(self, app, status, warning): """ .. blockdiag:: { A -> B; """ app.builder.build_all() self.assertIn('got unexpected token:', warning.getvalue()) @with_app(srcdir='tests/docs/basic', confoverrides=dict(blockdiag_html_image_format='JPG')) def test_unknown_format_error(self, app, status, warning): app.builder.build_all() self.assertIn('unknown format: JPG', warning.getvalue()) @with_app(srcdir='tests/docs/basic', confoverrides=dict(blockdiag_html_image_format='PDF')) def test_reportlab_not_found_error(self, app, status, warning): try: # unload reportlab and make loading it impossible sys.modules.pop('reportlab', None) path = sys.path sys.path = [] app.builder.build_all() self.assertIn('Could not output PDF format. Install reportlab.', warning.getvalue()) finally: sys.path = path @with_app(srcdir='tests/docs/basic') @patch("blockdiag.utils.rst.nodes.blockdiag.processor.drawer.DiagramDraw") def test_rendering_error(self, app, status, warning, DiagramDraw): DiagramDraw.side_effect = RuntimeError("UNKNOWN ERROR!") app.builder.build_all() self.assertIn('UNKNOWN ERROR!', warning.getvalue()) @with_app(srcdir='tests/docs/basic') @patch("sphinxcontrib.blockdiag.blockdiag.drawer.DiagramDraw.draw") def test_font_settings_error(self, app, status, warning, draw): draw.side_effect = UnicodeEncodeError("", u(""), 0, 0, "") app.builder.build_all() self.assertIn('UnicodeEncodeError caught (check your font settings)', warning.getvalue()) sphinxcontrib-blockdiag-1.5.0/tests/test_html.py0000644000076600000240000003065012417466727022670 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- from sphinx_testing import with_app import sys if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest with_png_app = with_app(srcdir='tests/docs/basic', buildername='html', write_docstring=True) with_svg_app = with_app(srcdir='tests/docs/basic', buildername='html', write_docstring=True, confoverrides={ 'blockdiag_html_image_format': 'SVG' }) class TestSphinxcontribBlockdiagHTML(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. blockdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_png_app def test_width_option_on_png(self, app, status, warning): """ .. blockdiag:: :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_height_option_on_png(self, app, status, warning): """ .. blockdiag:: :height: 240 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_width_option_and_height_option_on_png(self, app, status, warning): """ .. blockdiag:: :width: 100 :height: 200 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text() self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_scale_option_on_png(self, app, status, warning): """ .. blockdiag:: :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_width_option_and_scale_option_on_png(self, app, status, warning): """ .. blockdiag:: :width: 28 :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_align_option_on_png(self, app, status, warning): """ .. blockdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_png_app def test_align_option_and_width_option_on_png(self, app, status, warning): """ .. blockdiag:: :align: center :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '' '
')) @with_png_app def test_name_option_on_png(self, app, status, warning): """ .. blockdiag:: :name: target A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_png_app def test_name_option_and_width_option_on_png(self, app, status, warning): """ .. blockdiag:: :name: target :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_href_and_scale_option_on_png(self, app, status, warning): """ .. blockdiag:: :scale: 50% A -> B; A [href = 'http://blockdiag.com/']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '' '' '
')) @with_png_app def test_reftarget_in_href_on_png1(self, app, status, warning): """ .. _target: heading2 --------- .. blockdiag:: A -> B; A [href = ':ref:`target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '' '
')) @with_png_app def test_reftarget_in_href_on_png2(self, app, status, warning): """ .. _hello world: heading2 --------- .. blockdiag:: A -> B; A [href = ':ref:`hello world`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '' '
')) @with_png_app def test_missing_reftarget_in_href_on_png(self, app, status, warning): """ .. blockdiag:: A -> B; A [href = ':ref:`unknown_target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
')) self.assertIn('undefined label: unknown_target', warning.getvalue()) @with_app(srcdir='tests/docs/basic', copy_srcdir_to_tmpdir=True, write_docstring=True, confoverrides={'blockdiag_html_image_format': 'SVG'}) def test_build_svg_image(self, app, status, warning): """ .. blockdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_width_option_on_svg(self, app, status, warning): """ .. blockdiag:: :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_height_option_on_svg(self, app, status, warning): """ .. blockdiag:: :height: 240 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_width_option_and_height_option_on_svg(self, app, status, warning): """ .. blockdiag:: :width: 100 :height: 200 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_scale_option_on_svg(self, app, status, warning): """ .. blockdiag:: :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_width_option_and_scale_option_on_svg(self, app, status, warning): """ .. blockdiag:: :width: 28 :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_align_option_on_svg(self, app, status, warning): """ .. blockdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_name_option_on_svg(self, app, status, warning): """ .. blockdiag:: :name: target A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '
') @with_svg_app def test_reftarget_in_href_on_svg1(self, app, status, warning): """ .. _target: heading2 --------- .. blockdiag:: A -> B; A [href = ':ref:`target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\n\\s*\\n\\s*') @with_svg_app def test_reftarget_in_href_on_svg2(self, app, status, warning): """ .. _hello world: heading2 --------- .. blockdiag:: A -> B; A [href = ':ref:`hello world`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\n\\s*\\n\\s*') @with_svg_app def test_missing_reftarget_in_href_on_svg(self, app, status, warning): """ .. blockdiag:: A -> B; A [href = ':ref:`unknown_target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') if sys.version_info < (3, 0): self.assertNotRegexpMatches(source, '\\n\\s*\\n\\s*') else: self.assertNotRegex(source, '\\n\\s*\\n\\s*') self.assertIn('undefined label: unknown_target', warning.getvalue()) ����������������������������������������������������������������������������������������sphinxcontrib-blockdiag-1.5.0/tests/test_latex.py���������������������������������������������������0000644�0000766�0000024�00000014501�12417745573�023035� 0����������������������������������������������������������������������������������������������������ustar �tkomiya�������������������������staff���������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# -*- coding: utf-8 -*- import os import re from sphinx_testing import with_app from blockdiag.utils.compat import u import sys if sys.version_info < (2, 7): import unittest2 as unittest else: import unittest blockdiag_fontpath = '/usr/share/fonts/truetype/ipafont/ipagp.ttf' with_png_app = with_app(srcdir='tests/docs/basic', buildername='latex', write_docstring=True, confoverrides={ 'latex_documents': [('index', 'test.tex', u(''), u('test'), 'manual')], }) with_pdf_app = with_app(srcdir='tests/docs/basic', buildername='latex', write_docstring=True, confoverrides={ 'latex_documents': [('index', 'test.tex', u(''), u('test'), 'manual')], 'blockdiag_latex_image_format': 'PDF', 'blockdiag_fontpath': blockdiag_fontpath, }) with_oldpdf_app = with_app(srcdir='tests/docs/basic', buildername='latex', write_docstring=True, confoverrides={ 'latex_documents': [('index', 'test.tex', u(''), u('test'), 'manual')], 'blockdiag_tex_image_format': 'PDF', 'blockdiag_fontpath': blockdiag_fontpath, }) class TestSphinxcontribBlockdiagLatex(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. blockdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/blockdiag-.*?.png}') @unittest.skipUnless(os.path.exists(blockdiag_fontpath), "TrueType font not found") @unittest.skipIf(sys.version_info[:2] == (3, 2), "reportlab does not support python 3.2") @with_pdf_app def test_build_pdf_image1(self, app, status, warning): """ .. blockdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/blockdiag-.*?.pdf}') @unittest.skipUnless(os.path.exists(blockdiag_fontpath), "TrueType font not found") @unittest.skipIf(sys.version_info[:2] == (3, 2), "reportlab does not support python 3.2") @with_oldpdf_app def test_build_pdf_image2(self, app, status, warning): """ .. blockdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/blockdiag-.*?.pdf}') @with_png_app def test_width_option(self, app, status, warning): """ .. blockdiag:: :width: 3cm A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics\\[width=3cm\\]{.*?/latex/blockdiag-.*?.png}') @with_png_app def test_height_option(self, app, status, warning): """ .. blockdiag:: :height: 4cm A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics\\[height=4cm\\]{.*?/latex/blockdiag-.*?.png}') @with_png_app def test_scale_option(self, app, status, warning): """ .. blockdiag:: :scale: 50% A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\scalebox{0.500000}{\\\\includegraphics{.*?/latex/blockdiag-.*?.png}}') @with_png_app def test_align_option_left(self, app, status, warning): """ .. blockdiag:: :align: left A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\includegraphics{.*?/latex/blockdiag-.*?.png}\\\\hfill}') @with_png_app def test_align_option_center(self, app, status, warning): """ .. blockdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{.*?/latex/blockdiag-.*?.png}\\\\hfill}') @with_png_app def test_align_option_right(self, app, status, warning): """ .. blockdiag:: :align: right A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{.*?/latex/blockdiag-.*?.png}}') @with_png_app def test_caption_option(self, app, status, warning): """ .. blockdiag:: :caption: hello world A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/blockdiag-.*?.png}') figure = re.compile('\\\\begin{figure}\\[htbp\\]\n\\\\centering.*?' '\\\\caption{hello world}\\\\end{figure}', re.DOTALL) self.assertRegexpMatches(source, figure) @with_png_app def test_caption_option_and_align_option(self, app, status, warning): """ .. blockdiag:: :align: left :caption: hello world A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/blockdiag-.*?.png}') figure = re.compile('\\\\begin{figure}\\[htbp\\]\\\\begin{flushleft}.*?' '\\\\caption{hello world}\\\\end{flushleft}\\\\end{figure}', re.DOTALL) self.assertRegexpMatches(source, figure) ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������