Exemplo n.º 1
0
 def test_flush_structure_hrefs(self):
     section = self.doc_structure.add_new_section('mysection')
     section.writeln('section contents')
     self.doc_structure.hrefs['foo'] = 'www.foo.com'
     section.hrefs['bar'] = 'www.bar.com'
     contents = self.doc_structure.flush_structure()
     self.assertIn(six.b('.. _foo: www.foo.com'), contents)
     self.assertIn(six.b('.. _bar: www.bar.com'), contents)
Exemplo n.º 2
0
    def test_new_line(self):
        style = ReSTStyle(ReSTDocument())
        style.new_line()
        self.assertEqual(style.doc.getvalue(), six.b('\n'))

        style.do_p = False
        style.new_line()
        self.assertEqual(style.doc.getvalue(), six.b('\n\n'))
Exemplo n.º 3
0
def calculate_md5(params, **kwargs):
    request_dict = params
    if request_dict['body'] and not 'Content-MD5' in params['headers']:
        md5 = hashlib.md5()
        md5.update(six.b(params['body']))
        value = base64.b64encode(md5.digest()).decode('utf-8')
        params['headers']['Content-MD5'] = value
Exemplo n.º 4
0
 def test_sphinx_py_method_with_params(self):
     style = ReSTStyle(ReSTDocument())
     style.start_sphinx_py_method('method', 'foo=None')
     style.end_sphinx_py_method()
     self.assertEqual(
         style.doc.getvalue(),
         six.b('\n\n.. py:method:: method(foo=None)\n\n  \n\n'))
Exemplo n.º 5
0
def decode_console_output(parsed, **kwargs):
    if 'Output' in parsed:
        try:
            value = base64.b64decode(six.b(parsed['Output'])).decode('utf-8')
            parsed['Output'] = value
        except (ValueError, TypeError, AttributeError):
            logger.debug('Error decoding base64', exc_info=True)
Exemplo n.º 6
0
 def test_escape_href_link(self):
     style = ReSTStyle(ReSTDocument())
     style.start_a(attrs=[('href', 'http://example.org')])
     style.doc.write('foo: the next bar')
     style.end_a()
     self.assertEqual(
         style.doc.getvalue(),
         six.b('`foo\\: the next bar <http://example.org>`__ '))
Exemplo n.º 7
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.º 8
0
 def test_toctree_man(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'man'
     style.toctree()
     style.tocitem('foo')
     style.tocitem('bar')
     self.assertEqual(style.doc.getvalue(),
                      six.b('\n\n\n* foo\n\n\n* bar\n\n'))
Exemplo n.º 9
0
 def test_run_instances_userdata(self):
     user_data = "This is a test"
     b64_user_data = base64.b64encode(six.b(user_data)).decode("utf-8")
     event = "before-parameter-build.ec2.RunInstances"
     params = dict(ImageId="img-12345678", MinCount=1, MaxCount=5, UserData=user_data)
     self.session.emit(event, params=params)
     result = {"ImageId": "img-12345678", "MinCount": 1, "MaxCount": 5, "UserData": b64_user_data}
     self.assertEqual(params, result)
Exemplo n.º 10
0
 def test_hidden_toctree_non_html(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'man'
     style.hidden_toctree()
     style.hidden_tocitem('foo')
     style.hidden_tocitem('bar')
     self.assertEqual(
         style.doc.getvalue(),
         six.b(''))
Exemplo n.º 11
0
 def test_write_py_doc_string(self):
     style = ReSTStyle(ReSTDocument())
     docstring = (
         'This describes a function\n'
         ':param foo: Describes foo\n'
         'returns: None'
     )
     style.write_py_doc_string(docstring)
     self.assertEqual(style.doc.getvalue(), six.b(docstring + '\n'))
Exemplo n.º 12
0
 def test_href_link(self):
     style = ReSTStyle(ReSTDocument())
     style.start_a(attrs=[('href', 'http://example.org')])
     style.doc.write('example')
     style.end_a()
     self.assertEqual(
         style.doc.getvalue(),
         six.b('`example <http://example.org>`__ ')
     )
Exemplo n.º 13
0
 def test_run_instances_userdata(self):
     user_data = 'This is a test'
     b64_user_data = base64.b64encode(six.b(user_data)).decode('utf-8')
     op = self.ec2.get_operation('RunInstances')
     params = dict(image_id='img-12345678',
                   min_count=1, max_count=5, user_data=user_data)
     result = {'ImageId': 'img-12345678',
               'MinCount': 1,
               'MaxCount': 5,
               'UserData': b64_user_data}
Exemplo n.º 14
0
 def test_hidden_toctree_html(self):
     style = ReSTStyle(ReSTDocument())
     style.doc.target = 'html'
     style.hidden_toctree()
     style.hidden_tocitem('foo')
     style.hidden_tocitem('bar')
     self.assertEqual(
         style.doc.getvalue(),
         six.b('\n.. toctree::\n  :maxdepth: 1'
               '\n  :hidden:\n\n  foo\n  bar\n'))
Exemplo n.º 15
0
def decode_console_output(parsed, **kwargs):
    if "Output" in parsed:
        try:
            # We're using 'replace' for errors because it is
            # possible that console output contains non string
            # chars we can't utf-8 decode.
            value = base64.b64decode(six.b(parsed["Output"])).decode("utf-8", "replace")
            parsed["Output"] = value
        except (ValueError, TypeError, AttributeError):
            logger.debug("Error decoding base64", exc_info=True)
Exemplo n.º 16
0
 def test_run_instances_userdata(self):
     user_data = 'This is a test'
     b64_user_data = base64.b64encode(six.b(user_data)).decode('utf-8')
     params = dict(ImageId='img-12345678',
                   MinCount=1, MaxCount=5, UserData=user_data)
     handlers.base64_encode_user_data(params=params)
     result = {'ImageId': 'img-12345678',
               'MinCount': 1,
               'MaxCount': 5,
               'UserData': b64_user_data}
     self.assertEqual(params, result)
Exemplo n.º 17
0
 def test_run_instances_userdata(self):
     user_data = 'This is a test'
     b64_user_data = base64.b64encode(six.b(user_data)).decode('utf-8')
     event = 'before-parameter-build.ec2.RunInstances'
     params = dict(ImageId='img-12345678',
                   MinCount=1, MaxCount=5, UserData=user_data)
     self.session.emit(event, params=params)
     result = {'ImageId': 'img-12345678',
               'MinCount': 1,
               'MaxCount': 5,
               'UserData': b64_user_data}
     self.assertEqual(params, result)
Exemplo n.º 18
0
    def test_flush_structure(self):
        section = self.doc_structure.add_new_section('mysection')
        subsection = section.add_new_section('mysubsection')
        self.doc_structure.writeln('1')
        section.writeln('2')
        subsection.writeln('3')
        second_section = self.doc_structure.add_new_section('mysection2')
        second_section.writeln('4')
        contents = self.doc_structure.flush_structure()

        # Ensure the contents were flushed out correctly
        self.assertEqual(contents, six.b('1\n2\n3\n4\n'))
Exemplo n.º 19
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.º 20
0
    def create_config_file(self, filename):
        contents = (
            '[default]\n'
            'aws_access_key_id = foo\n'
            'aws_secret_access_key = bar\n\n'
            '[profile "personal"]\n'
            'aws_access_key_id = fie\n'
            'aws_secret_access_key = baz\n'
            'aws_security_token = fiebaz\n'
        )

        directory = self.tempdir
        if isinstance(filename, six.binary_type):
            directory = six.b(directory)
        full_path = os.path.join(directory, filename)

        with open(full_path, 'w') as f:
            f.write(contents)
        return full_path
Exemplo n.º 21
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.º 22
0
 def test_bold(self):
     style = ReSTStyle(ReSTDocument())
     style.bold('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('**foobar** '))
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_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.º 25
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.º 26
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.º 27
0
def path(filename):
    directory = os.path.join(os.path.dirname(__file__), 'cfg')
    if isinstance(filename, six.binary_type):
        directory = six.b(directory)
    return os.path.join(directory, filename)
Exemplo n.º 28
0
def decode_console_output(parsed, **kwargs):
    try:
        value = base64.b64decode(six.b(parsed['Output'])).decode('utf-8')
        parsed['Output'] = value
    except (ValueError, TypeError, AttributeError):
        logger.debug('Error decoding base64', exc_info=True)
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_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.º 31
0
 def test_code(self):
     style = ReSTStyle(ReSTDocument())
     style.code('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('``foobar`` '))
Exemplo n.º 32
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.º 33
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.º 34
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.º 35
0
 def test_table_of_contents(self):
     style = ReSTStyle(ReSTDocument())
     style.table_of_contents()
     self.assertEqual(style.doc.getvalue(), six.b('.. contents:: '))
Exemplo n.º 36
0
 def test_bold(self):
     style = ReSTStyle(ReSTDocument())
     style.bold('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('**foobar** '))
Exemplo n.º 37
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.º 38
0
 def test_italics(self):
     style = ReSTStyle(ReSTDocument())
     style.italics('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('*foobar* '))
Exemplo n.º 39
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.º 40
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.º 41
0
 def test_codeblock(self):
     style = ReSTStyle(ReSTDocument())
     style.codeblock('foobar')
     self.assertEqual(style.doc.getvalue(),
                      six.b('::\n\n  foobar\n\n\n'))
 def test_writeln(self):
     doc = ReSTDocument()
     doc.writeln('foo')
     self.assertEqual(doc.getvalue(), six.b('foo\n'))
Exemplo n.º 43
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.º 44
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'))
 def test_remove_doc_string(self):
     doc = ReSTDocument()
     doc.writeln('foo')
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     doc.remove_last_doc_string()
     self.assertEqual(doc.getvalue(), six.b('foo\n'))
Exemplo n.º 46
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'))
 def test_include_doc_string(self):
     doc = ReSTDocument()
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     self.assertEqual(doc.getvalue(), six.b('\n\nthis is a ``test`` \n\n'))
Exemplo n.º 48
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.º 49
0
 def test_italics(self):
     style = ReSTStyle(ReSTDocument())
     style.italics('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('*foobar* '))
Exemplo n.º 50
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.º 51
0
 def test_code(self):
     style = ReSTStyle(ReSTDocument())
     style.code('foobar')
     self.assertEqual(style.doc.getvalue(), six.b('``foobar`` '))
Exemplo n.º 52
0
 def test_list(self):
     style = ReSTStyle(ReSTDocument())
     style.li('foo')
     self.assertEqual(style.doc.getvalue(), six.b('\n* foo\n\n'))
Exemplo n.º 53
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>`'))
 def test_clear_text(self):
     self.doc_structure.write('Foo')
     self.doc_structure.clear_text()
     self.assertEqual(self.doc_structure.flush_structure(), six.b(''))