Best Python code snippet using pytest-django_python
test_imports.py
Source: test_imports.py
...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() }}'...
imports.py
Source: imports.py
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))...
SConscript
Source: SConscript
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")...
Check out the latest blogs from LambdaTest on this topic:
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!