Exemplo n.º 1
0
    def test_append_sub_item(self):
        spam = List(['spam'])
        ham = List(['ham'])
        eggs = List(['eggs'])

        spam.append_item(ham)
        ham.append_item(eggs)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:list>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:list>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>'
                    '</text:list-item>'
                    '</text:list>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(spam.serialize(), expected)
Exemplo n.º 2
0
    def test_insert_sub_item(self):
        spam = List(["spam"])
        ham = List(["ham"])
        eggs = List(["eggs"])

        spam.insert_item(ham, 1)
        ham.insert_item(eggs, 1)

        expected = ("<text:list>"
                    "<text:list-item>"
                    "<text:p>spam</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:list>"
                    "<text:list-item>"
                    "<text:p>ham</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:list>"
                    "<text:list-item>"
                    "<text:p>eggs</text:p>"
                    "</text:list-item>"
                    "</text:list>"
                    "</text:list-item>"
                    "</text:list>"
                    "</text:list-item>"
                    "</text:list>")
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(spam.serialize(), expected)
Exemplo n.º 3
0
    def test_get_formatted_text(self):
        # Create the items
        spam = ListItem('In this picture, there are 47 people;\n'
                        'none of them can be seen.')
        ham = ListItem('In this film, we hope to show you the\n'
                       'value of not being seen.\n')
        eggs = ListItem('Here is Mr. Bagthorpe of London, ' 'SE14.\n')
        foo = ListItem('He cannot be seen.')
        bar = ListItem('Now I am going to ask him to stand up.')
        baz = ListItem('Mr. Bagthorpe, will you stand up please?')
        # Create the lists
        how_not_to_be_seen1 = List()
        how_not_to_be_seen2 = List()
        how_not_to_be_seen3 = List()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {
            'document': None,
            'footnotes': [],
            'endnotes': [],
            'annotations': [],
            'rst_mode': False
        }
        expected = ('- In this picture, there are 47 people;\n'
                    '  none of them can be seen.\n'
                    '  \n'
                    '  - In this film, we hope to show you the\n'
                    '    value of not being seen.\n'
                    '  - Here is Mr. Bagthorpe of London, SE14.\n'
                    '  - He cannot be seen.\n'
                    '    \n'
                    '    - Now I am going to ask him to stand up.\n'
                    '    - Mr. Bagthorpe, will you stand up please?\n')
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
Exemplo n.º 4
0
    def test_get_formatted_text(self):
        # Create the items
        spam = ListItem("In this picture, there are 47 people;\n"
                        "none of them can be seen.")
        ham = ListItem("In this film, we hope to show you the\n"
                       "value of not being seen.\n")
        eggs = ListItem("Here is Mr. Bagthorpe of London, " "SE14.\n")
        foo = ListItem("He cannot be seen.")
        bar = ListItem("Now I am going to ask him to stand up.")
        baz = ListItem("Mr. Bagthorpe, will you stand up please?")
        # Create the lists
        how_not_to_be_seen1 = List()
        how_not_to_be_seen2 = List()
        how_not_to_be_seen3 = List()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {
            "document": None,
            "footnotes": [],
            "endnotes": [],
            "annotations": [],
            "rst_mode": False,
        }
        expected = ("- In this picture, there are 47 people;\n"
                    "  none of them can be seen.\n"
                    "  \n"
                    "  - In this film, we hope to show you the\n"
                    "    value of not being seen.\n"
                    "  - Here is Mr. Bagthorpe of London, SE14.\n"
                    "  - He cannot be seen.\n"
                    "    \n"
                    "    - Now I am going to ask him to stand up.\n"
                    "    - Mr. Bagthorpe, will you stand up please?\n")
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
Exemplo n.º 5
0
    def test_get_item_by_content(self):
        # Create the items
        spam = ListItem('spam')
        ham = ListItem('ham')
        eggs = ListItem('eggs')
        # Create the corresponding lists
        spam_list = List()
        ham_list = List()
        eggs_list = List()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append(ham_list)
        ham.append(eggs_list)

        item = spam_list.get_item(content=r'spam')
        expected = ('<text:list-item>\n'
                    '  <text:p>spam</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>ham</text:p>\n'
                    '      <text:list>\n'
                    '        <text:list-item>\n'
                    '          <text:p>eggs</text:p>\n'
                    '        </text:list-item>\n'
                    '      </text:list>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'ham')
        expected = ('<text:list-item>\n'
                    '  <text:p>ham</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>eggs</text:p>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'eggs')
        expected = ('<text:list-item>\n'
                    '  <text:p>eggs</text:p>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
Exemplo n.º 6
0
 def test_create_list_with_non_iterable(self):
     a_list = List(ZOE)
     expected = (('<text:list>'
                  '<text:list-item>'
                  '<text:p>%s</text:p>'
                  '</text:list-item>'
                  '</text:list>') % ZOE)
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 7
0
 def test_create_list(self):
     a_list = List([ZOE])
     expected = (('<text:list>'
                  '<text:list-item>'
                  '<text:p>%s</text:p>'
                  '</text:list-item>'
                  '</text:list>') % ZOE)
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 8
0
 def test_create_list(self):
     a_list = List([ZOE])
     expected = ("<text:list>"
                 "<text:list-item>"
                 "<text:p>%s</text:p>"
                 "</text:list-item>"
                 "</text:list>") % ZOE
     self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 9
0
    def test_insert_list(self):
        content = self.content
        clone = content.clone
        item = ListItem()
        a_list = List(style='a_style')
        a_list.append(item)
        body = clone.body
        body.append(a_list)

        expected = ('<text:list text:style-name="a_style">'
                    '<text:list-item/>'
                    '</text:list>')
        self.assertEqual(a_list.serialize(), expected)
Exemplo n.º 10
0
 def test_get_formatted_text(self):
     document = self.document
     body = self.body
     paragraph = body.get_element('//text:p')
     list_with_note = List()
     list_with_note.append_item(paragraph)
     body.append(list_with_note)
     expected = ("- Un paragraphe[1] d'apparence(i) banale[*].\n"
                 "----\n"
                 "[1] C'est-à-dire l'élément « text:p ».\n"
                 "\n"
                 "----\n"
                 "[*] Sauf qu'il est commenté !\n"
                 "\n"
                 "========\n"
                 "(i) Les apparences sont trompeuses !\n")
     self.assertEqual(document.get_formatted_text(), expected)
Exemplo n.º 11
0
    def test_insert_item(self):
        breakfast = List()
        breakfast.insert_item('spam', 1)
        breakfast.insert_item('eggs', 2)
        item = ListItem('ham')
        breakfast.insert_item(item, -1)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 12
0
    def test_insert_item(self):
        breakfast = List()
        breakfast.insert_item("spam", 1)
        breakfast.insert_item("eggs", 2)
        item = ListItem("ham")
        breakfast.insert_item(item, -1)

        expected = ("<text:list>"
                    "<text:list-item>"
                    "<text:p>spam</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:p>ham</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:p>eggs</text:p>"
                    "</text:list-item>"
                    "</text:list>")
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 13
0
    def test_insert_after(self):
        breakfast = List()
        breakfast.append_item('spam')
        ham = ListItem('ham')
        breakfast.append_item(ham)
        eggs = ListItem('eggs')
        breakfast.insert_item(eggs, after=ham)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 14
0
    def test_insert_before(self):
        breakfast = List()
        breakfast.append_item("spam")
        eggs = ListItem("eggs")
        breakfast.append_item(eggs)
        ham = ListItem("ham")
        breakfast.insert_item(ham, before=eggs)

        expected = ("<text:list>"
                    "<text:list-item>"
                    "<text:p>spam</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:p>ham</text:p>"
                    "</text:list-item>"
                    "<text:list-item>"
                    "<text:p>eggs</text:p>"
                    "</text:list-item>"
                    "</text:list>")
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
Exemplo n.º 15
0
    def test_nested_list(self):
        breakfast = List()
        spam = ListItem('spam')
        ham = ListItem('ham')
        eggs = ListItem('eggs')
        # First way: a list in an item, right next to a paragraph
        spam.append(List(['thé', 'café', 'chocolat']))
        breakfast.append_item(spam)
        breakfast.append_item(ham)
        breakfast.append_item(eggs)
        # Second way: a list as an item
        breakfast.append_item(breakfast.clone)

        expected = ('<text:list>\n'
                    '  <text:list-item>\n'
                    '    <text:p>spam</text:p>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>thé</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>café</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>chocolat</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>ham</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>eggs</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>spam</text:p>\n'
                    '        <text:list>\n'
                    '          <text:list-item>\n'
                    '            <text:p>thé</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>café</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>chocolat</text:p>\n'
                    '          </text:list-item>\n'
                    '        </text:list>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>ham</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>eggs</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '</text:list>\n')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(pretty=True), expected)