<s> """<STR_LIT>""" <EOL> import flask <EOL> import os <EOL> import sys <EOL> import pkgutil <EOL> import pytest <EOL> import textwrap <EOL> @ pytest . fixture <EOL> def test_apps ( monkeypatch ) : <EOL> monkeypatch . syspath_prepend ( <EOL> os . path . abspath ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> ) <EOL> @ pytest . fixture ( autouse = True ) <EOL> def leak_detector ( request ) : <EOL> def ensure_clean_request_context ( ) : <EOL> leaks = [ ] <EOL> while flask . _request_ctx_stack . top is not None : <EOL> leaks . append ( flask . _request_ctx_stack . pop ( ) ) <EOL> assert leaks == [ ] <EOL> request . addfinalizer ( ensure_clean_request_context ) <EOL> @ pytest . fixture ( params = ( True , False ) ) <EOL> def limit_loader ( request , monkeypatch ) : <EOL> """<STR_LIT>""" <EOL> if not request . param : <EOL> return <EOL> class LimitedLoader ( object ) : <EOL> def __init__ ( self , loader ) : <EOL> self . loader = loader <EOL> def __getattr__ ( self , name ) : <EOL> if name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> msg = '<STR_LIT>' % name <EOL> raise AttributeError ( msg ) <EOL> return getattr ( self . loader , name ) <EOL> old_get_loader = pkgutil . get_loader <EOL> def get_loader ( * args , ** kwargs ) : <EOL> return LimitedLoader ( old_get_loader ( * args , ** kwargs ) ) <EOL> monkeypatch . setattr ( pkgutil , '<STR_LIT>' , get_loader ) <EOL> @ pytest . fixture <EOL> def modules_tmpdir ( tmpdir , monkeypatch ) : <EOL> '''<STR_LIT>''' <EOL> rv = tmpdir . mkdir ( '<STR_LIT>' ) <EOL> monkeypatch . syspath_prepend ( str ( rv ) ) <EOL> return rv <EOL> @ pytest . fixture <EOL> def modules_tmpdir_prefix ( modules_tmpdir , monkeypatch ) : <EOL> monkeypatch . setattr ( sys , '<STR_LIT>' , str ( modules_tmpdir ) ) <EOL> return modules_tmpdir <EOL> @ pytest . fixture <EOL> def site_packages ( modules_tmpdir , monkeypatch ) : <EOL> '''<STR_LIT>''' <EOL> rv = modules_tmpdir . mkdir ( '<STR_LIT>' ) . mkdir ( '<STR_LIT>' . format ( x = sys . version_info ) ) . mkdir ( '<STR_LIT>' ) <EOL> monkeypatch . syspath_prepend ( str ( rv ) ) <EOL> return rv <EOL> @ pytest . fixture <EOL> def install_egg ( modules_tmpdir , monkeypatch ) : <EOL> '''<STR_LIT>''' <EOL> def inner ( name , base = modules_tmpdir ) : <EOL> if not isinstance ( name , str ) : <EOL> raise ValueError ( name ) <EOL> base . join ( name ) . ensure_dir ( ) <EOL> base . join ( name ) . join ( '<STR_LIT>' ) . ensure ( ) <EOL> egg_setup = base . join ( '<STR_LIT>' ) <EOL> egg_setup . write ( textwrap . dedent ( """<STR_LIT>""" . format ( name ) ) ) <EOL> import subprocess <EOL> subprocess . check_call ( <EOL> [ sys . executable , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> cwd = str ( modules_tmpdir ) <EOL> ) <EOL> egg_path , = modules_tmpdir . join ( '<STR_LIT>' ) . listdir ( ) <EOL> monkeypatch . syspath_prepend ( str ( egg_path ) ) <EOL> return egg_path <EOL> return inner <EOL> @ pytest . fixture <EOL> def purge_module ( request ) : <EOL> def inner ( name ) : <EOL> request . addfinalizer ( lambda : sys . modules . pop ( name , None ) ) <EOL> return inner <EOL> @ pytest . fixture <EOL> def catch_deprecation_warnings ( ) : <EOL> import warnings <EOL> warnings . simplefilter ( '<STR_LIT:default>' , category = DeprecationWarning ) <EOL> return lambda : warnings . catch_warnings ( record = True ) </s>
