How to use test_env method in pytest-django

Best Python code snippet using pytest-django_python

test_imports.py

Source:test_imports.py Github

copy

Full Screen

...10from jinja2 import Environment, DictLoader11from jinja2.exceptions import TemplateNotFound, TemplatesNotFound, \12 TemplateSyntaxError13@pytest.fixture14def test_env():15 env = Environment(loader=DictLoader(dict(16 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',17 header='[{{ foo }}|{{ 23 }}]',18 o_printer='({{ o }})'19 )))20 env.globals['bar'] = 2321 return env22@pytest.mark.imports23class TestImports(object):24 def test_context_imports(self, test_env):25 t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')26 assert t.render(foo=42) == '[|23]'27 t = test_env.from_string(28 '{% import "module" as m without context %}{{ m.test() }}'...

Full Screen

Full Screen

imports.py

Source:imports.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 jinja2.testsuite.imports4 ~~~~~~~~~~~~~~~~~~~~~~~~5 Tests the import features (with includes).6 :copyright: (c) 2010 by the Jinja Team.7 :license: BSD, see LICENSE for more details.8"""9import unittest10from jinja2.testsuite import JinjaTestCase11from jinja2 import Environment, DictLoader12from jinja2.exceptions import TemplateNotFound, TemplatesNotFound13test_env = Environment(loader=DictLoader(dict(14 module='{% macro test() %}[{{ foo }}|{{ bar }}]{% endmacro %}',15 header='[{{ foo }}|{{ 23 }}]',16 o_printer='({{ o }})'17)))18test_env.globals['bar'] = 2319class ImportsTestCase(JinjaTestCase):20 def test_context_imports(self):21 t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')22 assert t.render(foo=42) == '[|23]'23 t = test_env.from_string('{% import "module" as m without context %}{{ m.test() }}')24 assert t.render(foo=42) == '[|23]'25 t = test_env.from_string('{% import "module" as m with context %}{{ m.test() }}')26 assert t.render(foo=42) == '[42|23]'27 t = test_env.from_string('{% from "module" import test %}{{ test() }}')28 assert t.render(foo=42) == '[|23]'29 t = test_env.from_string('{% from "module" import test without context %}{{ test() }}')30 assert t.render(foo=42) == '[|23]'31 t = test_env.from_string('{% from "module" import test with context %}{{ test() }}')32 assert t.render(foo=42) == '[42|23]'33 def test_trailing_comma(self):34 test_env.from_string('{% from "foo" import bar, baz with context %}')35 test_env.from_string('{% from "foo" import bar, baz, with context %}')36 test_env.from_string('{% from "foo" import bar, with context %}')37 test_env.from_string('{% from "foo" import bar, with, context %}')38 test_env.from_string('{% from "foo" import bar, with with context %}')39 def test_exports(self):40 m = test_env.from_string('''41 {% macro toplevel() %}...{% endmacro %}42 {% macro __private() %}...{% endmacro %}43 {% set variable = 42 %}44 {% for item in [1] %}45 {% macro notthere() %}{% endmacro %}46 {% endfor %}47 ''').module48 assert m.toplevel() == '...'49 assert not hasattr(m, '__missing')50 assert m.variable == 4251 assert not hasattr(m, 'notthere')52class IncludesTestCase(JinjaTestCase):53 def test_context_include(self):54 t = test_env.from_string('{% include "header" %}')55 assert t.render(foo=42) == '[42|23]'56 t = test_env.from_string('{% include "header" with context %}')57 assert t.render(foo=42) == '[42|23]'58 t = test_env.from_string('{% include "header" without context %}')59 assert t.render(foo=42) == '[|23]'60 def test_choice_includes(self):61 t = test_env.from_string('{% include ["missing", "header"] %}')62 assert t.render(foo=42) == '[42|23]'63 t = test_env.from_string('{% include ["missing", "missing2"] ignore missing %}')64 assert t.render(foo=42) == ''65 t = test_env.from_string('{% include ["missing", "missing2"] %}')66 self.assert_raises(TemplateNotFound, t.render)67 try:68 t.render()69 except TemplatesNotFound, e:70 assert e.templates == ['missing', 'missing2']71 assert e.name == 'missing2'72 else:73 assert False, 'thou shalt raise'74 def test_includes(t, **ctx):75 ctx['foo'] = 4276 assert t.render(ctx) == '[42|23]'77 t = test_env.from_string('{% include ["missing", "header"] %}')78 test_includes(t)79 t = test_env.from_string('{% include x %}')80 test_includes(t, x=['missing', 'header'])81 t = test_env.from_string('{% include [x, "header"] %}')82 test_includes(t, x='missing')83 t = test_env.from_string('{% include x %}')84 test_includes(t, x='header')85 t = test_env.from_string('{% include x %}')86 test_includes(t, x='header')87 t = test_env.from_string('{% include [x] %}')88 test_includes(t, x='header')89 def test_include_ignoring_missing(self):90 t = test_env.from_string('{% include "missing" %}')91 self.assert_raises(TemplateNotFound, t.render)92 for extra in '', 'with context', 'without context':93 t = test_env.from_string('{% include "missing" ignore missing ' +94 extra + ' %}')95 assert t.render() == ''96 def test_context_include_with_overrides(self):97 env = Environment(loader=DictLoader(dict(98 main="{% for item in [1, 2, 3] %}{% include 'item' %}{% endfor %}",99 item="{{ item }}"100 )))101 assert env.get_template("main").render() == "123"102 def test_unoptimized_scopes(self):103 t = test_env.from_string("""104 {% macro outer(o) %}105 {% macro inner() %}106 {% include "o_printer" %}107 {% endmacro %}108 {{ inner() }}109 {% endmacro %}110 {{ outer("FOO") }}111 """)112 assert t.render().strip() == '(FOO)'113def suite():114 suite = unittest.TestSuite()115 suite.addTest(unittest.makeSuite(ImportsTestCase))116 suite.addTest(unittest.makeSuite(IncludesTestCase))...

Full Screen

Full Screen

SConscript

Source:SConscript Github

copy

Full Screen

1#!/usr/bin/env python invoke_using_scons2Import('test_env')3import platform4# local sources5srcs = ['test.c','test_ascend_base.c','redirectStdStreams.c','printutil.c','assertimpl.c']6# test cases from the different tested modules7for dir in test_env['TESTDIRS']:8 srcs += test_env['TESTSRCS_'+dir.upper()]9test_env.Append(10 LIBS = ['ascend','cunit']11 , LIBPATH = ['#']12 , CPPDEFINES = ['-DASC_SHARED']13)14if test_env.has_key('CUNIT_CPPPATH'):15 test_env.Append(CPPPATH=test_env['CUNIT_CPPPATH'])16if test_env.has_key('CUNIT_LIBPATH'):17 test_env.Append(LIBPATH=test_env['CUNIT_LIBPATH'])18testprog = test_env.Program('test',srcs)19test_env.Depends(testprog,"#/ascend/utilities/test")20if platform.system()=="Windows":21 test_env.Depends(testprog,test_env['libascend'])22else:23 test_env.Depends(testprog,"#/libascend.so.1")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-django automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful