root/trunk/python/tests/test_doctests.py

Revision 889, 3.0 kB (checked in by hobu, 2 months ago)

more licensing documentation, cleanups, and some keywords

  • Property svn:keywords set to Id Author Date Version
Line 
1"""
2/******************************************************************************
3 * $Id$
4 *
5 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
6 * Purpose:  A script to marshal .txt files into Python doctests
7 * Author:   Sean C. Gillies, sgillies@frii.com
8 *
9 ******************************************************************************
10 *
11 * This file is from the Shapely project:
12 * http://trac.gispython.org/projects/PCL/browser/Shapely/trunk/tests/test_doctests.py
13 *
14 * Copyright (c) 2007, Sean C. Gillies
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 *
20 *     * Redistributions of source code must retain the above copyright
21 *       notice, this list of conditions and the following disclaimer.
22 *     * Redistributions in binary form must reproduce the above copyright
23 *       notice, this list of conditions and the following disclaimer in the
24 *       documentation and/or other materials provided with the distribution.
25 *     * Neither the name of Sean C. Gillies nor the names of
26 *       its contributors may be used to endorse or promote products derived from
27 *       this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 ****
41"""
42
43import doctest
44import unittest
45import glob
46import os
47
48optionflags = (doctest.REPORT_ONLY_FIRST_FAILURE |
49               doctest.NORMALIZE_WHITESPACE |
50               doctest.ELLIPSIS)
51
52def list_doctests():
53    return [filename
54            for filename
55            in glob.glob(os.path.join(os.path.dirname(__file__), '*.txt'))]
56
57def open_file(filename, mode='r'):
58    """Helper function to open files from within the tests package."""
59    return open(os.path.join(os.path.dirname(__file__), filename), mode)
60
61def setUp(test):
62    test.globs.update(dict(
63            open_file = open_file,
64            ))
65
66def test_suite():
67    return unittest.TestSuite(
68        [doctest.DocFileSuite(os.path.basename(filename),
69                              optionflags=optionflags,
70                              setUp=setUp)
71         for filename
72         in list_doctests()])
73
74if __name__ == "__main__":
75    runner = unittest.TextTestRunner(verbosity=1)
76    runner.run(test_suite())
Note: See TracBrowser for help on using the browser.