Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_render_template_with_env_globals(template_path, build_path):
"""Ensure variables defined in env_globals can be accessed globally."""
template_name = 'template.html'
template_path.join(template_name).write('<h1>{{greeting}}</h1>')
site = make_site(searchpath=str(template_path),
outpath=str(build_path),
env_globals={'greeting': 'Hello world!'})
site.render_template(site.get_template(template_name))
assert build_path.join(template_name).read() == '<h1>Hello world!</h1>'
template_path.join('template2.html').write('Test 2')
template_path.mkdir('sub').join('template3.html').write('Test {{b}}')
template_path.join('template4.html').write('Test {{b}} and {{c}}')
template_path.mkdir('static_css').join('hello.css').write(
'a { color: blue; }'
)
template_path.mkdir('static_js').join('hello.js').write(
'var a = function () {return true};'
)
template_path.join('favicon.ico').write('Fake favicon')
contexts = [('template2.html', lambda t: {'a': 1}),
('.*template3.html', lambda: {'b': 3}),
('template4.html', {'b': 4, 'c': 5}),
('.*[4-9].html', {'c': 6})]
rules = [('template2.html', lambda env, t, a: None), ]
return make_site(searchpath=str(template_path),
outpath=str(build_path),
contexts=contexts,
rules=rules)
def reloader(site):
return Reloader(site)
def test_with_reloader(reloader, site):
reloader.watch_called = False
def watch(self):
reloader.watch_called = True
Reloader.watch = watch
site.render(use_reloader=True)
assert reloader.watch_called
def test_cli_srcpath_absolute(mock_make_site, mock_getcwd, mock_isdir):
mock_isdir.return_value = True
mock_getcwd.return_value = '/'
cli.render({
'--srcpath': '/foo/templates',
'--outpath': None,
'--static': None,
'watch': False,
})
mock_make_site.assert_called_once_with(
searchpath='/foo/templates',
outpath='/',
staticpaths=None
)
def test_cli_srcpath_default(mock_make_site, mock_getcwd, mock_isdir):
mock_isdir.return_value = True
mock_getcwd.return_value = '/'
cli.render({
'--srcpath': None,
'--outpath': None,
'--static': None,
'watch': False,
})
mock_make_site.assert_called_once_with(
searchpath='/templates',
outpath='/',
staticpaths=None
)
def test_cli_srcpath(mock_make_site, mock_getcwd, mock_isdir):
mock_isdir.return_value = True
mock_getcwd.return_value = '/'
cli.render({
'--srcpath': 'templates',
'--outpath': None,
'--static': None,
'watch': False,
})
mock_make_site.assert_called_once_with(
searchpath='/templates',
outpath='/',
staticpaths=None
)
print("The output directory '%s' is invalid."
% outpath)
sys.exit(1)
staticdirs = args['--static']
staticpaths = None
if staticdirs:
staticpaths = staticdirs.split(",")
for path in staticpaths:
path = os.path.join(srcpath, path)
if not os.path.isdir(path):
print("The static files directory '%s' is invalid." % path)
sys.exit(1)
site = staticjinja.make_site(
searchpath=srcpath,
outpath=outpath,
staticpaths=staticpaths
)
use_reloader = args['watch']
site.render(use_reloader=use_reloader)
import staticjinja
if __name__ == "__main__":
site = staticjinja.make_site()
site.render()
def html():
global entries
s = make_site(
contexts=[
('index.html', load_reports),
('.*.json', load_report),
],
rules=[
('.*.json', render_report),
],
outpath='output',
staticpaths=('static/',)
)
s.render()