Date encoding test failed with Python 2.4.
[docutils.git] / test / test_parsers / test_rst / test_directives / test_date.py
blobaa027db07d23795820d103871c06bb771af9242c
1 #! /usr/bin/env python
3 # $Id$
4 # Author: David Goodger <goodger@python.org>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Tests for the misc.py "date" directive.
9 """
11 from __init__ import DocutilsTestSupport
12 import time
14 from docutils.utils.error_reporting import locale_encoding
16 def suite():
17 s = DocutilsTestSupport.ParserTestSuite()
18 s.generateTests(totest)
19 return s
21 totest = {}
23 totest['date'] = [
24 ["""\
25 .. |date| date::
27 Today's date is |date|.
28 """,
29 """\
30 <document source="test data">
31 <substitution_definition names="date">
33 <paragraph>
34 Today's date is \n\
35 <substitution_reference refname="date">
36 date
38 """ % time.strftime('%Y-%m-%d')],
39 ["""\
40 .. |date| date:: %a, %d %b %Y
41 """,
42 """\
43 <document source="test data">
44 <substitution_definition names="date">
46 """ % time.strftime('%a, %d %b %Y')],
47 ["""\
48 .. date::
49 """,
50 """\
51 <document source="test data">
52 <system_message level="3" line="1" source="test data" type="ERROR">
53 <paragraph>
54 Invalid context: the "date" directive can only be used within a substitution definition.
55 <literal_block xml:space="preserve">
56 .. date::
57 """],
60 # some locales return non-ASCII characters for names of days or months
61 if locale_encoding in ['utf8', 'utf-8', 'latin-1']:
62 totest['decode date'] = [
63 [u"""\
64 .. |date| date:: t\xc3glich
65 """,
66 u"""\
67 <document source="test data">
68 <substitution_definition names="date">
69 t\xc3glich
70 """],
73 if __name__ == '__main__':
74 import unittest
75 unittest.main(defaultTest='suite')