Exemplo n.º 1
0
 def test_call_without_braces(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n" "\n" "   network {" "     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))
Exemplo n.º 2
0
 def test_setup_inline_svg_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=False)
     text = (".. nwdiag::\n" "\n" "   network {" "     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)))
Exemplo n.º 3
0
    def test_desctable_option_with_rest_markups(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     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]))
Exemplo n.º 4
0
    def test_desctable_option_with_rest_markups(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     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]))
Exemplo n.º 5
0
 def test_setup_noviewbox_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
     text = (".. nwdiag::\n" "\n" "   network {" "     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+" ')
Exemplo n.º 6
0
 def test_setup_nodoctype_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=False)
     text = (".. nwdiag::\n" "\n" "   network {" "     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])
Exemplo n.º 7
0
 def test_setup_inline_svg_is_true_but_nonsvg_format(self):
     directives.setup(format='PNG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Exemplo n.º 8
0
 def test_setup_fontpath2(self):
     with self.assertRaises(RuntimeError):
         directives.setup(format='SVG', fontpath='dummy.ttf',
                          outputdir=self.tmpdir)
         text = (".. nwdiag::\n"
                 "\n"
                 "   network {"
                 "     A"
                 "     B"
                 "   }")
         publish_doctree(text)
Exemplo n.º 9
0
 def test_setup_inline_svg_is_true_but_nonsvg_format(self):
     directives.setup(format='PNG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Exemplo n.º 10
0
 def test_setup_inline_svg_is_true_with_multibytes(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = u(".. nwdiag::\n"
              "\n"
              "   network {"
              "     あ"
              "     い"
              "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
Exemplo n.º 11
0
 def test_setup_fontpath2(self):
     with self.assertRaises(RuntimeError):
         directives.setup(format='SVG', fontpath='dummy.ttf',
                          outputdir=self.tmpdir)
         text = (".. nwdiag::\n"
                 "\n"
                 "   network {"
                 "     A"
                 "     B"
                 "   }")
         publish_doctree(text)
Exemplo n.º 12
0
 def test_setup_inline_svg_is_true_with_multibytes(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     あ"
             "     い"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.raw, type(doctree[0]))
Exemplo n.º 13
0
 def test_desctable_option_without_description(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :desctable:\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Exemplo n.º 14
0
 def test_setup_inline_svg_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. nwdiag::\n" "\n" "   network {" "     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)))
Exemplo n.º 15
0
 def test_setup_inline_svg_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=False)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     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)))
Exemplo n.º 16
0
 def test_call_without_braces(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     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))
Exemplo n.º 17
0
 def test_desctable_option_without_description(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :desctable:\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
Exemplo n.º 18
0
    def test_setup(self):
        directives.setup()
        options = directives.directive_options

        self.assertIn('nwdiag', docutils._directives)
        self.assertEqual(directives.NwdiagDirective,
                         docutils._directives['nwdiag'])
        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'])
Exemplo n.º 19
0
 def test_setup_noviewbox_is_false(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     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+" ')
Exemplo n.º 20
0
    def test_cleanup(self):
        directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
        text = (".. nwdiag::\n"
                "\n"
                "   plugin autoclass\n"
                "   network {"
                "     A"
                "     B"
                "   }")
        publish_doctree(text)

        from blockdiag import plugins
        self.assertEqual([], plugins.loaded_plugins)
Exemplo n.º 21
0
    def test_setup(self):
        directives.setup()
        options = directives.directive_options

        self.assertIn('nwdiag', docutils._directives)
        self.assertEqual(directives.NwdiagDirective,
                         docutils._directives['nwdiag'])
        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'])
Exemplo n.º 22
0
    def test_cleanup(self):
        directives.setup(format='SVG', outputdir=self.tmpdir, noviewbox=False)
        text = (".. nwdiag::\n"
                "\n"
                "   plugin autoclass\n"
                "   network {"
                "     A"
                "     B"
                "   }")
        publish_doctree(text)

        from blockdiag import plugins
        self.assertEqual([], plugins.loaded_plugins)
Exemplo n.º 23
0
 def test_figwidth_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "   :figwidth: image\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual('456px', doctree[0]['width'])
Exemplo n.º 24
0
 def test_height_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :height: 100\n"
             "\n"
             "   network {"
             "     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))
Exemplo n.º 25
0
 def test_class_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :class: bar%\n"
             "\n"
             "   network {"
             "     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))
Exemplo n.º 26
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('nwdiag', docutils._directives)
        self.assertEqual(directives.NwdiagDirective,
                         docutils._directives['nwdiag'])
        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'])
Exemplo n.º 27
0
 def test_figwidth_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "   :figwidth: image\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual('456px', doctree[0]['width'])
Exemplo n.º 28
0
 def test_align_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :align: center\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('center', doctree[0]['align'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Exemplo n.º 29
0
 def test_figclass_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "   :figclass: baz\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(['baz'], doctree[0]['classes'])
Exemplo n.º 30
0
 def test_class_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :class: bar%\n"
             "\n"
             "   network {"
             "     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))
Exemplo n.º 31
0
 def test_setup_nodoctype_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, nodoctype=True)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     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.assertNotEqual("<?xml version='1.0' encoding='UTF-8'?>\n"
                         "<!DOCTYPE ", svg[:49])
Exemplo n.º 32
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('nwdiag', docutils._directives)
        self.assertEqual(directives.NwdiagDirective,
                         docutils._directives['nwdiag'])
        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'])
Exemplo n.º 33
0
 def test_height_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :height: 100\n"
             "\n"
             "   network {"
             "     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))
Exemplo n.º 34
0
 def test_figclass_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "   :figclass: baz\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.figure, type(doctree[0]))
     self.assertEqual(['baz'], doctree[0]['classes'])
Exemplo n.º 35
0
 def test_align_option2(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :align: center\n"
             "\n"
             "   network {"
             "     A"
             "     B"
             "   }")
     doctree = publish_doctree(text)
     self.assertEqual(1, len(doctree))
     self.assertEqual(nodes.image, type(doctree[0]))
     self.assertEqual('center', doctree[0]['align'])
     self.assertEqual(0, doctree[0]['uri'].index(self.tmpdir))
Exemplo n.º 36
0
 def test_maxwidth_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :maxwidth: 100\n"
             "\n"
             "   network {"
             "     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]))
Exemplo n.º 37
0
 def test_maxwidth_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :maxwidth: 100\n"
             "\n"
             "   network {"
             "     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]))
Exemplo n.º 38
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 = (".. nwdiag::\n"
             "   :height: 10000\n"
             "\n"
             "   network {"
             "     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+" ')
Exemplo n.º 39
0
 def test_setup_inline_svg_is_true(self):
     directives.setup(format='SVG', outputdir=self.tmpdir, inline_svg=True)
     text = (".. nwdiag::\n"
             "\n"
             "   network {"
             "     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)))
Exemplo n.º 40
0
    def test_align_option4(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :align: unknown\n"
                "\n"
                "   network {"
                "     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()
Exemplo n.º 41
0
    def test_align_option4(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :align: unknown\n"
                "\n"
                "   network {"
                "     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()
Exemplo n.º 42
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 = (".. nwdiag::\n"
             "   :height: 10000\n"
             "\n"
             "   network {"
             "     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],
                              r'<svg height="10000" width="\d+" ')
Exemplo n.º 43
0
 def test_caption_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "\n"
             "   network {"
             "     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])
Exemplo n.º 44
0
 def test_caption_option(self):
     directives.setup(format='SVG', outputdir=self.tmpdir)
     text = (".. nwdiag::\n"
             "   :caption: hello world\n"
             "\n"
             "   network {"
             "     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])
Exemplo n.º 45
0
    def test_desctable_option_with_numbered_and_description(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     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])
Exemplo n.º 46
0
    def test_desctable_option_with_numbered_and_description(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     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])
Exemplo n.º 47
0
    def test_desctable_option_using_node_group(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     A [description = foo]"
                "     B [description = bar]"
                "   }"
                "   group {"
                "     A"
                "   }"
                "   network {"
                "     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])
Exemplo n.º 48
0
    def test_desctable_option_using_node_group(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. nwdiag::\n"
                "   :desctable:\n"
                "\n"
                "   network {"
                "     A [description = foo]"
                "     B [description = bar]"
                "   }"
                "   group {"
                "     A"
                "   }"
                "   network {"
                "     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])