Beispiel #1
0
        def dirStaticTypes( me, obj):
            'yield parent-obj, local-name, typ  for all StaticTypes in hierarchy'

            for name,typ in obj._order_Statics( items=True):
                if issubclass( typ, StaticStruct):
                    obj1 = getattr( obj, name)
                    for obj1,name1,typ in me.dirStaticTypes( obj1):
                        yield obj1, name1,typ
                else:
                    if not typ.meta:
                        yield obj, name,typ
Beispiel #2
0
        def _test_set_value_OKERR( me, OK =True, title=''):
            parent = me.name
            r = me.test_ctor_OK( quiet=True)
            print
            functor = OK and SetGetAttr or SetAttr
            for obj,name,typ in me.dirStaticTypes( r):
                print ' %s.%s' % ( obj.__class__.__name__, typ)
                n = 0
                try:
                    tester = typ.tester
                except AttributeError:
                    tester = typ.Test( typ)
                inputs = (OK and tester.get_testValue_ok or tester.get_testValue_err)()
                #auto turn on
                if typ.optional and not typ.optional.__get__( obj):
                    typ.optional.__set__( obj, True)

                for func,expect in tester.test_inputs( obj, inputs, functor=functor):
                    n+=1
                    try:
                        result = func()
                    except:
                        e = result = sys.exc_info()[1]
                        if issubclass( expect, Exception) or isinstance( expect, tuple) and issubclass( expect[0], Exception):
                            #print '*******', e, expect
                            if isinstance( e, expect): continue
                            if isinstance( expect, tuple):
                                expect = ','.join( [p.__name__ for p in expect] )
                            else: expect = expect.__name__
                        result = result.__class__.__name__
                        experr = '\n' + title + me.experr % locals()
                        e.args = ((e.args and e.args[0] or '') + experr ,) + e.args[1:]
                        raise
                    else:
                        if expect != result:
                            raise AssertionError, (me.experr +title) % locals()
                if not n:
                    print ' ! no testValue_%s for %s' % ( OK and 'ok' or 'err', name)
            return r