root / xap / tags / 0.1.4 / tests / test_docs.py

Revision 220:cb1c18a96b96, 2.2 kB (checked in by Lafaye Philippe (RAGE2000) <lafaye@…>, 10 months ago)

Add a new tag version of xap module

  • Property exe set to *
Line 
1#!/usr/bin/python
2# -*- coding: UTF-8 -*-
3#
4# Copyright (c) 2007 Tarek Ziadé
5#
6# Authors:
7#   Tarek Ziadé <tarek@ziade.org>
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22import doctest
23import unittest
24import sys
25import os
26
27current_dir = os.path.dirname(__file__)
28if current_dir == '':
29    current_dir = '.'
30
31abs_path = os.path.abspath(current_dir)
32
33if current_dir not in sys.path:
34    sys.path.append(os.path.split(current_dir)[0])
35
36# patching settings
37import settings
38settings.SQLURI = 'sqlite:///%s/data/base.sql3' % abs_path
39
40def doc_suite(test_dir, setUp=None, tearDown=None, globs=None):
41    """returns a test suite, based on docs"""
42    suite = []
43    if globs is None:
44        globs = globals()
45
46    flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
47             doctest.REPORT_ONLY_FIRST_FAILURE)
48
49    product_dir = os.path.split(test_dir)[0]
50    if product_dir not in sys.path:
51        sys.path.append(product_dir)
52
53    doc_dir = os.path.join(product_dir, 'doc')
54    #docs = [os.path.join(doc_dir, doc) for doc in
55    #        os.listdir(doc_dir) if doc.endswith('.txt')]
56    docs = [os.path.join(doc_dir, doc) for doc in
57            os.listdir(doc_dir) if doc.endswith('.txt')]
58
59    for test in docs:
60        suite.append(doctest.DocFileTest(test,
61                     optionflags=flags, globs=globs,
62                     setUp=setUp, tearDown=tearDown,
63                     module_relative=False))
64
65    return unittest.TestSuite(suite)
66
67
68def test_suite():
69    globs = globals()
70
71    return doc_suite(current_dir, globs=globs)
72
73if __name__ == '__main__':
74    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the browser.