LaTeX documentation update.
[docutils.git] / test / test_command_line.py
blobe7e3faa77176c0161ba7c6c105608a7414618105
1 #! /usr/bin/env python
2 # .. coding: utf-8
3 # $Id$
4 # Author: Günter Milde <milde@users.sourceforge.net>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Test module for the command line.
9 """
11 import unittest
12 import sys, codecs
13 import DocutilsTestSupport # must be imported before docutils
14 import docutils.core
16 # determine/guess the encoding of the standard input:
17 try:
18 import locale # module missing in Jython
19 locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
20 except ImportError:
21 locale_encoding = None
23 argv_encoding = locale_encoding or 'ascii'
24 try:
25 codecs.lookup(argv_encoding)
26 except LookupError:
27 argv_encoding = 'ascii'
30 class CommandLineEncodingTests(unittest.TestCase):
32 def test_sys_argv_decoding(self):
33 if argv_encoding == 'ascii': # cannot test
34 return
35 sys.argv.append('--source-url=test.txt') # pure ASCII argument
36 if sys.version_info < (3,0):
37 sys.argv.append(u'--title=Dornröschen'.encode(argv_encoding))
38 else:
39 sys.argv.append(u'--title=Dornröschen')
40 publisher = docutils.core.Publisher()
41 publisher.process_command_line()
42 self.assertEqual(publisher.settings.source_url, 'test.txt')
43 self.assertEqual(publisher.settings.title, u'Dornröschen')
44 sys.argv.pop() # --title
45 sys.argv.pop() # --source-url
48 if __name__ == '__main__':
49 unittest.main()