| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: UTF-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (c) 2006 Emencia |
|---|
| 5 | # |
|---|
| 6 | # |
|---|
| 7 | # Authors: Tarek Ziade <tarek@emencia.com> |
|---|
| 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 | # $Id: test_docs.py 1110 2007-02-14 08:43:34Z tarek $ |
|---|
| 23 | import doctest |
|---|
| 24 | import unittest |
|---|
| 25 | import sys |
|---|
| 26 | import os |
|---|
| 27 | |
|---|
| 28 | def doc_suite(test_dir, setUp=None, tearDown=None, globs=None): |
|---|
| 29 | """returns a test suite, based on docs""" |
|---|
| 30 | suite = [] |
|---|
| 31 | if globs is None: |
|---|
| 32 | globs = globals() |
|---|
| 33 | |
|---|
| 34 | flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
|---|
| 35 | doctest.REPORT_ONLY_FIRST_FAILURE) |
|---|
| 36 | |
|---|
| 37 | product_dir = os.path.split(test_dir)[0] |
|---|
| 38 | if product_dir not in sys.path: |
|---|
| 39 | sys.path.append(product_dir) |
|---|
| 40 | |
|---|
| 41 | doc_dir = os.path.join(product_dir, 'doc') |
|---|
| 42 | #docs = [os.path.join(doc_dir, doc) for doc in |
|---|
| 43 | # os.listdir(doc_dir) if doc.endswith('.txt')] |
|---|
| 44 | docs = [os.path.join(doc_dir, doc) for doc in |
|---|
| 45 | os.listdir(doc_dir) if doc.endswith('ME.txt')] |
|---|
| 46 | |
|---|
| 47 | for test in docs: |
|---|
| 48 | suite.append(doctest.DocFileTest(test, |
|---|
| 49 | optionflags=flags, globs=globs, |
|---|
| 50 | setUp=setUp, tearDown=tearDown, |
|---|
| 51 | module_relative=False)) |
|---|
| 52 | |
|---|
| 53 | return unittest.TestSuite(suite) |
|---|
| 54 | |
|---|
| 55 | current_dir = os.path.dirname(__file__) |
|---|
| 56 | rss_file = os.path.join(current_dir, 'sample.xml') |
|---|
| 57 | |
|---|
| 58 | def test_suite(): |
|---|
| 59 | globs = globals() |
|---|
| 60 | globs['rss_file'] = rss_file |
|---|
| 61 | |
|---|
| 62 | return doc_suite(current_dir, globs=globs) |
|---|
| 63 | |
|---|
| 64 | if __name__ == '__main__': |
|---|
| 65 | unittest.main(defaultTest='test_suite') |
|---|