def _post_teardown(self): if self._ctx is not None: self._ctx.pop() if self.app is not None: self.app.response_class = self._orig_response_class if _is_signals: template_rendered.disconnect(self._add_template)
def _post_teardown(self): if getattr(self, 'app', None) is not None: if getattr(self, '_orig_response_class', None) is not None: self.app.response_class = self._orig_response_class del self.app if hasattr(self, 'client'): del self.client if hasattr(self, 'templates'): del self.templates if hasattr(self, 'flashed_messages'): del self.flashed_messages if _is_signals: template_rendered.disconnect(self._add_template) if _is_message_flashed: message_flashed.disconnect(self._add_flash_message) if hasattr(self, '_original_template_render'): templating._render = self._original_template_render if self.run_gc_after_test: gc.collect()
def _post_teardown(self): if getattr(self, "_ctx", None) is not None: self._ctx.pop() del self._ctx if getattr(self, "app", None) is not None: if getattr(self, "_orig_response_class", None) is not None: self.app.response_class = self._orig_response_class del self.app if hasattr(self, "client"): del self.client if hasattr(self, "templates"): del self.templates if hasattr(self, "flashed_messages"): del self.flashed_messages if _is_signals: template_rendered.disconnect(self._add_template) if _is_message_flashed: message_flashed.disconnect(self._add_flash_message) if hasattr(self, "_original_template_render"): templating._render = self._original_template_render if self.run_gc_after_test: gc.collect()
def tearDown(self): BaseTestCase.tearDown(self) template_rendered.disconnect(self._add_template) user_logged_in.disconnect(self._signal_login) user_logged_out.disconnect(self._signal_logout) _ctx = getattr(self, '_ctx', None) if self._ctx: self._ctx.pop()
def teardown(self, obj): obj.client = None obj.xhr_client = None if _request_ctx_stack.top and _request_ctx_stack.top.preserved: _request_ctx_stack.top.pop() obj._ctx.pop() obj._ctx = None template_rendered.disconnect(obj._add_template)
def record(sender, template, context, **extra): template = create_product_form() recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def __exit__(self, *nargs): if getattr(self, 'app', None) is not None: del self.app del self.templates[:] del self.flashed_messages[:] template_rendered.disconnect(self._add_template) message_flashed.disconnect(self._add_flash_message)
def run(self, result=None): self.rendered_templates = [] def record(sender, template, context, **extra): self.rendered_templates.append((template, context)) template_rendered.connect(record, self.app) super().run(result) template_rendered.disconnect(record, self.app)
def captured_templates(app): recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def tearDown(self): super().tearDown() template_rendered.disconnect(self._add_template) if HAVE_FLASK_LOGIN: user_logged_in.disconnect(self._signal_login) user_logged_out.disconnect(self._signal_logout) _ctx = getattr(self, '_ctx', None) if self._ctx: self._ctx.pop()
def teardown_method(self, method): del self.client db.drop_all() db.session.remove() self._ctx.pop() template_rendered.disconnect(self._add_template)
def captured_templates(app): ''' Records which templates are used ''' recorded = [] def record(app, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record) yield recorded template_rendered.disconnect(record)
def get_context_variables(app): recorded = [] def record(sender, template, context, **extra): recorded.append(context) template_rendered.connect(record, app) try: yield iter(recorded) finally: template_rendered.disconnect(record, app)
def templates(app): recorded = [] def record(sender, template, context, **extra): recorded.append(template) template_rendered.connect(record, app) yield recorded template_rendered.disconnect(record, app)
def templates(app): templates = [] def gravador_de_templates(remetente, template, context, **extra): templates.append(template) template_rendered.connect(gravador_de_templates, app) yield templates template_rendered.disconnect(gravador_de_templates, app)
def template_spy(test_app): calls = [] def spy(sender, template, context, **extra): calls.append((template, context)) template_rendered.connect(spy, test_app) yield calls template_rendered.disconnect(spy, test_app)
def used_templates(flask_app): recorded = [] def record(_, template, context): recorded.append((template, context)) template_rendered.connect(record, flask_app) try: yield recorded finally: template_rendered.disconnect(record, flask_app)
def captured_templates(app): """Context manager to provide a list of templates rendered by a request.""" templates = [] def capture_template(sender, template, context, **kwargs): templates.append((template, context)) template_rendered.connect(capture_template, app) try: yield templates finally: template_rendered.disconnect(capture_template, app)
def captured_templates(app): """Use signals to capture the templates rendered for a route.""" recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(): """receive templates name and context during flask render""" recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """use to keep track of templates rendered for testing""" recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """ Context manger to capture all rendered templates into a list.""" def record(sender, template, context, **extra): nonlocal recorded recorded.append((template, context)) recorded = [] template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def templates(app): records = [] RenderedTemplate = namedtuple('RenderedTemplate', 'template context') def record(sender, template, context, **extra): records.append(RenderedTemplate(template, context)) template_rendered.connect(record, app) try: yield records finally: template_rendered.disconnect(record, app)
def captured_templates(app): """ Function return the data from jinja templates """ recorded = [] def record(sender, template, context, **kwags): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """Context manager to help determine which templates were rendered""" recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """Determines which templates were rendered and what variables were passed to the template""" recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def rendered_context(app): """ Store templates and contexts rendered during a request. May be refactored out if needed elsewhere. """ merged_context = {} def record(sender, template, context, **extra): # pylint: disable=unused-argument merged_context.update(context) template_rendered.connect(record, app) try: yield merged_context finally: template_rendered.disconnect(record, app)
def record_templates(app): recorded = [] def record(sender, template, context, **extra): print('received template rendered sign~') print("sender:%s \n template:%s \n" % (sender, template)) recorded.append((template, sender)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_context(self, app): recorded = [] def record(sender, template, context, **extra): recorded.append(context) # This signal is sent when a template was successfully rendered. # The signal is invoked with the instance of the template as # template and the context as dictionary (named context). template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """Capture all templates being rendered along with the context used.""" recorded = [] def record(sender, template, context, **extra): # pylint:disable=unused-argument recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def capture_templates(app): """ Capture template in order to call them in test functions """ recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def captured_templates(app): """ https://stackoverflow.com/a/40531281/7154700 :param app: :return: """ recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def _post_teardown(self): if self._ctx is not None: self._ctx.pop() if self.app is not None: self.app.response_class = self._orig_response_class if _is_signals: template_rendered.disconnect(self._add_template) if hasattr(self, '_true_render'): templating._render = self._true_render del self.app del self.client del self.templates del self._ctx gc.collect()
def captured_templates(app): """ Used for figuring which templates and what context was used to render a request Thanks: http://flask.pocoo.org/docs/0.10/signals/ """ # Pylint comaplins about sender and extra, these are used by signals # pylint: disable=unused-argument recorded = [] def record(sender, template, context, **extra): recorded.append((template, context)) template_rendered.connect(record, app) try: yield recorded finally: template_rendered.disconnect(record, app)
def _post_teardown(self): """ Deactivate the testbed once the tests are completed. Otherwise the original stubs will not be restored. """ if hasattr(self, 'pre_teardown_hook'): self.pre_teardown_hook() self.tb.deactivate() if self._ctx is not None: self._ctx.pop() if self.app is not None: self.app.response_class = self._orig_response_class if _is_signals: template_rendered.disconnect(self._add_template) global taskqueue_test_client taskqueue_test_client = None if hasattr(self, 'post_teardown_hook'): self.post_teardown_hook()
def _post_teardown(self): if getattr(self, '_ctx', None) is not None: self._ctx.pop() del self._ctx if getattr(self, 'app', None) is not None: if getattr(self, '_orig_response_class', None) is not None: self.app.response_class = self._orig_response_class del self.app if hasattr(self, 'client'): del self.client if hasattr(self, 'templates'): del self.templates if _is_signals: template_rendered.disconnect(self._add_template) if hasattr(self, '_original_template_render'): templating._render = self._original_template_render if self.run_gc_after_test: gc.collect()
def teardown(): template_rendered.disconnect(record, app)
def capture(self): self.templates = [] template_rendered.connect(self._add_template) yield template_rendered.disconnect(self._add_template)