#!/www/python/bin/python

"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_typeutils.py $
$Id: test_typeutils.py 20909 2003-03-04 14:35:33Z dbinger $

Test for dulcinea.typeutils.
"""

from types import *
from sancho.unittest import TestScenario, parse_args, run_scenarios
from dulcinea.typeutils import typecheck, typecheck_seq

tested_modules = [ "dulcinea.typeutils" ]

class TypeUtilsTest (TestScenario):

    def check_typecheck_seq (self):
        self.test_stmt("typecheck_seq([4, 2], IntType)")
        self.test_exc("typecheck_seq([4.0, 2], IntType)", TypeError)
        self.test_exc("typecheck_seq([4.0, 2], FloatType)", TypeError)
        self.test_stmt("typecheck_seq([4.0, 2.0], FloatType)")
        self.test_stmt("typecheck_seq(['foo', 'bar', 'baz'], str)")
        self.test_exc("typecheck_seq(['foo', 'bar', 666], str)", TypeError)
        self.test_stmt("typecheck_seq([], str)")
        self.test_stmt("typecheck_seq([], FloatType)")
        self.test_stmt("typecheck_seq([], IntType)")
        self.test_exc("typecheck_seq(4, IntType)", TypeError)
        self.test_exc("typecheck_seq(None, IntType)", TypeError)
        self.test_stmt("typecheck_seq(None, IntType, allow_none=1)")

    def check_typecheck (self):
        self.test_stmt("typecheck(4, IntType)")
        self.test_exc("typecheck(4.0, IntType, allow_none=1)", TypeError)
        self.test_stmt("typecheck(4.0, (FloatType, IntType))")
        self.test_exc("typecheck('foo', (FloatType, IntType))", TypeError)
        self.test_exc("typecheck(None, IntType)", TypeError)
        self.test_stmt("typecheck(None, IntType, allow_none=1)")

if __name__ == "__main__":
    (scenarios, options) = parse_args()
    run_scenarios (scenarios, options)
