summaryrefslogtreecommitdiff
path: root/sandbox/docutils_xml/test/test_io.py
blob: fb66314ed4ba348ad06207a773c68eb62643ab4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Stefan Merten

# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

"""
Test I/O support classes for XML.
"""

import unittest

import DocutilsTestSupport

from docutils_xml.io import ZipFileInput

###############################################################################

class HelloZipFileInput(ZipFileInput):

    content = u'Hello world!\n'

    contentUnicode = u'Hello wörld!\n'

    contentPath = "hello.txt"

###############################################################################

class InputTests(unittest.TestCase):

    def test_simple(self):
        input = HelloZipFileInput(source_path="data/hello.zip")
        self.assertEqual(input.read(), HelloZipFileInput.content)

    def test_nonZip(self):
        input = HelloZipFileInput(source='')
        with self.assertRaises(ValueError):
            input.read()

    def test_emptyZip(self):
        input = HelloZipFileInput(source_path="data/empty.zip")
        with self.assertRaises(KeyError):
            input.read()

    def test_undecodedZip(self):
        input = HelloZipFileInput(source_path="data/utf8.zip")
        self.assertEqual(input.read(),
                         HelloZipFileInput.contentUnicode.encode("utf-8"))

    def test_utf8Zip(self):
        input = HelloZipFileInput(source_path="data/utf8.zip", encoding="utf-8")
        self.assertEqual(input.read(), HelloZipFileInput.contentUnicode)

    def test_latin1Zip(self):
        input = HelloZipFileInput(source_path="data/latin1.zip",
                                  encoding="iso-8859-1")
        self.assertEqual(input.read(), HelloZipFileInput.contentUnicode)