#!/usr/bin/env python

# 
# Test script for the grouch.util module.
# 
# created 2001/03/09, GPW
#

# XXX currently requires ExtensionClass!

__revision__ = "$Id: test_util.py,v 1.2 2001/08/21 22:20:28 gward Exp $"


from ExtensionClass import ExtensionClass, Base
from mems.tools.unittest import TestScenario, parse_args, run_scenarios
from grouch.util import issubclass, isinstance

tested_modules = ["grouch.util"]

class SuperEC (Base):
    pass

class ChildEC (SuperEC):
    pass

class Super:
    pass

class Child (Super):
    pass

class ECTest (TestScenario):

    def setup (self):
        self.super_ec = SuperEC()
        self.child_ec = ChildEC()
        self.super = Super()
        self.child = Child()

    def shutdown (self):
        del self.super_ec, self.child_ec
        del self.super, self.child


    test_cases = ['subclass_ec', 'subclass_normal',
                  'instance_ec', 'instance_normal']

    def check_subclass_ec (self):
        "EC classes and subclasses: 7"

        self.test_bool("issubclass(SuperEC, SuperEC)")
        self.test_bool("issubclass(SuperEC, Base)")

        self.test_bool("issubclass(ChildEC, ChildEC)")
        self.test_bool("issubclass(ChildEC, SuperEC)")
        self.test_bool("issubclass(ChildEC, Base)")

        self.test_bool("issubclass(SuperEC, ChildEC)", want_true=0)
        self.test_bool("issubclass(Base, ChildEC)", want_true=0)

    def check_subclass_normal (self):
        "normal classes and subclasses: 11"

        self.test_bool("issubclass(Super, Super)")
        self.test_bool("issubclass(Super, Base)", want_true=0)

        self.test_bool("issubclass(Child, Child)")
        self.test_bool("issubclass(Child, Super)")
        self.test_bool("issubclass(Child, Base)", want_true=0)

        self.test_bool("issubclass(Super, Child)", want_true=0)
        self.test_bool("issubclass(Base, Child)", want_true=0)
        
        self.test_bool("issubclass(Super, SuperEC)", want_true=0)
        self.test_bool("issubclass(Child, SuperEC)", want_true=0)

        self.test_bool("issubclass(ChildEC, Super)", want_true=0)
        self.test_bool("issubclass(ChildEC, Child)", want_true=0)
        
    def check_instance_ec (self):
        "EC instances: 9"

        self.test_bool("isinstance(self.super_ec, SuperEC)")
        self.test_bool("isinstance(self.super_ec, Base)")
        self.test_bool("isinstance(self.super_ec, Super)", want_true=0)
        self.test_bool("isinstance(self.super_ec, ChildEC)", want_true=0)

        self.test_bool("isinstance(self.child_ec, ChildEC)")
        self.test_bool("isinstance(self.child_ec, SuperEC)")
        self.test_bool("isinstance(self.child_ec, Base)")
        self.test_bool("isinstance(self.child_ec, Super)", want_true=0)
        self.test_bool("isinstance(self.child_ec, Child)", want_true=0)


    def check_instance_normal (self):
        "normal instances: 9"

        self.test_bool("isinstance(self.super, Super)")
        self.test_bool("isinstance(self.super, Base)", want_true=0)
        self.test_bool("isinstance(self.super, SuperEC)", want_true=0)
        self.test_bool("isinstance(self.super, ChildEC)", want_true=0)

        self.test_bool("isinstance(self.child, Child)")
        self.test_bool("isinstance(self.child, Super)")
        self.test_bool("isinstance(self.child, Base)", want_true=0)
        self.test_bool("isinstance(self.child, SuperEC)", want_true=0)
        self.test_bool("isinstance(self.child, ChildEC)", want_true=0)


# class ECTest


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