| Line | |
|---|
| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: UTF-8 -*- |
|---|
| 3 | import doctest |
|---|
| 4 | import unittest |
|---|
| 5 | import os |
|---|
| 6 | |
|---|
| 7 | flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | |
|---|
| 8 | doctest.REPORT_ONLY_FIRST_FAILURE) |
|---|
| 9 | |
|---|
| 10 | def getTextFiles(path): |
|---|
| 11 | """grab all text files and return a list of absolute paths""" |
|---|
| 12 | textfiles = [] |
|---|
| 13 | for root, dirs, files in os.walk(path): |
|---|
| 14 | for filename in files: |
|---|
| 15 | if not filename.endswith('.txt'): |
|---|
| 16 | continue |
|---|
| 17 | textfiles.append(os.path.realpath(os.path.join(root, filename))) |
|---|
| 18 | return textfiles |
|---|
| 19 | |
|---|
| 20 | def test_suite(): |
|---|
| 21 | suite = [] |
|---|
| 22 | path = os.path.dirname(__file__) |
|---|
| 23 | if path == '': |
|---|
| 24 | path = '.' |
|---|
| 25 | for testfile in getTextFiles(path): |
|---|
| 26 | suite.append(doctest.DocFileTest(testfile, optionflags=flags, |
|---|
| 27 | module_relative=False)) |
|---|
| 28 | return unittest.TestSuite(suite) |
|---|
| 29 | |
|---|
| 30 | if __name__ == '__main__': |
|---|
| 31 | unittest.main(defaultTest='test_suite') |
|---|
| 32 | |
|---|