U SW @s|ddlmZddlZddlmZddlmZedZGdddeZ Gdd d ej Z Gd d d eZ Gd d d e Z dS)wrapsN)create_model_tables)drop_model_tablespeeweec@s&eZdZd ddZddZddZd S) test_databaseTFcCs>t|tttfstd|||_||_||_||_||_ dS)Nz%r must be a list or tuple.) isinstancelisttupleset ValueErrordbmodels create_tables drop_tables fail_silently)selfr rrrrr/test_utils.py__init__ s ztest_database.__init__cCsFg|_|jD]}|j|jj|j|j_q |jrBt|j|jddSN)r) origrappend_metadatabaser rrr)rmrrr __enter__s   ztest_database.__enter__cCsB|jr|jrt|j|jdt|jD]\}}|j||j_q&dSr) rrrrr enumeraterrr)rexc_typeexc_valexc_tbirrrr__exit__s ztest_database.__exit__N)TTF)__name__ __module__ __qualname__rrr"rrrrr s  rc@seZdZddZddZdS)_QueryLogHandlercOsg|_tjj|f||dSN)queriesloggingHandlerr)rargskwargsrrrr%sz_QueryLogHandler.__init__cCs|j|dSr')r(r)rrecordrrremit)sz_QueryLogHandler.emitN)r#r$r%rr.rrrrr&$sr&c@s.eZdZd ddZddZddZdd Zd S) count_queriesFcCs||_d|_dS)Nr) only_selectcount)rr0rrrr.szcount_queries.__init__cCs|jjSr')_handlerr(rrrr get_queries2szcount_queries.get_queriescCs$t|_ttjt|j|Sr')r&r2loggerZsetLevelr)DEBUGZ addHandlerr3rrrr5s  zcount_queries.__enter__cCs>t|j|jr,tdd|jjD|_nt|jj|_dS)NcSs g|]}|jddr|qS)rzSELECT )msg startswith).0qrrr >sz*count_queries.__exit__..)r5Z removeHandlerr2r0lenr(r1rrrr rrrr";s zcount_queries.__exit__N)F)r#r$r%rr4rr"rrrrr/-s r/cs:eZdZd fdd ZddZddZfdd ZZS) assert_query_countFcstt|j|d||_dS)N)r0)superr>rexpected)rr@r0 __class__rrrEszassert_query_count.__init__cstfdd}|S)Nc s&||}W5QRX|Sr') _assert_count)r+kwdsZretfrrr decoratedJsz.assert_query_count.__call__..decoratedr)rrFrGrrEr__call__Iszassert_query_count.__call__cCsd|j|jf}dS)Nz%s != %s)r1r@)rZ error_msgrrrrCTsz assert_query_count._assert_countcs tt|||||dSr')r?r>r"rCr=rArrr"Xszassert_query_count.__exit__)F)r#r$r%rrHrCr" __classcell__rrrArr>Ds r>) functoolsrr)rrrZ getLoggerr5objectrr*r&r/r>rrrrs