Exemplo n.º 1
0
 def test_toctree_html(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'html'
     style.toctree()
     style.tocitem('foo')
     style.tocitem('bar')
     self.assertEqual(
         style.doc.getvalue(),
         six.b('\n.. toctree::\n  :maxdepth: 1'
               '\n  :titlesonly:\n\n  foo\n  bar\n'))
Exemplo n.º 2
0
 def create_help_command(self):
     help_command = mock.Mock()
     help_command.doc = ReSTDocument()
     help_command.event_class = 'custom'
     help_command.arg_table = {}
     operation_model = mock.Mock()
     operation_model.documentation = 'description'
     operation_model.service_model.operation_names = []
     help_command.obj = operation_model
     return help_command
Exemplo n.º 3
0
 def get_help_docs_for_argument(self, shape):
     arg_table = {'arg-name': mock.Mock(argument_model=shape)}
     help_command = mock.Mock()
     help_command.doc = ReSTDocument()
     help_command.event_class = 'custom'
     help_command.arg_table = arg_table
     operation_model = mock.Mock()
     operation_model.service_model.operation_names = []
     help_command.obj = operation_model
     operation_handler = OperationDocumentEventHandler(help_command)
     operation_handler.doc_option('arg-name', help_command)
     return help_command.doc.getvalue().decode('utf-8')
Exemplo n.º 4
0
 def __init__(self, session, obj, command_table, arg_table):
     self.session = session
     self.obj = obj
     if command_table is None:
         command_table = {}
     self.command_table = command_table
     if arg_table is None:
         arg_table = {}
     self.arg_table = arg_table
     self._subcommand_table = {}
     self._related_items = []
     self.renderer = get_renderer()
     self.doc = ReSTDocument(target='man')
Exemplo n.º 5
0
 def test_documents_enum_values(self):
     shape = {'type': 'string', 'enum': ['FOO', 'BAZ']}
     shape = StringShape('EnumArg', shape)
     arg_table = {'arg-name': mock.Mock(argument_model=shape)}
     help_command = mock.Mock()
     help_command.doc = ReSTDocument()
     help_command.event_class = 'custom'
     help_command.arg_table = arg_table
     operation_model = mock.Mock()
     operation_model.service_model.operation_names = []
     help_command.obj = operation_model
     operation_handler = OperationDocumentEventHandler(help_command)
     operation_handler.doc_option('arg-name', help_command)
     rendered = help_command.doc.getvalue().decode('utf-8')
     self.assertIn('Possible values', rendered)
     self.assertIn('FOO', rendered)
     self.assertIn('BAZ', rendered)
Exemplo n.º 6
0
 def test_documents_json_header_shape(self):
     shape = {
         'type': 'string',
         'jsonvalue': True,
         'location': 'header',
         'locationName': 'X-Amz-Header-Name'
     }
     shape = StringShape('JSONValueArg', shape)
     arg_table = {'arg-name': mock.Mock(argument_model=shape)}
     help_command = mock.Mock()
     help_command.doc = ReSTDocument()
     help_command.event_class = 'custom'
     help_command.arg_table = arg_table
     operation_model = mock.Mock()
     operation_model.service_model.operation_names = []
     help_command.obj = operation_model
     operation_handler = OperationDocumentEventHandler(help_command)
     operation_handler.doc_option('arg-name', help_command)
     rendered = help_command.doc.getvalue().decode('utf-8')
     self.assertIn('(JSON)', rendered)
Exemplo n.º 7
0
    def test_non_top_level_lists_are_indented(self):
        style = ReSTStyle(ReSTDocument())

        # Start the top level list
        style.start_ul()

        # Write one list element
        style.start_li()
        style.doc.handle_data('foo')
        style.end_li()

        self.assertEqual(style.doc.getvalue(), six.b("\n\n\n* foo\n"))

        # Start the nested list
        style.start_ul()

        # Write an element to the nested list
        style.start_li()
        style.doc.handle_data('bar')
        style.end_li()

        self.assertEqual(style.doc.getvalue(),
                         six.b("\n\n\n* foo\n\n\n  \n  * bar\n  "))
Exemplo n.º 8
0
 def test_table_of_contents_with_title_and_depth(self):
     style = ReSTStyle(ReSTDocument())
     style.table_of_contents(title='Foo', depth=2)
     self.assertEqual(style.doc.getvalue(),
                      six.b('.. contents:: Foo\n   :depth: 2\n'))
Exemplo n.º 9
0
 def test_sphinx_py_class(self):
     style = ReSTStyle(ReSTDocument())
     style.start_sphinx_py_class('FooClass')
     style.end_sphinx_py_class()
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n.. py:class:: FooClass\n\n  \n\n'))
Exemplo n.º 10
0
 def test_sphinx_reference_label_non_html_no_text(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'man'
     style.sphinx_reference_label('foo')
     self.assertEqual(style.doc.getvalue(), six.b('foo'))
Exemplo n.º 11
0
 def test_table_of_contents(self):
     style = ReSTStyle(ReSTDocument())
     style.table_of_contents()
     self.assertEqual(style.doc.getvalue(), six.b('.. contents:: '))
Exemplo n.º 12
0
 def test_handle_no_text_hrefs(self):
     style = ReSTStyle(ReSTDocument())
     style.start_a(attrs=[('href', 'http://example.org')])
     style.end_a()
     self.assertEqual(style.doc.getvalue(),
                      six.b('`<http://example.org>`_ '))
Exemplo n.º 13
0
 def test_sphinx_reference_label_html(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'html'
     style.sphinx_reference_label('foo', 'bar')
     self.assertEqual(style.doc.getvalue(), six.b(':ref:`bar <foo>`'))
Exemplo n.º 14
0
 def test_h3(self):
     style = ReSTStyle(ReSTDocument())
     style.h3('foobar fiebaz')
     self.assertEqual(
         style.doc.getvalue(),
         six.b('\n\n-------------\nfoobar fiebaz\n-------------\n\n'))
Exemplo n.º 15
0
 def test_danger(self):
     style = ReSTStyle(ReSTDocument())
     style.start_danger()
     style.end_danger()
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n.. danger::\n\n  \n\n'))
Exemplo n.º 16
0
 def test_bold(self):
     style = ReSTStyle(ReSTDocument())
     style.bold('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('**foobar** '))
Exemplo n.º 17
0
 def test_p(self):
     style = ReSTStyle(ReSTDocument())
     style.start_p()
     style.doc.write('foo')
     style.end_p()
     self.assertEqual(style.doc.getvalue(), six.b('\n\nfoo\n\n'))
Exemplo n.º 18
0
 def test_list(self):
     style = ReSTStyle(ReSTDocument())
     style.li('foo')
     self.assertEqual(style.doc.getvalue(), six.b('\n* foo\n\n'))
Exemplo n.º 19
0
 def test_internal_link_in_man_page(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'man'
     style.internal_link('MyLink', '/index')
     self.assertEqual(style.doc.getvalue(), six.b('MyLink'))
Exemplo n.º 20
0
 def test_internal_link(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'html'
     style.internal_link('MyLink', '/index')
     self.assertEqual(style.doc.getvalue(), six.b(':doc:`MyLink </index>`'))
Exemplo n.º 21
0
 def test_sphinx_py_method(self):
     style = ReSTStyle(ReSTDocument())
     style.start_sphinx_py_method('method')
     style.end_sphinx_py_method()
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n.. py:method:: method\n\n  \n\n'))
Exemplo n.º 22
0
 def test_add_links(self):
     doc = ReSTDocument()
     doc.hrefs['foo'] = 'https://example.com/'
     self.assertEqual(
         doc.getvalue(), six.b('\n\n.. _foo: https://example.com/\n'))
Exemplo n.º 23
0
 def test_sphinx_py_attr(self):
     style = ReSTStyle(ReSTDocument())
     style.start_sphinx_py_attr('Foo')
     style.end_sphinx_py_attr()
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n.. py:attribute:: Foo\n\n  \n\n'))
Exemplo n.º 24
0
 def test_important(self):
     style = ReSTStyle(ReSTDocument())
     style.start_important()
     style.end_important()
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n.. warning::\n\n  \n\n'))
Exemplo n.º 25
0
 def test_italics(self):
     style = ReSTStyle(ReSTDocument())
     style.italics('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('*foobar* '))
Exemplo n.º 26
0
 def test_external_link(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'html'
     style.external_link('MyLink', 'http://example.com/foo')
     self.assertEqual(style.doc.getvalue(),
                      six.b('`MyLink <http://example.com/foo>`_'))
Exemplo n.º 27
0
 def test_code(self):
     style = ReSTStyle(ReSTDocument())
     style.code('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('``foobar`` '))
Exemplo n.º 28
0
 def test_external_link_in_man_page(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'man'
     style.external_link('MyLink', 'http://example.com/foo')
     self.assertEqual(style.doc.getvalue(), six.b('MyLink'))
Exemplo n.º 29
0
 def test_ref(self):
     style = ReSTStyle(ReSTDocument())
     style.ref('foobar', 'http://foo.bar.com')
     self.assertEqual(style.doc.getvalue(),
                      six.b(':doc:`foobar <http://foo.bar.com>`'))
Exemplo n.º 30
0
 def test_codeblock(self):
     style = ReSTStyle(ReSTDocument())
     style.codeblock('foobar')
     self.assertEqual(style.doc.getvalue(),
                      six.b('::\n\n  foobar\n\n\n'))