Пример #1
0
 def test_call_without_braces(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #2
0
    def test_cleanup(self):
        directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
        text = (".. seqdiag::\n" "\n" "   plugin autoclass\n" "   A -> B")
        publish_doctree(text)

        from blockdiag import plugins
        self.assertEqual([], plugins.loaded_plugins)
Пример #3
0
 def test_setup_inline_svg_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=False)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(1, len(os.listdir(self.tmpdir)))
Пример #4
0
 def test_setup_fontpath2(self):
     with self.assertRaises(RuntimeError):
         directives.setup(format='SVG',
                          fontpath='dummy.ttf',
                          outputdir=self.tmpdir)
         text = (".. seqdiag::\n" "\n" "   A -> B")
         publish_doctree(text)
Пример #5
0
 def test_setup_noviewbox_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     svg = open(doctree[0]['uri']).read()
     self.assertRegex(svg, r'<svg viewBox="0 0 \d+ \d+" ')
Пример #6
0
 def test_setup_fontpath2(self):
     with self.assertRaises(RuntimeError):
         directives.setup(format='SVG', fontpath='dummy.ttf',
                          outputdir=self.tmpdir)
         text = (".. seqdiag::\n"
                 "\n"
                 "   A -> B")
         publish_doctree(text)
Пример #7
0
 def test_setup_inline_svg_is_true_with_multibytes(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = u(".. seqdiag::\n"
              "\n"
              "   あ -> い")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
Пример #8
0
 def test_setup_nodoctype_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=True)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[-1]))
     svg = open(doctree[0]['uri']).read()
     self.assertEqual("<svg viewBox=\"0 0 ", svg[:18])
Пример #9
0
 def test_setup_inline_svg_is_true_but_format_isnt_svg(self):
     directives.setup(format='PNG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Пример #10
0
 def test_setup_inline_svg_is_true_but_format_isnt_svg(self):
     directives.setup(format='PNG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Пример #11
0
 def test_class_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :class: bar%\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(['bar'], doctree[0]['classes'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #12
0
 def test_setup_inline_svg_is_true_with_multibytes(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = u(".. seqdiag::\n"
              "\n"
              "   あ -> い")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
Пример #13
0
 def test_height_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :height: 100\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('100', doctree[0]['height'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #14
0
 def test_scale_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :scale: 50%\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(50, doctree[0]['scale'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #15
0
 def test_align_option3(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :align: right\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('right', doctree[0]['align'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #16
0
    def test_desctable_option_with_rest_markups(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = \"foo *bar* **baz**\"]"
                "   B [description = \"**foo** *bar* baz\"]")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        # tgroup
        self.assertEqual(4, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.thead, type(doctree[1][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][3]))

        # colspec
        self.assertEqual(50, doctree[1][0][0]['colwidth'])
        self.assertEqual(50, doctree[1][0][1]['colwidth'])

        # thead
        thead = doctree[1][0][2]
        self.assertEqual(2, len(thead[0]))
        self.assertEqual('Name', thead[0][0][0][0])
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[1][0][3]
        self.assertEqual(2, len(tbody))
        self.assertEqual('A', tbody[0][0][0][0])
        self.assertEqual(4, len(tbody[0][1][0]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][0]))
        self.assertEqual('foo ', str(tbody[0][1][0][0]))
        self.assertEqual(nodes.emphasis, type(tbody[0][1][0][1]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][1][0]))
        self.assertEqual('bar', tbody[0][1][0][1][0])
        self.assertEqual(nodes.Text, type(tbody[0][1][0][2]))
        self.assertEqual(' ', str(tbody[0][1][0][2]))
        self.assertEqual(nodes.strong, type(tbody[0][1][0][3]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][3][0]))
        self.assertEqual('baz', str(tbody[0][1][0][3][0]))

        self.assertEqual('B', tbody[1][0][0][0])
        self.assertEqual(4, len(tbody[1][1][0]))
        self.assertEqual(nodes.strong, type(tbody[1][1][0][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][0][0]))
        self.assertEqual('foo', str(tbody[1][1][0][0][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][1]))
        self.assertEqual(' ', str(tbody[1][1][0][1]))
        self.assertEqual(nodes.emphasis, type(tbody[1][1][0][2]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][2][0]))
        self.assertEqual('bar', str(tbody[1][1][0][2][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][3]))
        self.assertEqual(' baz', str(tbody[1][1][0][3]))
Пример #17
0
 def test_setup_inline_svg_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=False)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(1, len(os.listdir(self.tmpdir)))
Пример #18
0
 def test_maxwidth_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :maxwidth: 100\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(2, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
     self.assertEqual('100', doctree[0]['width'])
     self.assertEqual(nodes.system_message, type(doctree[1]))
Пример #19
0
 def test_call_without_braces(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #20
0
 def test_desctable_option_without_description(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :desctable:\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Пример #21
0
 def test_desctable_option_without_description(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :desctable:\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Пример #22
0
    def test_desctable_option_with_rest_markups(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = \"foo *bar* **baz**\"]"
                "   B [description = \"**foo** *bar* baz\"]")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        # tgroup
        self.assertEqual(4, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.thead, type(doctree[1][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][3]))

        # colspec
        self.assertEqual(50, doctree[1][0][0]['colwidth'])
        self.assertEqual(50, doctree[1][0][1]['colwidth'])

        # thead
        thead = doctree[1][0][2]
        self.assertEqual(2, len(thead[0]))
        self.assertEqual('Name', thead[0][0][0][0])
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[1][0][3]
        self.assertEqual(2, len(tbody))
        self.assertEqual('A', tbody[0][0][0][0])
        self.assertEqual(4, len(tbody[0][1][0]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][0]))
        self.assertEqual('foo ', str(tbody[0][1][0][0]))
        self.assertEqual(nodes.emphasis, type(tbody[0][1][0][1]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][1][0]))
        self.assertEqual('bar', tbody[0][1][0][1][0])
        self.assertEqual(nodes.Text, type(tbody[0][1][0][2]))
        self.assertEqual(' ', str(tbody[0][1][0][2]))
        self.assertEqual(nodes.strong, type(tbody[0][1][0][3]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][3][0]))
        self.assertEqual('baz', str(tbody[0][1][0][3][0]))

        self.assertEqual('B', tbody[1][0][0][0])
        self.assertEqual(4, len(tbody[1][1][0]))
        self.assertEqual(nodes.strong, type(tbody[1][1][0][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][0][0]))
        self.assertEqual('foo', str(tbody[1][1][0][0][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][1]))
        self.assertEqual(' ', str(tbody[1][1][0][1]))
        self.assertEqual(nodes.emphasis, type(tbody[1][1][0][2]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][2][0]))
        self.assertEqual('bar', str(tbody[1][1][0][2][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][3]))
        self.assertEqual(' baz', str(tbody[1][1][0][3]))
Пример #23
0
    def test_align_option4(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n" "   :align: unknown\n" "\n" "   A -> B")
        doctree = publish_doctree(text)
        self.assertEqual(1, len(doctree))
        self.assertEqual(nodes.system_message, type(doctree[0]))

        # clear stderr outputs (ignore ERROR)
        from io import StringIO
        sys.stderr = StringIO()
Пример #24
0
 def test_setup_nodoctype_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=False)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     svg = open(doctree[0]['uri']).read()
     self.assertEqual(
         "<?xml version='1.0' encoding='UTF-8'?>\n"
         "<!DOCTYPE ", svg[:49])
Пример #25
0
 def test_setup_nodoctype_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=True)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[-1]))
     svg = open(doctree[0]['uri']).read()
     self.assertEqual("<svg viewBox=\"0 0 ", svg[:18])
Пример #26
0
 def test_setup_noviewbox_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     svg = open(doctree[0]['uri']).read()
     self.assertRegexpMatches(svg, '<svg viewBox="0 0 \d+ \d+" ')
Пример #27
0
    def test_cleanup(self):
        directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
        text = (".. seqdiag::\n"
                "\n"
                "   plugin autoclass\n"
                "   A -> B")
        publish_doctree(text)

        from blockdiag import plugins
        self.assertEqual([], plugins.loaded_plugins)
Пример #28
0
 def test_setup_noviewbox_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=True)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     svg = open(doctree[0]['uri']).read()
     self.assertRegexpMatches(svg, '<svg height="\d+" width="\d+" ')
Пример #29
0
 def test_scale_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :scale: 50%\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(50, doctree[0]['scale'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #30
0
 def test_align_option3(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :align: right\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('right', doctree[0]['align'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #31
0
 def test_class_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :class: bar%\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(['bar'], doctree[0]['classes'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #32
0
 def test_figwidth_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :caption: hello world\n"
             "   :figwidth: image\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual('448px', doctree[0]['width'])
Пример #33
0
 def test_figwidth_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :caption: hello world\n"
             "   :figwidth: image\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual('448px', doctree[0]['width'])
Пример #34
0
 def test_figclass_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :caption: hello world\n"
             "   :figclass: baz\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(['baz'], doctree[0]['classes'])
Пример #35
0
 def test_figclass_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :caption: hello world\n"
             "   :figclass: baz\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(['baz'], doctree[0]['classes'])
Пример #36
0
 def test_setup_nodoctype_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=False)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     svg = open(doctree[0]['uri']).read()
     self.assertEqual("<?xml version='1.0' encoding='UTF-8'?>\n"
                      "<!DOCTYPE ", svg[:49])
Пример #37
0
 def test_height_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :height: 100\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('100', doctree[0]['height'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Пример #38
0
 def test_caption_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n" "   :caption: hello world\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(2, len(doctree[0]))
     self.assertEqual(nodes.image, type(doctree[0][0]))
     self.assertEqual(nodes.caption, type(doctree[0][1]))
     self.assertEqual(1, len(doctree[0][1]))
     self.assertEqual(nodes.Text, type(doctree[0][1][0]))
     self.assertEqual('hello world', doctree[0][1][0])
Пример #39
0
 def test_maxwidth_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :maxwidth: 100\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(2, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
     self.assertEqual('100', doctree[0]['width'])
     self.assertEqual(nodes.system_message, type(doctree[1]))
Пример #40
0
 def test_setup_inline_svg_is_true_and_height_option2(self):
     directives.setup(format='SVG',
                      outputdir=self.tmpdir,
                      nodoctype=True,
                      noviewbox=True,
                      inline_svg=True)
     text = (".. seqdiag::\n" "   :height: 10000\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
     self.assertEqual(nodes.Text, type(doctree[0][0]))
     self.assertRegex(doctree[0][0], r'<svg height="10000" width="\d+" ')
Пример #41
0
 def test_setup_inline_svg_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. seqdiag::\n" "\n" "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
     self.assertEqual('html', doctree[0]['format'])
     self.assertEqual(nodes.Text, type(doctree[0][0]))
     self.assertEqual(
         "<?xml version='1.0' encoding='UTF-8'?>\n"
         "<!DOCTYPE ", doctree[0][0][:49])
     self.assertEqual(0, len(os.listdir(self.tmpdir)))
Пример #42
0
 def test_setup_inline_svg_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. seqdiag::\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
     self.assertEqual('html', doctree[0]['format'])
     self.assertEqual(nodes.Text, type(doctree[0][0]))
     self.assertEqual("<?xml version='1.0' encoding='UTF-8'?>\n"
                      "<!DOCTYPE ", doctree[0][0][:49])
     self.assertEqual(0, len(os.listdir(self.tmpdir)))
Пример #43
0
 def test_setup_inline_svg_is_true_and_height_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir,
                      nodoctype=True, noviewbox=True, inline_svg=True)
     text = (".. seqdiag::\n"
             "   :height: 10000\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
     self.assertEqual(nodes.Text, type(doctree[0][0]))
     self.assertRegexpMatches(doctree[0][0],
                              '<svg height="10000" width="\d+" ')
Пример #44
0
    def test_setup(self):
        directives.setup()
        options = directives.directive_options

        self.assertIn('seqdiag', docutils._directives)
        self.assertEqual(directives.SeqdiagDirective,
                         docutils._directives['seqdiag'])
        self.assertEqual('PNG', options['format'])
        self.assertEqual(False, options['antialias'])
        self.assertEqual(None, options['fontpath'])
        self.assertEqual(False, options['nodoctype'])
        self.assertEqual(False, options['noviewbox'])
        self.assertEqual(False, options['inline_svg'])
Пример #45
0
    def test_setup(self):
        directives.setup()
        options = directives.directive_options

        self.assertIn('seqdiag', docutils._directives)
        self.assertEqual(directives.SeqdiagDirective,
                         docutils._directives['seqdiag'])
        self.assertEqual('PNG', options['format'])
        self.assertEqual(False, options['antialias'])
        self.assertEqual(None, options['fontpath'])
        self.assertEqual(False, options['nodoctype'])
        self.assertEqual(False, options['noviewbox'])
        self.assertEqual(False, options['inline_svg'])
Пример #46
0
    def test_align_option4(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :align: unknown\n"
                "\n"
                "   A -> B")
        doctree = publish_doctree(text)
        self.assertEqual(1, len(doctree))
        self.assertEqual(nodes.system_message, type(doctree[0]))

        # clear stderr outputs (ignore ERROR)
        from io import StringIO
        sys.stderr = StringIO()
Пример #47
0
    def test_setup_with_args(self):
        directives.setup(format='SVG', antialias=True, fontpath='/dev/null',
                         nodoctype=True, noviewbox=True, inline_svg=True)
        options = directives.directive_options

        self.assertIn('seqdiag', docutils._directives)
        self.assertEqual(directives.SeqdiagDirective,
                         docutils._directives['seqdiag'])
        self.assertEqual('SVG', options['format'])
        self.assertEqual(True, options['antialias'])
        self.assertEqual('/dev/null', options['fontpath'])
        self.assertEqual(True, options['nodoctype'])
        self.assertEqual(True, options['noviewbox'])
        self.assertEqual(True, options['inline_svg'])
Пример #48
0
    def test_setup_with_args(self):
        directives.setup(format='SVG', antialias=True, fontpath='/dev/null',
                         nodoctype=True, noviewbox=True, inline_svg=True)
        options = directives.directive_options

        self.assertIn('seqdiag', docutils._directives)
        self.assertEqual(directives.SeqdiagDirective,
                         docutils._directives['seqdiag'])
        self.assertEqual('SVG', options['format'])
        self.assertEqual(True, options['antialias'])
        self.assertEqual('/dev/null', options['fontpath'])
        self.assertEqual(True, options['nodoctype'])
        self.assertEqual(True, options['noviewbox'])
        self.assertEqual(True, options['inline_svg'])
Пример #49
0
 def test_caption_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. seqdiag::\n"
             "   :caption: hello world\n"
             "\n"
             "   A -> B")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(2, len(doctree[0]))
     self.assertEqual(nodes.image, type(doctree[0][0]))
     self.assertEqual(nodes.caption, type(doctree[0][1]))
     self.assertEqual(1, len(doctree[0][1]))
     self.assertEqual(nodes.Text, type(doctree[0][1][0]))
     self.assertEqual('hello world', doctree[0][1][0])
Пример #50
0
    def test_desctable_option_for_nodes_and_edges(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A -->> B [description = \"foo\"]"
                "   C => D [description = \"bar\"]"
                "   C [label = \"label_C\", description = foo]"
                "   D [label = \"label_D\"]")
        doctree = publish_doctree(text)
        self.assertEqual(3, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))
        self.assertEqual(nodes.table, type(doctree[2]))

        # tgroup
        self.assertEqual(4, len(doctree[2][0]))
        self.assertEqual(nodes.colspec, type(doctree[2][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[2][0][1]))
        self.assertEqual(nodes.thead, type(doctree[2][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[2][0][3]))

        # colspec
        self.assertEqual(25, doctree[2][0][0]['colwidth'])
        self.assertEqual(50, doctree[2][0][1]['colwidth'])

        # thead
        thead = doctree[2][0][2]
        self.assertEqual(2, len(thead[0]))
        self.assertEqual('Name', thead[0][0][0][0])
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[2][0][3]
        self.assertEqual(3, len(tbody))
        self.assertEqual('A -->> B', tbody[0][0][0][0])
        self.assertEqual(1, len(tbody[0][1][0]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][0]))
        self.assertEqual('foo', str(tbody[0][1][0][0]))
        self.assertEqual('label_C -> label_D', tbody[1][0][0][0])
        self.assertEqual(1, len(tbody[1][1][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][0]))
        self.assertEqual('bar', str(tbody[1][1][0][0]))
        self.assertEqual('label_C <-- label_D', tbody[2][0][0][0])
        self.assertEqual(1, len(tbody[2][1][0]))
        self.assertEqual(nodes.Text, type(tbody[2][1][0][0]))
        self.assertEqual('bar', str(tbody[2][1][0][0]))
Пример #51
0
    def test_desctable_option_for_nodes_and_edges(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A -->> B [description = \"foo\"]"
                "   C => D [description = \"bar\"]"
                "   C [label = \"label_C\", description = foo]"
                "   D [label = \"label_D\"]")
        doctree = publish_doctree(text)
        self.assertEqual(3, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))
        self.assertEqual(nodes.table, type(doctree[2]))

        # tgroup
        self.assertEqual(4, len(doctree[2][0]))
        self.assertEqual(nodes.colspec, type(doctree[2][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[2][0][1]))
        self.assertEqual(nodes.thead, type(doctree[2][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[2][0][3]))

        # colspec
        self.assertEqual(25, doctree[2][0][0]['colwidth'])
        self.assertEqual(50, doctree[2][0][1]['colwidth'])

        # thead
        thead = doctree[2][0][2]
        self.assertEqual(2, len(thead[0]))
        self.assertEqual('Name', thead[0][0][0][0])
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[2][0][3]
        self.assertEqual(3, len(tbody))
        self.assertEqual('A -->> B', tbody[0][0][0][0])
        self.assertEqual(1, len(tbody[0][1][0]))
        self.assertEqual(nodes.Text, type(tbody[0][1][0][0]))
        self.assertEqual('foo', str(tbody[0][1][0][0]))
        self.assertEqual('label_C -> label_D', tbody[1][0][0][0])
        self.assertEqual(1, len(tbody[1][1][0]))
        self.assertEqual(nodes.Text, type(tbody[1][1][0][0]))
        self.assertEqual('bar', str(tbody[1][1][0][0]))
        self.assertEqual('label_C <-- label_D', tbody[2][0][0][0])
        self.assertEqual(1, len(tbody[2][1][0]))
        self.assertEqual(nodes.Text, type(tbody[2][1][0][0]))
        self.assertEqual('bar', str(tbody[2][1][0][0]))
Пример #52
0
    def test_desctable_option_with_numbered_and_description(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = foo, numbered = 2]"
                "   B [description = bar, numbered = 1]")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        # tgroup
        self.assertEqual(5, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][2]))
        self.assertEqual(nodes.thead, type(doctree[1][0][3]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][4]))

        # colspec
        self.assertEqual(25, doctree[1][0][0]['colwidth'])
        self.assertEqual(50, doctree[1][0][1]['colwidth'])
        self.assertEqual(50, doctree[1][0][2]['colwidth'])

        # thead
        thead = doctree[1][0][3]
        self.assertEqual(3, len(thead[0]))
        self.assertEqual('No', thead[0][0][0][0])
        self.assertEqual('Name', thead[0][1][0][0])
        self.assertEqual('Description', thead[0][2][0][0])

        # tbody
        tbody = doctree[1][0][4]
        self.assertEqual(2, len(tbody))
        self.assertEqual('1', tbody[0][0][0][0])
        self.assertEqual('B', tbody[0][1][0][0])
        self.assertEqual(1, len(tbody[0][2]))
        self.assertEqual('bar', tbody[0][2][0][0])
        self.assertEqual('2', tbody[1][0][0][0])
        self.assertEqual('A', tbody[1][1][0][0])
        self.assertEqual('foo', tbody[1][2][0][0])
Пример #53
0
    def test_desctable_option_with_numbered_and_description(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = foo, numbered = 2]"
                "   B [description = bar, numbered = 1]")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        # tgroup
        self.assertEqual(5, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][2]))
        self.assertEqual(nodes.thead, type(doctree[1][0][3]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][4]))

        # colspec
        self.assertEqual(25, doctree[1][0][0]['colwidth'])
        self.assertEqual(50, doctree[1][0][1]['colwidth'])
        self.assertEqual(50, doctree[1][0][2]['colwidth'])

        # thead
        thead = doctree[1][0][3]
        self.assertEqual(3, len(thead[0]))
        self.assertEqual('No', thead[0][0][0][0])
        self.assertEqual('Name', thead[0][1][0][0])
        self.assertEqual('Description', thead[0][2][0][0])

        # tbody
        tbody = doctree[1][0][4]
        self.assertEqual(2, len(tbody))
        self.assertEqual('1', tbody[0][0][0][0])
        self.assertEqual('B', tbody[0][1][0][0])
        self.assertEqual(1, len(tbody[0][2]))
        self.assertEqual('bar', tbody[0][2][0][0])
        self.assertEqual('2', tbody[1][0][0][0])
        self.assertEqual('A', tbody[1][1][0][0])
        self.assertEqual('foo', tbody[1][2][0][0])
Пример #54
0
    def test_desctable_option_using_node_group(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = foo]"
                "   B [description = bar]"
                "   group { A }"
                "   A -> B")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        self.assertEqual(1, len(doctree[1]))
        self.assertEqual(nodes.tgroup, type(doctree[1][0]))

        # tgroup
        self.assertEqual(4, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.thead, type(doctree[1][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][3]))

        # colspec
        self.assertEqual(0, len(doctree[1][0][0]))
        self.assertEqual(50, doctree[1][0][0]['colwidth'])

        self.assertEqual(0, len(doctree[1][0][1]))
        self.assertEqual(50, doctree[1][0][1]['colwidth'])

        # thead
        thead = doctree[1][0][2]
        self.assertEqual(1, len(thead))
        self.assertEqual(2, len(thead[0]))

        self.assertEqual(1, len(thead[0][0]))
        self.assertEqual(1, len(thead[0][0][0]))
        self.assertEqual('Name', thead[0][0][0][0])

        self.assertEqual(1, len(thead[0][1]))
        self.assertEqual(1, len(thead[0][1][0]))
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[1][0][3]
        self.assertEqual(2, len(tbody))

        self.assertEqual(2, len(tbody[0]))
        self.assertEqual(1, len(tbody[0][0]))
        self.assertEqual(1, len(tbody[0][0][0]))
        self.assertEqual('A', tbody[0][0][0][0])
        self.assertEqual(1, len(tbody[0][1]))
        self.assertEqual('foo', tbody[0][1][0][0])

        self.assertEqual(2, len(tbody[1]))
        self.assertEqual(1, len(tbody[1][0]))
        self.assertEqual(1, len(tbody[1][0][0]))
        self.assertEqual('B', tbody[1][0][0][0])
        self.assertEqual(1, len(tbody[1][1]))
        self.assertEqual('bar', tbody[1][1][0][0])
Пример #55
0
    def test_desctable_option_using_node_group(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. seqdiag::\n"
                "   :desctable:\n"
                "\n"
                "   A [description = foo]"
                "   B [description = bar]"
                "   group { A }"
                "   A -> B")
        doctree = publish_doctree(text)
        self.assertEqual(2, len(doctree))
        self.assertEqual(nodes.image, type(doctree[0]))
        self.assertEqual(nodes.table, type(doctree[1]))

        self.assertEqual(1, len(doctree[1]))
        self.assertEqual(nodes.tgroup, type(doctree[1][0]))

        # tgroup
        self.assertEqual(4, len(doctree[1][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][0]))
        self.assertEqual(nodes.colspec, type(doctree[1][0][1]))
        self.assertEqual(nodes.thead, type(doctree[1][0][2]))
        self.assertEqual(nodes.tbody, type(doctree[1][0][3]))

        # colspec
        self.assertEqual(0, len(doctree[1][0][0]))
        self.assertEqual(50, doctree[1][0][0]['colwidth'])

        self.assertEqual(0, len(doctree[1][0][1]))
        self.assertEqual(50, doctree[1][0][1]['colwidth'])

        # thead
        thead = doctree[1][0][2]
        self.assertEqual(1, len(thead))
        self.assertEqual(2, len(thead[0]))

        self.assertEqual(1, len(thead[0][0]))
        self.assertEqual(1, len(thead[0][0][0]))
        self.assertEqual('Name', thead[0][0][0][0])

        self.assertEqual(1, len(thead[0][1]))
        self.assertEqual(1, len(thead[0][1][0]))
        self.assertEqual('Description', thead[0][1][0][0])

        # tbody
        tbody = doctree[1][0][3]
        self.assertEqual(2, len(tbody))

        self.assertEqual(2, len(tbody[0]))
        self.assertEqual(1, len(tbody[0][0]))
        self.assertEqual(1, len(tbody[0][0][0]))
        self.assertEqual('A', tbody[0][0][0][0])
        self.assertEqual(1, len(tbody[0][1]))
        self.assertEqual('foo', tbody[0][1][0][0])

        self.assertEqual(2, len(tbody[1]))
        self.assertEqual(1, len(tbody[1][0]))
        self.assertEqual(1, len(tbody[1][0][0]))
        self.assertEqual('B', tbody[1][0][0][0])
        self.assertEqual(1, len(tbody[1][1]))
        self.assertEqual('bar', tbody[1][1][0][0])