parameters: (*fixtures_in)
return_statement: return decorator
docstring: Find all fixtures, including dependencies, topologically sorted
docstring_summary: Find all fixtures, including dependencies, topologically sorted
docstring_tokens: Find all fixtures including dependencies topologically sorted
function: def uses(*fixtures_in):
          """Find all fixtures, including dependencies, topologically sorted"""
          fixtures = []
          reversed_fixtures = []
          stack = list(fixtures_in)
          while stack:
              fixture = stack.pop()
              reversed_fixtures.append(fixture)
              stack.extend(getattr(fixture, "__prerequisites__", ()))
          for fixture in reversed(reversed_fixtures):
              if isinstance(fixture, str):
                  fixture = Template(fixture)
              if fixture not in fixtures:
                  fixtures.append(fixture)
  
          def decorator(func):
  
              if Fixture.__fixture_debug__:
                  # in debug mode log all calls to fixtures
                  def call(obj, f, args=()):
                      logging.debug("Calling %s.%s", obj.__class__.__name__, f)
                      return getattr(obj, f)(*args)
  
              else:
  
                  def call(obj, f, args=()):
                      return getattr(obj, f)(*args)
  
              @functools.wraps(func)
              def wrapper(*args, **kwargs):
                  # data shared by all fixtures in the pipeline for each request
                  shared_data = {"template_context": {}}
                  try:
                      for obj in fixtures:
                          call(obj, "on_request")
                      ret = func(*args, **kwargs)
                      for obj in fixtures:
                          ret = call(obj, "transform", (ret, shared_data))
                      for obj in fixtures:
                          call(obj, "on_success", (200,))
                      return ret
                  except HTTP as http:
                      if http.type == http.Type.success:
                          for obj in fixtures:
                              call(obj, "on_success", (http.status,))
                      else:
                          if obj in fixtures:
                              call(obj, "on_error")
                      raise
                  except Exception:
                      for obj in fixtures:
                          call(obj, "on_error")
                      raise
                  finally:
                      for obj in fixtures:
                          call(obj, "finalize")
                      # Clears the current object to prevent leakage.
  
              return wrapper
  
          return decorator
function_tokens: def uses ( * fixtures_in ) : fixtures = [ ] reversed_fixtures = [ ] stack = list ( fixtures_in ) while stack : fixture = stack . pop ( ) reversed_fixtures . append ( fixture ) stack . extend ( getattr ( fixture , "__prerequisites__" , ( ) ) ) for fixture in reversed ( reversed_fixtures ) : if isinstance ( fixture , str ) : fixture = Template ( fixture ) if fixture not in fixtures : fixtures . append ( fixture ) def decorator ( func ) : if Fixture . __fixture_debug__ : # in debug mode log all calls to fixtures def call ( obj , f , args = ( ) ) : logging . debug ( "Calling %s.%s" , obj . __class__ . __name__ , f ) return getattr ( obj , f ) ( * args ) else : def call ( obj , f , args = ( ) ) : return getattr ( obj , f ) ( * args ) @ functools . wraps ( func ) def wrapper ( * args , * * kwargs ) : # data shared by all fixtures in the pipeline for each request shared_data = { "template_context" : { } } try : for obj in fixtures : call ( obj , "on_request" ) ret = func ( * args , * * kwargs ) for obj in fixtures : ret = call ( obj , "transform" , ( ret , shared_data ) ) for obj in fixtures : call ( obj , "on_success" , ( 200 , ) ) return ret except HTTP as http : if http . type == http . Type . success : for obj in fixtures : call ( obj , "on_success" , ( http . status , ) ) else : if obj in fixtures : call ( obj , "on_error" ) raise except Exception : for obj in fixtures : call ( obj , "on_error" ) raise finally : for obj in fixtures : call ( obj , "finalize" ) # Clears the current object to prevent leakage. return wrapper return decorator