コード例 #1
0
    def test_empty(self):
        "Check empty cases: 2"

        # Empty file
        xml = self.xml_header + "<quotations></quotations>"
        input = StringIO(xml)
        self.assertEqual(parse.parse(input), [])

        # Empty quotation
        xml = self.xml_header + ("<quotations><quotation>"
                                 "</quotation></quotations>")
        input = StringIO(xml)
        L = []
        parse.parse(input)
コード例 #2
0
    def test_parse(self):
        "Check parsing of an actual quotation"
        # Empty quotation
        xml = self.xml_header + ("""<quotations>
        <quotation id="qtid" date="2000-01-01" type="funny, silly">
        <p>para1</p><p><em>bold</em></p><p>line1<br/>line2</p>
        <author type="a1,a2">a1</author>
        <source type="s1,s2">s1</source><note><p>n1</p></note>
        </quotation></quotations>""")

        input = StringIO(xml)
        coll = parse.parse(input)

        qt = coll[0]
        self.assertEqual(qt.id, 'qtid')
        self.assertEqual(qt.date, '2000-01-01')
        self.assertEqual(qt.type, ['funny', 'silly'])

        # Check first and second paragraph
        self.assertEqual(qt.text[0][0].as_text(), 'para1')
        self.assertEqual(qt.text[1][0].as_text(), '*bold*')

        # Test third paragraph contains a Break
        self.assertTrue(isinstance(qt.text[2][1], quotation.Break))

        # Check author, source, and notes
        self.assertEqual(qt.author.as_text(), 'a1')
        self.assertEqual(qt.author.type, ['a1','a2'])
        self.assertEqual(qt.source.as_text(), 's1')
        self.assertEqual(qt.source.type, ['s1','s2'])
        self.assertEqual(qt.note[0][0].as_text(), 'n1')
コード例 #3
0
    def test_parse_header(self):
        "Check parsing of the file header"
        xml = self.xml_header + ("""<quotations>
          <title>Test Title</title><editor>Me</editor>
          <description>More text</description>
          <copyright>Terms</copyright>
          <license><p>para1</p><p>para2</p></license>
        </quotations>""")

        input = StringIO(xml)
        coll = parse.parse(input)

        self.assertEqual(coll.title, 'Test Title')
        self.assertEqual(coll.editor, 'Me')
        self.assertEqual(coll.description, 'More text')