#!/usr/bin/python
# -*- coding: UTF-8 -*-

'''Run self tests.'''

# (c) 2007 Canonical Ltd.
#
# 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 unittest, os.path, sys, logging, os

from cStringIO import StringIO

# prefer modules in the local tree
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from jockey.oslib import OSLib

import sandbox

if __name__ == '__main__':
    os.environ['LC_ALL'] = 'C'

    # set the global OSLib instance for all tests
    OSLib.inst = sandbox.TestOSLib()

    # suppress log output to terminal for the test suite
    sandbox.log = StringIO()
    logging.basicConfig(stream=sandbox.log, level=logging.DEBUG)

    # run all tests in our directory
    suite = unittest.TestLoader().loadTestsFromNames(
        [t[:-3] for t in os.listdir(os.path.dirname(__file__)) 
         if t.endswith('.py')])
    res = unittest.TextTestRunner(verbosity=2).run(suite)

    if res.errors or res.failures:
        sys.exit(1)
