| 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. |
|---|
| 22 | import doctest |
|---|
| 23 | import unittest |
|---|
| 24 | import sys |
|---|
| 25 | import os |
|---|
| 26 | |
|---|
| 27 | def doc_suite(test_dir, setUp=None, tearDown=None, globs=None): |
|---|
| 28 | """returns a test suite, based on docs""" |
|---|
| 29 | suite = [] |
|---|
| 30 | if globs is None: |
|---|
| 31 | globs = globals() |
|---|
| 32 | |
|---|
| 33 | flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
|---|
| 34 | doctest.REPORT_ONLY_FIRST_FAILURE) |
|---|
| 35 | |
|---|
| 36 | product_dir = os.path.split(test_dir)[0] |
|---|
| 37 | if product_dir not in sys.path: |
|---|
| 38 | sys.path.append(product_dir) |
|---|
| 39 | |
|---|
| 40 | doc_dir = os.path.join(product_dir, 'doc') |
|---|
| 41 | #docs = [os.path.join(doc_dir, doc) for doc in |
|---|
| 42 | # os.listdir(doc_dir) if doc.endswith('.txt')] |
|---|
| 43 | docs = [os.path.join(doc_dir, doc) for doc in |
|---|
| 44 | os.listdir(doc_dir) if doc.endswith('.txt')] |
|---|
| 45 | |
|---|
| 46 | for test in docs: |
|---|
| 47 | suite.append(doctest.DocFileTest(test, |
|---|
| 48 | optionflags=flags, globs=globs, |
|---|
| 49 | setUp=setUp, tearDown=tearDown, |
|---|
| 50 | module_relative=False)) |
|---|
| 51 | |
|---|
| 52 | return unittest.TestSuite(suite) |
|---|
| 53 | |
|---|
| 54 | current_dir = os.path.dirname(__file__) |
|---|
| 55 | if current_dir == '': |
|---|
| 56 | current_dir = '.' |
|---|
| 57 | current_dir = os.path.realpath(current_dir) |
|---|
| 58 | |
|---|
| 59 | def test_suite(): |
|---|
| 60 | globs = globals() |
|---|
| 61 | test_db = os.path.join(current_dir, 'test.db') |
|---|
| 62 | if os.path.exists(test_db): |
|---|
| 63 | os.remove(test_db) |
|---|
| 64 | |
|---|
| 65 | globs['test_db'] = 'sqlite:////%s' % test_db |
|---|
| 66 | return doc_suite(current_dir, globs=globs) |
|---|
| 67 | |
|---|
| 68 | if __name__ == '__main__': |
|---|
| 69 | unittest.main(defaultTest='test_suite') |
|---|