#!/usr/bin/python2
# -*- coding: ISO-8859-1 -*-
# Copyright (C) 2006 Juan David Ibez Palomar <jdavid@itaapy.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# Import from the Standard Library
from optparse import OptionParser
import os
import sys
from types import ClassType
from unittest import TestCase, makeSuite, TestSuite, TextTestRunner

# Import from itools
import itools



if __name__ == '__main__':
    # The command line parser
    version = 'itools %s' % itools.__version__
    description = ('Builds the package.')
    parser = OptionParser('%prog', version=version, description=description)

    options, args = parser.parse_args()
    if len(args) != 0:
        parser.error('incorrect number of arguments')

    os.chdir('test')
    sys.path.insert(0, '')
    cmd = 'find -name "test_*.py"'
    for path in os.popen(cmd).readlines():
        path = path.strip()[2:-3]
        module = __import__(path)
        for name in dir(module):
            thing = getattr(module, name)
            if type(thing) is type and issubclass(thing, TestCase):
                if thing is not TestCase:
                    suite = makeSuite(thing)
                    runner = TextTestRunner(verbosity=0)
                    runner.run(suite)
