sphinxcontrib-actdiag-0.8.0/0000755000076600000240000000000012420130152016572 5ustar tkomiyastaff00000000000000sphinxcontrib-actdiag-0.8.0/AUTHORS0000644000076600000240000000004512022072632017647 0ustar tkomiyastaff00000000000000Takeshi KOMIYA sphinxcontrib-actdiag-0.8.0/LICENSE0000644000076600000240000000261212022072632017606 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-actdiag-0.8.0/MANIFEST.in0000644000076600000240000000010112022072632020326 0ustar tkomiyastaff00000000000000include AUTHORS include LICENSE include README include CHANGES.* sphinxcontrib-actdiag-0.8.0/PKG-INFO0000644000076600000240000000326212420130152017672 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-actdiag Version: 0.8.0 Summary: Sphinx "actdiag" 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-actdiag Description: ===================== sphinxcontrib-actdiag ===================== A sphinx extension for embedding activity diagram using actdiag_. This extension enables you to insert activity diagrams into your document. Following code is an example:: .. actdiag:: actdiag { A -> B -> C -> D; lane { A; B; } lane { C; D; } } .. _actdiag: http://bitbucket.org/blockdiag/actdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/actdiag/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: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-actdiag-0.8.0/README.rst0000644000076600000240000000112512420130053020260 0ustar tkomiyastaff00000000000000===================== sphinxcontrib-actdiag ===================== A sphinx extension for embedding activity diagram using actdiag_. This extension enables you to insert activity diagrams into your document. Following code is an example:: .. actdiag:: actdiag { A -> B -> C -> D; lane { A; B; } lane { C; D; } } .. _actdiag: http://bitbucket.org/blockdiag/actdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/actdiag/sphinxcontrib.html sphinxcontrib-actdiag-0.8.0/setup.cfg0000644000076600000240000000046512420130152020420 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-actdiag-0.8.0/setup.py0000644000076600000240000000235712420130122020310 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- from setuptools import setup, find_packages requires = ['actdiag>=0.5.3', 'Sphinx>=0.6', 'setuptools'] setup( name='sphinxcontrib-actdiag', version='0.8.0', url='http://bitbucket.org/birkenfeld/sphinx-contrib', download_url='http://pypi.python.org/pypi/sphinxcontrib-actdiag', license='BSD', author='Takeshi KOMIYA', author_email='i.tkomiya@gmail.com', description='Sphinx "actdiag" 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', 'Topic :: Documentation', 'Topic :: Utilities', ], platforms='any', packages=find_packages(), include_package_data=True, install_requires=requires, namespace_packages=['sphinxcontrib'], ) sphinxcontrib-actdiag-0.8.0/sphinxcontrib/0000755000076600000240000000000012420130152021464 5ustar tkomiyastaff00000000000000sphinxcontrib-actdiag-0.8.0/sphinxcontrib/__init__.py0000644000076600000240000000055512355541477023631 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-actdiag-0.8.0/sphinxcontrib/actdiag.py0000644000076600000240000002462212420127530023446 0ustar tkomiyastaff00000000000000# -*- coding: utf-8 -*- """ actdiag.sphinx_ext ~~~~~~~~~~~~~~~~~~~~ Allow actdiag-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 actdiag.utils.rst.nodes import actdiag.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 actdiag_node(actdiag.utils.rst.nodes.actdiag): 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.actdiag_antialias transparency = builder.config.actdiag_transparency image = super(actdiag_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.actdiag_antialias, fontpath=builder.config.actdiag_fontpath, fontmap=builder.config.actdiag_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.actdiag_antialias, fontpath=builder.config.actdiag_fontpath, fontmap=builder.config.actdiag_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 Actdiag(actdiag.utils.rst.directives.ActdiagDirective): node_class = actdiag_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_actdiag(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.actdiag_debug: traceback.print_exc() msg = ("actdiag error: UnicodeEncodeError caught " "(check your font settings)") self.builder.warn(msg) raise nodes.SkipNode except Exception as exc: if self.builder.config.actdiag_debug: traceback.print_exc() self.builder.warn('dot code %r: %s' % (node['code'], str(exc))) raise nodes.SkipNode def html_depart_actdiag(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.actdiag_html_image_format.upper() elif builder.format == 'latex': if builder.config.actdiag_tex_image_format: image_format = builder.config.actdiag_tex_image_format.upper() else: image_format = builder.config.actdiag_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.actdiag_tex_image_format: self.builder.warn('actdiag_tex_image_format is deprecated. Use actdiag_latex_image_format.') # initialize fontmap global fontmap try: fontmappath = self.builder.config.actdiag_fontmap fontmap = FontMap(fontmappath) except: fontmap = FontMap(None) try: fontpath = self.builder.config.actdiag_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.actdiag_debug: traceback.print_exc() self.builder.warn('actdiag error: %s' % exc) for node in doctree.traverse(actdiag_node): node.parent.remove(node) return for node in doctree.traverse(actdiag_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.actdiag_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(actdiag_node, html=(html_visit_actdiag, html_depart_actdiag)) app.add_directive('actdiag', Actdiag) app.add_config_value('actdiag_fontpath', None, 'html') app.add_config_value('actdiag_fontmap', None, 'html') app.add_config_value('actdiag_antialias', False, 'html') app.add_config_value('actdiag_transparency', True, 'html') app.add_config_value('actdiag_debug', False, 'html') app.add_config_value('actdiag_html_image_format', 'PNG', 'html') app.add_config_value('actdiag_tex_image_format', None, 'html') # backward compatibility for 0.6.1 app.add_config_value('actdiag_latex_image_format', 'PNG', 'html') app.connect("builder-inited", on_builder_inited) app.connect("doctree-resolved", on_doctree_resolved) sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/0000755000076600000240000000000012420130152024632 5ustar tkomiyastaff00000000000000sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/dependency_links.txt0000644000076600000240000000000112420130141030676 0ustar tkomiyastaff00000000000000 sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/namespace_packages.txt0000644000076600000240000000001612420130141031160 0ustar tkomiyastaff00000000000000sphinxcontrib sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/not-zip-safe0000644000076600000240000000000112051454204027067 0ustar tkomiyastaff00000000000000 sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/PKG-INFO0000644000076600000240000000326212420130141025730 0ustar tkomiyastaff00000000000000Metadata-Version: 1.1 Name: sphinxcontrib-actdiag Version: 0.8.0 Summary: Sphinx "actdiag" 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-actdiag Description: ===================== sphinxcontrib-actdiag ===================== A sphinx extension for embedding activity diagram using actdiag_. This extension enables you to insert activity diagrams into your document. Following code is an example:: .. actdiag:: actdiag { A -> B -> C -> D; lane { A; B; } lane { C; D; } } .. _actdiag: http://bitbucket.org/blockdiag/actdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/actdiag/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: Topic :: Documentation Classifier: Topic :: Utilities sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/requires.txt0000644000076600000240000000004612420130141027230 0ustar tkomiyastaff00000000000000actdiag>=0.5.3 Sphinx>=0.6 setuptools sphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/SOURCES.txt0000644000076600000240000000102012420130142026506 0ustar tkomiyastaff00000000000000AUTHORS LICENSE MANIFEST.in README.rst setup.cfg setup.py sphinxcontrib/__init__.py sphinxcontrib/actdiag.py sphinxcontrib_actdiag.egg-info/PKG-INFO sphinxcontrib_actdiag.egg-info/SOURCES.txt sphinxcontrib_actdiag.egg-info/dependency_links.txt sphinxcontrib_actdiag.egg-info/namespace_packages.txt sphinxcontrib_actdiag.egg-info/not-zip-safe sphinxcontrib_actdiag.egg-info/requires.txt sphinxcontrib_actdiag.egg-info/top_level.txt tests/__init__.py tests/test_basic.py tests/test_errors.py tests/test_html.py tests/test_latex.pysphinxcontrib-actdiag-0.8.0/sphinxcontrib_actdiag.egg-info/top_level.txt0000644000076600000240000000002412420130141027356 0ustar tkomiyastaff00000000000000sphinxcontrib tests sphinxcontrib-actdiag-0.8.0/tests/0000755000076600000240000000000012420130152017734 5ustar tkomiyastaff00000000000000sphinxcontrib-actdiag-0.8.0/tests/__init__.py0000644000076600000240000000000012355541477022062 0ustar tkomiyastaff00000000000000sphinxcontrib-actdiag-0.8.0/tests/test_basic.py0000644000076600000240000000133212417626003022440 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-actdiag-0.8.0/tests/test_errors.py0000644000076600000240000000407112417626003022676 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 TestSphinxcontribActdiagErrors(unittest.TestCase): @with_app(srcdir='tests/docs/basic', write_docstring=True) def test_parse_error(self, app, status, warning): """ .. actdiag:: { A -> B; """ app.builder.build_all() self.assertIn('got unexpected token:', warning.getvalue()) @with_app(srcdir='tests/docs/basic', confoverrides=dict(actdiag_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(actdiag_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("actdiag.utils.rst.nodes.actdiag.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.actdiag.actdiag.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-actdiag-0.8.0/tests/test_html.py0000644000076600000240000003037712417626003022336 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={ 'actdiag_html_image_format': 'SVG', }) class TestSphinxcontribActdiagHTML(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. actdiag:: 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): """ .. actdiag:: :width: 128 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): """ .. actdiag:: :height: 140 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): """ .. actdiag:: :width: 100 :height: 200 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, ('
' '
')) @with_png_app def test_scale_option_on_png(self, app, status, warning): """ .. actdiag:: :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): """ .. actdiag:: :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): """ .. actdiag:: :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): """ .. actdiag:: :align: center :width: 128 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): """ .. actdiag:: :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): """ .. actdiag:: :name: target :width: 128 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): """ .. actdiag:: :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 --------- .. actdiag:: 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 --------- .. actdiag:: 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): """ .. actdiag:: 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_svg_app def test_build_svg_image(self, app, status, warning): """ .. actdiag:: 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): """ .. actdiag:: :width: 128 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): """ .. actdiag:: :height: 140 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): """ .. actdiag:: :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): """ .. actdiag:: :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): """ .. actdiag:: :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): """ .. actdiag:: :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): """ .. actdiag:: :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 --------- .. actdiag:: 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 --------- .. actdiag:: 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): """ .. actdiag:: 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-actdiag-0.8.0/tests/test_latex.py�����������������������������������������������������0000644�0000766�0000024�00000014401�12417747207�022507� 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 actdiag_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')], 'actdiag_latex_image_format': 'PDF', 'actdiag_fontpath': actdiag_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')], 'actdiag_tex_image_format': 'PDF', 'actdiag_fontpath': actdiag_fontpath, }) class TestSphinxcontribActdiagLatex(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. actdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/actdiag-.*?.png}') @unittest.skipUnless(os.path.exists(actdiag_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): """ .. actdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/actdiag-.*?.pdf}') @unittest.skipUnless(os.path.exists(actdiag_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): """ .. actdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/actdiag-.*?.pdf}') @with_png_app def test_width_option(self, app, status, warning): """ .. actdiag:: :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/actdiag-.*?.png}') @with_png_app def test_height_option(self, app, status, warning): """ .. actdiag:: :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/actdiag-.*?.png}') @with_png_app def test_scale_option(self, app, status, warning): """ .. actdiag:: :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/actdiag-.*?.png}}') @with_png_app def test_align_option_left(self, app, status, warning): """ .. actdiag:: :align: left A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\includegraphics{.*?/latex/actdiag-.*?.png}\\\\hfill}') @with_png_app def test_align_option_center(self, app, status, warning): """ .. actdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{.*?/latex/actdiag-.*?.png}\\\\hfill}') @with_png_app def test_align_option_right(self, app, status, warning): """ .. actdiag:: :align: right A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '{\\\\hfill\\\\includegraphics{.*?/latex/actdiag-.*?.png}}') @with_png_app def test_caption_option(self, app, status, warning): """ .. actdiag:: :caption: hello world A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, '\\\\includegraphics{.*?/latex/actdiag-.*?.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): """ .. actdiag:: :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/actdiag-.*?.png}') figure = re.compile('\\\\begin{figure}\\[htbp\\]\\\\begin{flushleft}.*?' '\\\\caption{hello world}\\\\end{flushleft}\\\\end{figure}', re.DOTALL) self.assertRegexpMatches(source, figure) �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������