Debian Codegraph @

src/zc/customdoctests/tests.py

raw
1 ##############################################################################
2 #
3 # Copyright (c) 2010 Zope Foundation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 # from zope.testing import setupstack
15 # import manuel.capture
16 # import manuel.doctest
17 # import manuel.testing
18 import unittest
19 import doctest
20
21 import zc.customdoctests.js
22
23 def custom_doctest_parser():
24 r"""
25 >>> [e] = zc.customdoctests.DocTestParser().get_examples('''
26 ...
27 ... >>> 2 + 2 # doctest: +ELLIPSIS
28 ... 5
29 ...
30 ... ''')
31 >>> e.source, e.want, e.options == {doctest.ELLIPSIS: True}
32 ('2 + 2 # doctest: +ELLIPSIS\n', '5\n', True)
33
34 >>> [e] = zc.customdoctests.DocTestParser(
35 ... ps1='js>', comment_prefix='//', transform=lambda s: 'JS(%r)' % s
36 ... ).get_examples('''
37 ...
38 ... js> 2 +
39 ... ... 2 // doctest: +ELLIPSIS
40 ... 5
41 ...
42 ... >>> x
43 ... 1
44 ...
45 ... ''')
46 >>> e.source, e.want, e.options == {doctest.ELLIPSIS: True}
47 ("JS('2 +\\n2 // doctest: +ELLIPSIS\\n')", '5\n', True)
48
49 """
50
51 def test_suite():
52 suite = unittest.TestSuite([doctest.DocTestSuite()])
53 try:
54 import spidermonkey
55 except ImportError:
56 pass
57 else:
58 import manuel.capture
59 import manuel.doctest
60 import manuel.testing
61 suite.addTest(
62 manuel.testing.TestSuite(
63 manuel.doctest.Manuel(parser=zc.customdoctests.js.parser) +
64 manuel.doctest.Manuel(parser=zc.customdoctests.js.eq_parser) +
65 manuel.doctest.Manuel() +
66 manuel.capture.Manuel(),
67 'spidermonkey.txt',
68 setUp=zc.customdoctests.js.spidermonkeySetUp)
69 )
70 return suite
71