当前位置: 首页>>代码示例>>Python>>正文


Python util.function_named函数代码示例

本文整理汇总了Python中sqlalchemy.util.function_named函数的典型用法代码示例。如果您正苦于以下问题:Python function_named函数的具体用法?Python function_named怎么用?Python function_named使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了function_named函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decorator

    def decorator(fn):
        def profiled(*args, **kw):
            if (target not in profile_config['targets'] and
                not target_opts.get('always', None)):
                return fn(*args, **kw)

            elapsed, load_stats, result = _profile(
                filename, fn, *args, **kw)

            report = target_opts.get('report', profile_config['report'])
            if report:
                sort_ = target_opts.get('sort', profile_config['sort'])
                limit = target_opts.get('limit', profile_config['limit'])
                print "Profile report for target '%s' (%s)" % (
                    target, filename)

                stats = load_stats()
                stats.sort_stats(*sort_)
                if limit:
                    stats.print_stats(limit)
                else:
                    stats.print_stats()
                #stats.print_callers()
            os.unlink(filename)
            return result
        return function_named(profiled, fn.__name__)
开发者ID:MaxMorais,项目名称:skink,代码行数:26,代码来源:profiling.py

示例2: make_test

    def make_test(fetchtype):
        def test_roundtrip(self):
            class A(_fixtures.Base):pass
            class B(A):pass
            class C(B):pass

            if fetchtype == 'union':
                abc = a.outerjoin(b).outerjoin(c)
                bc = a.join(b).outerjoin(c)
            else:
                abc = bc = None

            mapper(A, a, with_polymorphic=('*', abc), polymorphic_on=a.c.type, polymorphic_identity='a')
            mapper(B, b, with_polymorphic=('*', bc), inherits=A, polymorphic_identity='b')
            mapper(C, c, inherits=B, polymorphic_identity='c')

            a1 = A(adata='a1')
            b1 = B(bdata='b1', adata='b1')
            b2 = B(bdata='b2', adata='b2')
            b3 = B(bdata='b3', adata='b3')
            c1 = C(cdata='c1', bdata='c1', adata='c1')
            c2 = C(cdata='c2', bdata='c2', adata='c2')
            c3 = C(cdata='c2', bdata='c2', adata='c2')

            sess = create_session()
            for x in (a1, b1, b2, b3, c1, c2, c3):
                sess.add(x)
            sess.flush()
            sess.expunge_all()

            #for obj in sess.query(A).all():
            #    print obj
            assert [
                A(adata='a1'),
                B(bdata='b1', adata='b1'),
                B(bdata='b2', adata='b2'),
                B(bdata='b3', adata='b3'),
                C(cdata='c1', bdata='c1', adata='c1'),
                C(cdata='c2', bdata='c2', adata='c2'),
                C(cdata='c2', bdata='c2', adata='c2'),
            ] == sess.query(A).order_by(A.id).all()

            assert [
                B(bdata='b1', adata='b1'),
                B(bdata='b2', adata='b2'),
                B(bdata='b3', adata='b3'),
                C(cdata='c1', bdata='c1', adata='c1'),
                C(cdata='c2', bdata='c2', adata='c2'),
                C(cdata='c2', bdata='c2', adata='c2'),
            ] == sess.query(B).all()

            assert [
                C(cdata='c1', bdata='c1', adata='c1'),
                C(cdata='c2', bdata='c2', adata='c2'),
                C(cdata='c2', bdata='c2', adata='c2'),
            ] == sess.query(C).all()

        test_roundtrip = function_named(
            test_roundtrip, 'test_%s' % fetchtype)
        return test_roundtrip
开发者ID:AndryulE,项目名称:kitsune,代码行数:60,代码来源:test_abc_polymorphic.py

示例3: assert_conns_closed

def assert_conns_closed(fn):
    def decorated(*args, **kw):
        try:
            fn(*args, **kw)
        finally:
            testing_reaper.assert_all_closed()
    return function_named(decorated, fn.__name__)
开发者ID:MaxMorais,项目名称:skink,代码行数:7,代码来源:engines.py

示例4: decorate

    def decorate(fn):
        def safe(*args, **kw):
            # todo: should probably be strict about this, too
            filters = [dict(action='ignore',
                            category=sa_exc.SAPendingDeprecationWarning)]
            if not messages:
                filters.append(dict(action='ignore',
                                    category=sa_exc.SADeprecationWarning))
            else:
                filters.extend(
                    [dict(action='ignore',
                          message=message,
                          category=sa_exc.SADeprecationWarning)
                     for message in
                     [ (m.startswith('//') and
                        ('Call to deprecated function ' + m[2:]) or m)
                       for m in messages] ])

            for f in filters:
                warnings.filterwarnings(**f)
            try:
                return fn(*args, **kw)
            finally:
                resetwarnings()
        return function_named(safe, fn.__name__)
开发者ID:gajop,项目名称:springgrid,代码行数:25,代码来源:testing.py

示例5: resolve_artifact_names

def resolve_artifact_names(fn):
    """Decorator, augment function globals with tables and classes.

    Swaps out the function's globals at execution time. The 'global' statement
    will not work as expected inside a decorated function.

    """
    # This could be automatically applied to framework and test_ methods in
    # the MappedTest-derived test suites but... *some* explicitness for this
    # magic is probably good.  Especially as 'global' won't work- these
    # rebound functions aren't regular Python..
    #
    # Also: it's lame that CPython accepts a dict-subclass for globals, but
    # only calls dict methods.  That would allow 'global' to pass through to
    # the func_globals.
    def resolved(*args, **kwargs):
        self = args[0]
        context = dict(fn.func_globals)
        for source in self._artifact_registries:
            context.update(getattr(self, source))
        # jython bug #1034
        rebound = types.FunctionType(
            fn.func_code, context, fn.func_name, fn.func_defaults,
            fn.func_closure)
        return rebound(*args, **kwargs)
    return function_named(resolved, fn.func_name)
开发者ID:gajop,项目名称:springgrid,代码行数:26,代码来源:testing.py

示例6: decorate

 def decorate(fn):
     def wrapped(*args, **kw):
         try:
             attributes._install_lookup_strategy(strategy)
             return fn(*args, **kw)
         finally:
             attributes._install_lookup_strategy(sa.util.symbol('native'))
     return function_named(wrapped, fn.func_name)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:8,代码来源:test_instrumentation.py

示例7: close_first

def close_first(fn):
    """Decorator that closes all connections before fn execution."""

    def decorated(*args, **kw):
        testing_reaper.close_all()
        fn(*args, **kw)

    return function_named(decorated, fn.__name__)
开发者ID:blitzmann,项目名称:Pyfa-skel,代码行数:8,代码来源:engines.py

示例8: rollback_open_connections

def rollback_open_connections(fn):
    """Decorator that rolls back all open connections after fn execution."""

    def decorated(*args, **kw):
        try:
            fn(*args, **kw)
        finally:
            testing_reaper.rollback_all()
    return function_named(decorated, fn.__name__)
开发者ID:MaxMorais,项目名称:skink,代码行数:9,代码来源:engines.py

示例9: modifies_instrumentation_finders

def modifies_instrumentation_finders(fn):
    def decorated(*args, **kw):
        pristine = attributes.instrumentation_finders[:]
        try:
            fn(*args, **kw)
        finally:
            del attributes.instrumentation_finders[:]
            attributes.instrumentation_finders.extend(pristine)
    return function_named(decorated, fn.func_name)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_instrumentation.py

示例10: close_open_connections

def close_open_connections(fn):
    """Decorator that closes all connections after fn execution."""

    def decorated(*args, **kw):
        try:
            fn(*args, **kw)
        finally:
            testing_reaper.close_all()
    return function_named(decorated, fn.__name__)
开发者ID:MaxMorais,项目名称:skink,代码行数:9,代码来源:engines.py

示例11: decorate

 def decorate(fn):
     fn_name = fn.__name__
     def maybe(*args, **kw):
         if predicate():
             msg = "'%s' skipped on DB %s version '%s': %s" % (
                 fn_name, config.db.name, _server_version(), reason)
             raise SkipTest(msg)
         else:
             return fn(*args, **kw)
     return function_named(maybe, fn_name)
开发者ID:dreamwave,项目名称:rad,代码行数:10,代码来源:testing.py

示例12: decorate

 def decorate(fn):
     fn_name = fn.__name__
     def maybe(*args, **kw):
         if predicate():
             msg = "'%s' skipped on DB %s version '%s': %s" % (
                 fn_name, config.db.name, _server_version(), reason)
             print msg
             if carp:
                 print >> sys.stderr, msg
             return True
         else:
             return fn(*args, **kw)
     return function_named(maybe, fn_name)
开发者ID:cnelsonsic,项目名称:Liquor-Cabinet,代码行数:13,代码来源:testing.py

示例13: provide_metadata

def provide_metadata(fn):
    """Provides a bound MetaData object for a single test, 
    drops it afterwards."""
    def maybe(*args, **kw):
        metadata = schema.MetaData(db)
        context = dict(fn.func_globals)
        context['metadata'] = metadata
        # jython bug #1034
        rebound = types.FunctionType(
            fn.func_code, context, fn.func_name, fn.func_defaults,
            fn.func_closure)
        try:
            return rebound(*args, **kw)
        finally:
            metadata.drop_all()
    return function_named(maybe, fn.__name__)
开发者ID:cnelsonsic,项目名称:Liquor-Cabinet,代码行数:16,代码来源:testing.py

示例14: _create_backref_test

def _create_backref_test(autoflush, saveuser):

    @testing.resolve_artifact_names
    def test_backref(self):
        mapper(User, users, properties={
            'addresses':dynamic_loader(mapper(Address, addresses), backref='user')
        })
        sess = create_session(autoflush=autoflush)

        u = User(name='buffy')

        a = Address(email_address='[email protected]')
        a.user = u

        if saveuser:
            sess.add(u)
        else:
            sess.add(a)

        if not autoflush:
            sess.flush()

        assert u in sess
        assert a in sess

        self.assert_(list(u.addresses) == [a])

        a.user = None
        if not autoflush:
            self.assert_(list(u.addresses) == [a])

        if not autoflush:
            sess.flush()
        self.assert_(list(u.addresses) == [])

    test_backref = function_named(
        test_backref, "test%s%s" % ((autoflush and "_autoflush" or ""),
                                    (saveuser and "_saveuser" or "_savead")))
    setattr(SessionTest, test_backref.__name__, test_backref)
开发者ID:gajop,项目名称:springgrid,代码行数:39,代码来源:test_dynamic.py

示例15: _generate_round_trip_test


#.........这里部分代码省略.........
            Manager(status='ABA', manager_name='manager2', **{person_attribute_name:'jsmith'})
        ]
        
        pointy = employees[0]
        jsmith = employees[-1]
        dilbert = employees[1]
        
        session = create_session()
        c = Company(name='company1')
        c.employees = employees
        session.add(c)

        session.flush()
        session.expunge_all()
        
        eq_(session.query(Person).get(dilbert.person_id), dilbert)
        session.expunge_all()

        eq_(session.query(Person).filter(Person.person_id==dilbert.person_id).one(), dilbert)
        session.expunge_all()

        def go():
            cc = session.query(Company).get(c.company_id)
            eq_(cc.employees, employees)
            
        if not lazy_relation:
            if with_polymorphic != 'none':
                self.assert_sql_count(testing.db, go, 1)
            else:
                self.assert_sql_count(testing.db, go, 5)

        else:
            if with_polymorphic != 'none':
                self.assert_sql_count(testing.db, go, 2)
            else:
                self.assert_sql_count(testing.db, go, 6)
        
        # test selecting from the query, using the base mapped table (people) as the selection criterion.
        # in the case of the polymorphic Person query, the "people" selectable should be adapted to be "person_join"
        eq_(
            session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first(),
            dilbert
        )

        assert session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first().person_id

        eq_(
            session.query(Engineer).filter(getattr(Person, person_attribute_name)=='dilbert').first(),
            dilbert
        )
        
        # test selecting from the query, joining against an alias of the base "people" table.  test that
        # the "palias" alias does *not* get sucked up into the "person_join" conversion.
        palias = people.alias("palias")
        dilbert = session.query(Person).get(dilbert.person_id)
        assert dilbert is session.query(Person).filter((palias.c.name=='dilbert') & (palias.c.person_id==Person.person_id)).first()
        assert dilbert is session.query(Engineer).filter((palias.c.name=='dilbert') & (palias.c.person_id==Person.person_id)).first()
        assert dilbert is session.query(Person).filter((Engineer.engineer_name=="engineer1") & (engineers.c.person_id==people.c.person_id)).first()
        assert dilbert is session.query(Engineer).filter(Engineer.engineer_name=="engineer1")[0]
        
        dilbert.engineer_name = 'hes dibert!'

        session.flush()
        session.expunge_all()
        
        def go():
            session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first()
        self.assert_sql_count(testing.db, go, 1)
        session.expunge_all()
        dilbert = session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first()
        def go():
            # assert that only primary table is queried for already-present-in-session
            d = session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first()
        self.assert_sql_count(testing.db, go, 1)

        # test standalone orphans
        daboss = Boss(status='BBB', manager_name='boss', golf_swing='fore', **{person_attribute_name:'daboss'})
        session.add(daboss)
        assert_raises(orm_exc.FlushError, session.flush)
        c = session.query(Company).first()
        daboss.company = c
        manager_list = [e for e in c.employees if isinstance(e, Manager)]
        session.flush()
        session.expunge_all()

        eq_(session.query(Manager).order_by(Manager.person_id).all(), manager_list)
        c = session.query(Company).first()
        
        session.delete(c)
        session.flush()
        
        eq_(people.count().scalar(), 0)
        
    test_roundtrip = function_named(
        test_roundtrip, "test_%s%s%s_%s" % (
          (lazy_relation and "lazy" or "eager"),
          (include_base and "_inclbase" or ""),
          (redefine_colprop and "_redefcol" or ""),
          with_polymorphic))
    setattr(RoundTripTest, test_roundtrip.__name__, test_roundtrip)
开发者ID:clones,项目名称:sqlalchemy,代码行数:101,代码来源:test_polymorph.py


注:本文中的sqlalchemy.util.function_named函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。