# Path: shimehari/shared.py
# class _SharedRequestClass(object):
# def _lookUpObjectInRequestContext(name):
# def findApp():


from contextlib import contextmanager
from werkzeug.test import Client, EnvironBuilder
from shimehari import _requestContextStack
    Shimehari.testing
    ~~~~~~~~~~~~~~~~~
    テスト
===============================
"""



def makeTestEnvironBuilder(app, path='/', baseUrl=None, *args, **kwargs):
    httpHost = app.config.get('SERVER_NAME')
    appRoot = app.config.get('APP_ROOT')
    if baseUrl is None:
        baseUrl = 'http://%s/' % (httpHost or 'localhost')
        if appRoot:
            baseUrl += appRoot.lstrip('/')
    return EnvironBuilder(path, baseUrl, *args, **kwargs)


class ShimehariClient(Client):

    preserveContext = False

    @contextmanager
    def sessionTransaction(self, *args, **kwargs):
        if self.cookieJar is None:
            raise RuntimeError('cookieeee')

        app = self.application
        environOverrides = kwargs.setdefault('environOverrides', {})
        self.cookie_jar.inject_wsgi(environOverrides)

# Path: shimehari/shared.py
# class _SharedRequestClass(object):
# def _lookUpObjectInRequestContext(name):
# def findApp():


# Path: shimehari/testing.py
from contextlib import contextmanager
from werkzeug.test import Client, EnvironBuilder
from shimehari import _requestContextStack

    Shimehari.testing
    ~~~~~~~~~~~~~~~~~
    テスト
===============================
"""



def makeTestEnvironBuilder(app, path='/', baseUrl=None, *args, **kwargs):
    httpHost = app.config.get('SERVER_NAME')
    appRoot = app.config.get('APP_ROOT')
    if baseUrl is None:
        baseUrl = 'http://%s/' % (httpHost or 'localhost')
        if appRoot:
            baseUrl += appRoot.lstrip('/')
    return EnvironBuilder(path, baseUrl, *args, **kwargs)


class ShimehariClient(Client):

    preserveContext = False

    @contextmanager
    def sessionTransaction(self, *args, **kwargs):
        if self.cookieJar is None:
            raise RuntimeError('cookieeee')

        app = self.application
        environOverrides = kwargs.setdefault('environOverrides', {})
        self.cookie_jar.inject_wsgi(environOverrides)

        otherReqContext = _requestContextStack.top