blob: a2201430c8a06ae08a25a894000b7e8e059a52a0 (
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
|
#! /usr/bin/env python
# .. coding: utf8
# $Id$
# Author: Günter Milde <milde@users.sourceforge.net>
# Copyright: This module has been placed in the public domain.
"""
Test module for the command line.
"""
import os.path
import unittest
import sys
import DocutilsTestSupport # must be imported before docutils
import docutils.core
import docutils.utils
try:
import subprocess # new in 2.4
except ImportError:
argv_encoding = None
try:
import locale
argv_encoding = locale.getpreferredencoding()
except:
argv_encoding = None
testoutput = u"""\
<document source="<stdin>" title="Dornröschen">
<decoration>
<footer>
<paragraph>
"""
class CommandLineEncodingTests(unittest.TestCase):
# This does not work, as there is no "encoding" argument!
# def test_argv_encoding(self):
# if argv_encoding is None:
# # failure to load "locale" module
# return
# if sys.argv:
# self.assertEqual(sys.argv[0].encoding,
# locale.getpreferredencoding())
def test_argv_decoding(self):
if argv_encoding is None:
# failure to load "locale" or "subprocess" module
return # nothing to test
cmd_str = (u'../tools/rst2pseudoxml.py --no-generator '
u'--no-datestamp --title=Dornröschen')
p = subprocess.Popen([cmd_str.encode(argv_encoding)], shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.close()
output = p.stdout.read().decode(argv_encoding)
p.stdout.close()
self.assertEqual(output, testoutput)
if __name__ == '__main__':
unittest.main()
|