pax_global_header00006660000000000000000000000064141531454150014515gustar00rootroot0000000000000052 comment=4510d472013546dd04e0819c6b988685955a505e sphinxcontrib-seqdiag-3.0.0/000077500000000000000000000000001415314541500160225ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/.codeclimate.yml000066400000000000000000000000701415314541500210710ustar00rootroot00000000000000languages: Python: true exclude_paths: - "tests/*.py" sphinxcontrib-seqdiag-3.0.0/.github/000077500000000000000000000000001415314541500173625ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/.github/workflows/000077500000000000000000000000001415314541500214175ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/.github/workflows/release.yml000066400000000000000000000012131415314541500235570ustar00rootroot00000000000000name: Release a new package on: push: tags: - '*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: pip install docutils setuptools wheel - name: Build package run: python setup.py sdist bdist_wheel - name: Upload package to PyPI uses: pypa/gh-action-pypi-publish@master if: startsWith(github.ref, 'refs/tags/') with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} sphinxcontrib-seqdiag-3.0.0/.github/workflows/test.yml000066400000000000000000000015231415314541500231220ustar00rootroot00000000000000name: CI on: [push, pull_request] jobs: ubuntu: runs-on: ubuntu-latest strategy: fail-fast: false matrix: name: [py37, py38, py39, blockdiag_dev] include: - name: py37 python: 3.7 toxenv: py37 - name: py38 python: 3.8 toxenv: py38 - name: py39 python: 3.9 toxenv: py39 - name: blockdiag_dev python: 3.9 toxenv: blockdiag_dev steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python }} - name: Check Python version run: python --version - name: Install dependencies run: pip install -U tox - name: Run Tox run: tox -e ${{ matrix.toxenv }} -- -vv sphinxcontrib-seqdiag-3.0.0/.gitignore000066400000000000000000000001021415314541500200030ustar00rootroot00000000000000*.egg-info *.pyc .coverage .tox/ .mypy_cache/ bin/ include/ lib/ sphinxcontrib-seqdiag-3.0.0/AUTHORS000066400000000000000000000000451415314541500170710ustar00rootroot00000000000000Takeshi KOMIYA sphinxcontrib-seqdiag-3.0.0/LICENSE000066400000000000000000000026121415314541500170300ustar00rootroot00000000000000If 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-seqdiag-3.0.0/MANIFEST.in000066400000000000000000000001051415314541500175540ustar00rootroot00000000000000include AUTHORS include LICENSE include README.rst include CHANGES.* sphinxcontrib-seqdiag-3.0.0/README.rst000066400000000000000000000017751415314541500175230ustar00rootroot00000000000000===================== sphinxcontrib-seqdiag ===================== .. image:: https://travis-ci.org/blockdiag/sphinxcontrib-seqdiag.svg?branch=master :target: https://travis-ci.org/blockdiag/sphinxcontrib-seqdiag .. image:: https://coveralls.io/repos/blockdiag/sphinxcontrib-seqdiag/badge.png?branch=master :target: https://coveralls.io/r/blockdiag/sphinxcontrib-seqdiag?branch=master .. image:: https://codeclimate.com/github/blockdiag/sphinxcontrib-seqdiag/badges/gpa.svg :target: https://codeclimate.com/github/blockdiag/sphinxcontrib-seqdiag A sphinx extension for embedding sequence diagram using seqdiag_. This extension enables you to insert sequence diagrams into your document. Following code is an example:: .. seqdiag:: seqdiag { browser => webserver => database; } .. _seqdiag: http://bitbucket.org/blockdiag/seqdiag/ For more details, see `online documentation`_ at http://blockdiag.com/. .. _online documentation: http://blockdiag.com/en/seqdiag/sphinxcontrib.html sphinxcontrib-seqdiag-3.0.0/setup.cfg000066400000000000000000000004231415314541500176420ustar00rootroot00000000000000[egg_info] ;tag_build = dev [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=W504 exclude=tests/docs/ sphinxcontrib-seqdiag-3.0.0/setup.py000066400000000000000000000026061415314541500175400ustar00rootroot00000000000000# -*- coding: utf-8 -*- from setuptools import setup, find_packages requires = ['blockdiag>=1.5.0', 'seqdiag>=0.9.3', 'Sphinx>=2.0'] setup( name='sphinxcontrib-seqdiag', version='3.0.0', url='https://github.com/blockdiag/sphinxcontrib-seqdiag', license='BSD', author='Takeshi KOMIYA', author_email='i.tkomiya@gmail.com', description='Sphinx "seqdiag" extension', long_description=open('README.rst').read(), zip_safe=False, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Environment :: Web Environment', 'Framework :: Sphinx :: Extension', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Topic :: Documentation', 'Topic :: Documentation :: Sphinx', 'Topic :: Utilities', ], platforms='any', packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, python_requires=">=3.7", install_requires=requires, namespace_packages=['sphinxcontrib'], ) sphinxcontrib-seqdiag-3.0.0/sphinxcontrib/000077500000000000000000000000001415314541500207145ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/sphinxcontrib/__init__.py000066400000000000000000000005551415314541500230320ustar00rootroot00000000000000# -*- 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-seqdiag-3.0.0/sphinxcontrib/seqdiag.py000066400000000000000000000255111415314541500227070ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ seqdiag.sphinx_ext ~~~~~~~~~~~~~~~~~~~~ Allow seqdiag-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 posixpath import traceback import pkg_resources from collections import namedtuple from docutils import nodes from sphinx import addnodes from sphinx.util import logging from sphinx.util.osutil import ensuredir import seqdiag.utils.rst.nodes import seqdiag.utils.rst.directives from blockdiag.utils.bootstrap import detectfont, Application from blockdiag.utils.fontmap import FontMap from blockdiag.utils.rst.directives import with_blockdiag # fontconfig; it will be initialized on `builder-inited` event. fontmap = None logger = logging.getLogger(__name__) class seqdiag_node(seqdiag.utils.rst.nodes.seqdiag): 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.seqdiag_antialias transparency = builder.config.seqdiag_transparency image = super(seqdiag_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.seqdiag_antialias, fontpath=builder.config.seqdiag_fontpath, fontmap=builder.config.seqdiag_fontmap, format=image_format, transparency=builder.config.seqdiag_transparency) if hasattr(builder, 'imgpath'): # Sphinx (<= 1.2.x) or HTML writer outputdir = builder.imgpath else: outputdir = '' return posixpath.join(outputdir, self.get_path(**options)) def get_abspath(self, image_format, builder): options = dict(antialias=builder.config.seqdiag_antialias, fontpath=builder.config.seqdiag_fontpath, fontmap=builder.config.seqdiag_fontmap, format=image_format, transparency=builder.config.seqdiag_transparency) 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 Seqdiag(seqdiag.utils.rst.directives.SeqdiagDirective): node_class = seqdiag_node def node2image(self, node, diagram): return node def resolve_reference(builder, href): if href is None: return None pattern = re.compile("^:ref:`(.+?)`", re.UNICODE) matched = pattern.search(href) if matched is None: return href elif not hasattr(builder, 'current_docname'): # ex. latex builder return matched.group(1) 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: logger.warning('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() # align align = node['options'].get('align', 'default') self.body.append('
' % align) 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 align = node['options'].get('align', 'default') self.body.append('
' % align) self.context.append('
\n') # 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)) @with_blockdiag def html_visit_seqdiag(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.seqdiag_debug: traceback.print_exc() msg = ("seqdiag error: UnicodeEncodeError caught " "(check your font settings)") logger.warning(msg) raise nodes.SkipNode except Exception as exc: if self.builder.config.seqdiag_debug: traceback.print_exc() logger.warning('dot code %r: %s', node['code'], exc) raise nodes.SkipNode def html_depart_seqdiag(self, node): self.body.append(self.context.pop()) self.body.append(self.context.pop()) def get_image_format_for(builder): if builder.format in ('html', 'slides'): image_format = builder.config.seqdiag_html_image_format.upper() elif builder.format == 'latex': if builder.config.seqdiag_tex_image_format: image_format = builder.config.seqdiag_tex_image_format.upper() else: image_format = builder.config.seqdiag_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.seqdiag_tex_image_format: logger.warning('seqdiag_tex_image_format is deprecated. Use seqdiag_latex_image_format.') # initialize fontmap global fontmap try: fontmappath = self.builder.config.seqdiag_fontmap fontmap = FontMap(fontmappath) except Exception: fontmap = FontMap(None) try: fontpath = self.builder.config.seqdiag_fontpath if isinstance(fontpath, str): fontpath = [fontpath] if fontpath: config = namedtuple('Config', 'font')(fontpath) fontpath = detectfont(config) fontmap.set_default_font(fontpath) except Exception: pass def on_doctree_resolved(self, doctree, docname): if self.builder.format in ('html', 'slides'): return try: image_format = get_image_format_for(self.builder) except Exception as exc: if self.builder.config.seqdiag_debug: traceback.print_exc() logger.warning('seqdiag error: %s', exc) for node in doctree.traverse(seqdiag_node): node.parent.remove(node) return for node in doctree.traverse(seqdiag_node): try: with Application(): 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=relfn, candidates={'*': relfn}, **node['options']) node.parent.replace(node, image) except Exception as exc: if self.builder.config.seqdiag_debug: traceback.print_exc() logger.warning('dot code %r: %s', node['code'], exc) node.parent.remove(node) def setup(app): app.add_node(seqdiag_node, html=(html_visit_seqdiag, html_depart_seqdiag)) app.add_directive('seqdiag', Seqdiag) app.add_config_value('seqdiag_fontpath', None, 'html') app.add_config_value('seqdiag_fontmap', None, 'html') app.add_config_value('seqdiag_antialias', False, 'html') app.add_config_value('seqdiag_transparency', True, 'html') app.add_config_value('seqdiag_debug', False, 'html') app.add_config_value('seqdiag_html_image_format', 'PNG', 'html') app.add_config_value('seqdiag_tex_image_format', None, 'html') # backward compatibility for 0.6.1 app.add_config_value('seqdiag_latex_image_format', 'PNG', 'html') app.connect("builder-inited", on_builder_inited) app.connect("doctree-resolved", on_doctree_resolved) return { 'version': pkg_resources.require('seqdiag')[0].version, 'parallel_read_safe': True, 'parallel_write_safe': True, } sphinxcontrib-seqdiag-3.0.0/tests/000077500000000000000000000000001415314541500171645ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/__init__.py000066400000000000000000000000001415314541500212630ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/docs/000077500000000000000000000000001415314541500201145ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/docs/basic/000077500000000000000000000000001415314541500211755ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/docs/basic/conf.py000066400000000000000000000000471415314541500224750ustar00rootroot00000000000000extensions = ['sphinxcontrib.seqdiag'] sphinxcontrib-seqdiag-3.0.0/tests/docs/basic/index.rst000066400000000000000000000001511415314541500230330ustar00rootroot00000000000000Welcome to test's documentation! ================================ .. seqdiag:: { A -> B; } sphinxcontrib-seqdiag-3.0.0/tests/docs/subdir/000077500000000000000000000000001415314541500214045ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/docs/subdir/conf.py000066400000000000000000000000471415314541500227040ustar00rootroot00000000000000extensions = ['sphinxcontrib.seqdiag'] sphinxcontrib-seqdiag-3.0.0/tests/docs/subdir/index.rst000066400000000000000000000001511415314541500232420ustar00rootroot00000000000000Welcome to test's documentation! ================================ .. seqdiag:: { A -> B; } sphinxcontrib-seqdiag-3.0.0/tests/docs/subdir/subdir/000077500000000000000000000000001415314541500226745ustar00rootroot00000000000000sphinxcontrib-seqdiag-3.0.0/tests/docs/subdir/subdir/index.rst000066400000000000000000000001511415314541500245320ustar00rootroot00000000000000Welcome to test's documentation! ================================ .. seqdiag:: { A -> B; } sphinxcontrib-seqdiag-3.0.0/tests/test_basic.py000066400000000000000000000013321415314541500216550ustar00rootroot00000000000000# -*- 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-seqdiag-3.0.0/tests/test_errors.py000066400000000000000000000037101415314541500221120ustar00rootroot00000000000000# -*- coding: utf-8 -*- from mock import patch from sphinx_testing import with_app import sys import unittest class TestSphinxcontribSeqdiagErrors(unittest.TestCase): @with_app(srcdir='tests/docs/basic', write_docstring=True) def test_parse_error(self, app, status, warning): """ .. seqdiag:: { A -> B; """ app.builder.build_all() self.assertIn('got unexpected token:', warning.getvalue()) @with_app(srcdir='tests/docs/basic', confoverrides=dict(seqdiag_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(seqdiag_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("seqdiag.utils.rst.nodes.seqdiag.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.seqdiag.seqdiag.drawer.DiagramDraw.draw") def test_font_settings_error(self, app, status, warning, draw): draw.side_effect = UnicodeEncodeError("", "", 0, 0, "") app.builder.build_all() self.assertIn('UnicodeEncodeError caught (check your font settings)', warning.getvalue()) sphinxcontrib-seqdiag-3.0.0/tests/test_html.py000066400000000000000000000347551415314541500215570ustar00rootroot00000000000000# -*- 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={ 'seqdiag_html_image_format': 'SVG', }) class TestSphinxcontribSeqdiagHTML(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'
')) @with_app(srcdir='tests/docs/subdir', buildername='html', write_docstring=True) def test_build_png_image_in_subdir(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'subdir' / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'
')) @with_png_app def test_width_option_on_png(self, app, status, warning): """ .. seqdiag:: :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_height_option_on_png(self, app, status, warning): """ .. seqdiag:: :height: 97 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_width_option_and_height_option_on_png(self, app, status, warning): """ .. seqdiag:: :width: 100 :height: 200 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_scale_option_on_png(self, app, status, warning): """ .. seqdiag:: :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_width_option_and_scale_option_on_png(self, app, status, warning): """ .. seqdiag:: :width: 28 :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_align_option_on_png(self, app, status, warning): """ .. seqdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'
') @with_png_app def test_align_option_and_width_option_on_png(self, app, status, warning): """ .. seqdiag:: :align: center :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_name_option_on_png(self, app, status, warning): """ .. seqdiag:: :name: target A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'
')) @with_png_app def test_name_option_and_width_option_on_png(self, app, status, warning): """ .. seqdiag:: :name: target :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_href_and_scale_option_on_png(self, app, status, warning): """ .. seqdiag:: :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, (r'
' r'' r'' r'' r'
')) @with_png_app def test_reftarget_in_href_on_png1(self, app, status, warning): """ .. _target: heading2 --------- .. seqdiag:: A -> B; A [href = ':ref:`target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_reftarget_in_href_on_png2(self, app, status, warning): """ .. _hello world: heading2 --------- .. seqdiag:: A -> B; A [href = ':ref:`hello world`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'' r'
')) @with_png_app def test_missing_reftarget_in_href_on_png(self, app, status, warning): """ .. seqdiag:: A -> B; A [href = ':ref:`unknown_target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'
')) self.assertIn('undefined label: unknown_target', warning.getvalue()) @with_svg_app def test_build_svg_image(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'
') @with_svg_app def test_width_option_on_svg(self, app, status, warning): """ .. seqdiag:: :width: 224 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_height_option_on_svg(self, app, status, warning): """ .. seqdiag:: :height: 97 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_width_option_and_height_option_on_svg(self, app, status, warning): """ .. seqdiag:: :width: 100 :height: 200 A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_scale_option_on_svg(self, app, status, warning): """ .. seqdiag:: :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_width_option_and_scale_option_on_svg(self, app, status, warning): """ .. seqdiag:: :width: 28 :scale: 25% A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_align_option_on_svg(self, app, status, warning): """ .. seqdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'
') @with_svg_app def test_name_option_on_svg(self, app, status, warning): """ .. seqdiag:: :name: target A -> B; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'
' r'')) @with_svg_app def test_reftarget_in_href_on_svg1(self, app, status, warning): """ .. _target: heading2 --------- .. seqdiag:: A -> B; A [href = ':ref:`target`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\n\s*\n\s*') @with_svg_app def test_reftarget_in_href_on_svg2(self, app, status, warning): """ .. _hello world: heading2 --------- .. seqdiag:: A -> B; A [href = ':ref:`hello world`']; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\n\s*\n\s*') @with_svg_app def test_missing_reftarget_in_href_on_svg(self, app, status, warning): """ .. seqdiag:: 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, r'\n\s*\n\s*') else: self.assertNotRegex(source, r'\n\s*\n\s*') self.assertIn('undefined label: unknown_target', warning.getvalue()) @with_svg_app def test_autoclass_should_not_effect_to_other_diagram(self, app, status, warning): """ This testcase checks that autoclass plugin is unloaded correctly (and it does not effect to other diagram). .. seqdiag:: plugin autoclass; class foo [color = red]; A_foo; .. seqdiag:: class foo [color = red]; A_foo; """ app.builder.build_all() source = (app.outdir / 'index.html').read_text(encoding='utf-8') self.assertRegexpMatches(source, r']+>A_foo') # 2nd diagram has a node labeled 'A_foo'. �������������������sphinxcontrib-seqdiag-3.0.0/tests/test_latex.py�����������������������������������������������������0000664�0000000�0000000�00000015321�14153145415�0021714�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# -*- coding: utf-8 -*- import os import re from sphinx_testing import with_app import unittest CR = '\r?\n' seqdiag_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', '', 'test', 'manual')], }) with_pdf_app = with_app(srcdir='tests/docs/basic', buildername='latex', write_docstring=True, confoverrides={ 'seqdiag_latex_image_format': 'PDF', 'latex_documents': [('index', 'test.tex', '', 'test', 'manual')], 'seqdiag_fontpath': seqdiag_fontpath, }) with_oldpdf_app = with_app(srcdir='tests/docs/basic', buildername='latex', write_docstring=True, confoverrides={ 'seqdiag_tex_image_format': 'PDF', 'latex_documents': [('index', 'test.tex', '', 'test', 'manual')], 'seqdiag_fontpath': seqdiag_fontpath, }) class TestSphinxcontribSeqdiagLatex(unittest.TestCase): @with_png_app def test_build_png_image(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{seqdiag-.*?}.png}') @unittest.skipUnless(os.path.exists(seqdiag_fontpath), "TrueType font not found") @with_pdf_app def test_build_pdf_image1(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics{seqdiag-.*?.pdf}') @unittest.skipUnless(os.path.exists(seqdiag_fontpath), "TrueType font not found") @with_oldpdf_app def test_build_pdf_image2(self, app, status, warning): """ .. seqdiag:: A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{seqdiag-.*?}.pdf}') @with_png_app def test_width_option(self, app, status, warning): """ .. seqdiag:: :width: 3cm A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[width=3cm\]{{seqdiag-.*?}.png}') @with_png_app def test_height_option(self, app, status, warning): """ .. seqdiag:: :height: 4cm A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[height=4cm\]{{seqdiag-.*?}.png}') @with_png_app def test_scale_option(self, app, status, warning): """ .. seqdiag:: :scale: 50% A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics\[scale=0.5\]{{seqdiag-.*?}.png}') @with_png_app def test_align_option_left(self, app, status, warning): """ .. seqdiag:: :align: left A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'{\\sphinxincludegraphics{{seqdiag-.*?}.png}' r'\\hspace\*{\\fill}}')) @with_png_app def test_align_option_center(self, app, status, warning): """ .. seqdiag:: :align: center A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'{\\hspace\*{\\fill}' r'\\sphinxincludegraphics{{seqdiag-.*?}.png}' r'\\hspace\*{\\fill}}')) @with_png_app def test_align_option_right(self, app, status, warning): """ .. seqdiag:: :align: right A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, (r'{\\hspace\*{\\fill}' r'\\sphinxincludegraphics{{seqdiag-.*?}.png}}')) @with_png_app def test_caption_option(self, app, status, warning): """ .. seqdiag:: :caption: hello world A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') figure = re.compile((r'\\begin{figure}\[htbp\]' + CR + r'\\centering' + CR + r'\\capstart' + CR + CR + r'\\noindent\\sphinxincludegraphics{{seqdiag-.*?}.png}' + CR + r'\\caption{hello world}\\label{\\detokenize{index:id1}}\\end{figure}'), re.DOTALL) self.assertRegexpMatches(source, figure) @with_png_app def test_caption_option_and_align_option(self, app, status, warning): """ .. seqdiag:: :align: left :caption: hello world A -> B; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') figure = re.compile((r'\\begin{wrapfigure}{l}{0pt}' + CR + r'\\centering' + CR + r'\\noindent\\sphinxincludegraphics{{seqdiag-.*?}.png}' + CR + r'\\caption{hello world}\\label{\\detokenize{index:id1}}\\end{wrapfigure}'), re.DOTALL) self.assertRegexpMatches(source, figure) @with_png_app def test_href(self, app, status, warning): """ .. seqdiag:: A -> B; A [href=":ref:`target`"]; """ app.builder.build_all() source = (app.outdir / 'test.tex').read_text(encoding='utf-8') self.assertRegexpMatches(source, r'\\sphinxincludegraphics{{seqdiag-.*?}.png}') ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������sphinxcontrib-seqdiag-3.0.0/tox.ini�����������������������������������������������������������������0000664�0000000�0000000�00000001444�14153145415�0017340�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������## configuration for tox ## tox automates running certain tasks within virtualenvs. The following ## tox configuration outlines a basic setup for running unit tests and ## building sphinx docs in separate virtual environments. Give it a try! [tox] envlist=py{37,38,39},blockdiag_dev [testenv] usedevelop = True deps= nose mock flake8 reportlab sphinx-testing >= 0.5.2 # for funcparserlib-1.0.0a0 pip_pre=true passenv= TRAVIS* commands= nosetests flake8 setup.py sphinxcontrib/ tests/ [testenv:blockdiag_dev] deps= {[testenv]deps} git+https://github.com/blockdiag/blockdiag [testenv:coverage] deps= {[testenv]deps} coverage coveralls commands= nosetests --with-coverage --cover-package=sphinxcontrib coveralls ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������