Permalink
Browse files

Merge pull request #94 from toscawidgets/feature/yielding-again

Feature/yielding again
  • Loading branch information...
ralphbean committed Aug 27, 2013
2 parents 1ac6f43 + ea14b79 commit 30e4c4b3d1bdda1a04c72b857cf24dbc1d6297cc
@@ -2,7 +2,6 @@ language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
install: python setup.py install
script: python setup.py test
@@ -10,14 +10,12 @@ recursive-include tw2/core/test_templates *.py
recursive-include tw2/core/test_templates *.html
recursive-include tw2/core/test_templates *.tmpl
recursive-include tw2/core/test_templates *.jinja
recursive-include tw2/core/test_templates *.kajiki
recursive-include tw2/core/test_templates *.pt
recursive-include tw2/core/test_templates *.mak
recursive-include tw2/core/templates *.py
recursive-include tw2/core/templates *.html
recursive-include tw2/core/templates *.tmpl
recursive-include tw2/core/templates *.jinja
recursive-include tw2/core/templates *.kajiki
recursive-include tw2/core/templates *.pt
recursive-include tw2/core/templates *.mak
prune *.pyc
@@ -124,7 +124,7 @@ When a value like ``{'title': 'my title'}`` is passed to MyForm, this will propa
Template
========
Every widget can have a template. Toscawidgets has some template-language hooks which currently support Genshi, Mako, Jinja2, Kajiki, and Chameleon.
Every widget can have a template. Toscawidgets has some template-language hooks which currently support Genshi, Mako, Jinja2, and Chameleon.
At one point, ToscaWidgets2 aimed to support any templating engine that supported the ``buffet`` interface, (an initiative by the TurboGears project to create a standard interface for template libraries). In practice though, there are more differences between template engines than the buffet interface standardises so this approach has been dropped.
@@ -36,11 +36,6 @@ def get_description(fname='README.rst'):
_extra_jinja = ["jinja2"]
_extra_chameleon = ["chameleon"]
if sys.version_info[0] == 3:
_extra_kajiki = []
else:
_extra_kajiki = ["kajiki"] # Broken for py3.3
requires = [
'WebOb>=0.9.7',
'PasteDeploy',
@@ -60,7 +55,6 @@ def get_description(fname='README.rst'):
_extra_genshi + \
_extra_mako + \
_extra_jinja + \
_extra_kajiki + \
_extra_chameleon
if sys.version_info[0] == 2:
@@ -85,7 +79,6 @@ def get_description(fname='README.rst'):
'genshi': _extra_genshi,
'mako': _extra_mako,
'jinja': _extra_jinja,
'kajiki': _extra_kajiki,
'chameleon': _extra_chameleon,
},
url = "http://toscawidgets.org/",
@@ -1,3 +1,4 @@
from __future__ import print_function
from nose.tools import eq_
import tw2.core as twc, testapi
import six
@@ -86,4 +87,5 @@ class TestWidget(twc.Widget):
TestWidget.display()
assert False, "Should have raised an exception."
except ValueError as e:
eq_(str(e), "'some_param' is a required Parameter")
print(str(e))
assert(str(e).startswith("'some_param' is a required Parameter"))
@@ -279,6 +279,10 @@ class TestJsSource(tb.WidgetTest):
attrs = {'src':'something'}
expected = '<script type="text/javascript">something</script>'
def _check_rendering_vs_expected(self, engine, *args, **kw):
base = super(TestJsSource, self)
return base._check_rendering_vs_expected(engine, *args, **kw)
def _test_repr_(self):
#not sure how to test resources.py:79
r = repr(self.widget(**self.attrs))
@@ -291,58 +295,70 @@ class TestJsFuncall(tb.WidgetTest):
expected = None
def test_display(self):
for t in self._get_all_possible_engines():
r = self.widget(**self.attrs).display(template='%s:%s' % (t, twr._JSFuncCall.template))
assert r == """<script type="text/javascript">foo("a", "b")</script>""", r
for engine in self._get_all_possible_engines():
yield self._check_equal, engine
def _check_equal(self, engine):
r = self.widget(**self.attrs).display(
template='%s:%s' % (engine, twr._JSFuncCall.template))
eq_(r, '<script type="text/javascript">foo("a", "b")</script>')
class TestJSSourceEscaping(tb.WidgetTest):
widget = twr.JSSource
attrs = {}
expected = None
def test_display(self):
s = twr.JSSource(src='''
s = twr.JSSource(src='''
function test(a, b) {
if (b < 5)
return b;
else
return "OK";
}
''')
r = s.req()
compare_to = None
for e in self._get_all_possible_engines():
display = r.display(
template='%s:%s' % (e, twr.JSSource.template)).strip()
if compare_to is None:
compare_to = display
else:
assert display == compare_to, e
compare_to = None
def test_display(self):
for engine in self._get_all_possible_engines():
yield self._check_equal, engine
def _check_equal(self, engine):
r = self.s.req()
display = r.display(
template='%s:%s' % (engine, twr.JSSource.template)).strip()
if self.compare_to is None:
self.compare_to = display
else:
eq_(display, self.compare_to)
class TestCSSSourceEscaping(tb.WidgetTest):
widget = twr.CSSSource
attrs = {}
expected = None
def test_display(self):
s = twr.CSSSource(src='''
s = twr.CSSSource(src='''
p > strong:after {
content:"WOAH, this was STRONG!";
}
''')
r = s.req()
compare_to = None
for e in self._get_all_possible_engines():
# CSSource misses pt template.
if e in ['chameleon']:
continue
display = r.display(
template='%s:%s' % (e, twr.CSSSource.template)).strip()
if compare_to is None:
compare_to = display
else:
assert display == compare_to, e
compare_to = None
def test_display(self):
for engine in self._get_all_possible_engines():
yield self._check_equal, engine
def _check_equal(self, engine):
if engine in ['chameleon']:
self.skipTest("CSSSource is missing a pt template.")
r = self.s.req()
display = r.display(
template='%s:%s' % (engine, twr.CSSSource.template)).strip()
if self.compare_to is None:
self.compare_to = display
else:
eq_(display, self.compare_to)
from pkg_resources import Requirement
class TestResourcesApp:
@@ -16,9 +16,6 @@
# TBD: only test engines that are installed
engines = ['genshi', 'mako', 'jinja', 'chameleon']
if not six.PY3:
engines.append('kajiki')
# Python 2.5 support shim. TODO -- remove this in the future.
if not hasattr(itertools, 'product'):
@@ -163,7 +160,7 @@ def test_widget_relative_inheritance(self):
twc.core.request_local()['middleware'] = twc.make_middleware(None)
# These aren't yet supported in the tests yet.
ignored_engines = ['jinja', 'kajiki', 'chameleon']
ignored_engines = ['jinja', 'chameleon']
for engine in engines:
if engine in ignored_engines:
@@ -75,7 +75,7 @@ class Config(object):
`preferred_rendering_engines`
List of rendering engines in order of preference.
(default: ['mako','genshi','jinja','kajiki'])
(default: ['mako','genshi','jinja'])
`strict_engine_selection`
If set to true, TW2 will only select rendering engines from within your
@@ -89,7 +89,6 @@ class Config(object):
'mako':['mak', 'mako'],
'genshi':['genshi', 'html'],
'jinja':['jinja', 'html'],
'kajiki':['kajiki', 'html'],
})
`script_name`
@@ -113,14 +112,13 @@ class Config(object):
validator_msgs = {}
encoding = 'utf-8'
auto_reload_templates = None
preferred_rendering_engines = ['mako', 'genshi', 'jinja', 'kajiki']
preferred_rendering_engines = ['mako', 'genshi', 'jinja']
strict_engine_selection = True
rendering_extension_lookup = {
'mako': ['mak', 'mako'],
'genshi': ['genshi', 'html'],
'genshi_abs': ['genshi', 'html'], # just for backwards compatibility with tw2 2.0.0
'jinja':['jinja', 'html'],
'kajiki':['kajiki', 'html'],
'chameleon': ['pt']
}
script_name = ''
@@ -22,11 +22,6 @@
'chameleon': ['pt']
}
if not six.PY3:
_default_rendering_extension_lookup.update({
'kajiki': ['kajiki', 'html'],
})
def get_rendering_extensions_lookup(mw):
if mw is None:
@@ -42,7 +37,7 @@ def get_engine_name(template_name, mw=None):
if template_name in engine_name_cache:
return engine_name_cache[template_name]
if ':' in template_name:
if template_name and ':' in template_name:
engine_name = template_name.split(':', 1)[0]
engine_name_cache[template_name] = engine_name
return engine_name
@@ -54,8 +49,6 @@ def get_engine_name(template_name, mw=None):
pref_rend_eng = mw.config.preferred_rendering_engines
except (KeyError, AttributeError):
pref_rend_eng = ['mako', 'genshi', 'jinja', 'chameleon']
if not six.PY3:
pref_rend_eng.append('kajiki')
# find the first file in the preffered engines available for templating
for engine_name in pref_rend_eng:
@@ -68,8 +61,6 @@ def get_engine_name(template_name, mw=None):
if not mw.config.strict_engine_selection:
pref_rend_eng = ['mako', 'genshi', 'jinja', 'chameleon']
if not six.PY3:
pref_rend_eng.append('kajiki')
for engine_name in pref_rend_eng:
try:
get_source(engine_name, template_name, mw=mw)
@@ -179,11 +170,6 @@ def get_render_callable(engine_name, displays_on, src, filename=None, inline=Fal
tmpl.filename = filename
return lambda kwargs: Markup(tmpl.render(**kwargs))
elif engine_name == 'kajiki':
import kajiki
tmpl = kajiki.XMLTemplate(src, filename=filename)
return lambda kwargs: Markup(tmpl(kwargs).render())
elif engine_name == 'chameleon':
import chameleon
tmpl = chameleon.PageTemplate(src, filename=filename)

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,7 +1,6 @@
import os
import re
import copy
import unittest
import pkg_resources as pk
@@ -91,7 +90,18 @@ class MyTestWidget(widget):
return MyTestWidget
class WidgetTest(unittest.TestCase):
class Base(object):
def setUp(self):
pass
def tearDown(self):
pass
def skipTest(self, msg):
raise SkipTest(msg)
class WidgetTest(Base):
"""
This class provides a basis for testing all widget classes. It's setup
will automatically create a request, and a widget of the type specified.
@@ -189,8 +199,8 @@ def test_display(self):
return
for engine in self._get_all_possible_engines():
self._check_rendering_vs_expected(engine,
self.attrs, self.params, self.expected)
yield self._check_rendering_vs_expected, \
engine, self.attrs, self.params, self.expected
def _check_validation(self, attrs, params, expected, raises=None):
if raises is not None:
@@ -209,11 +219,11 @@ def test_validate(self):
params[0] = self.attrs
if len(params) < 4:
params.append(None)
self._check_validation(params[0],
params[1], params[2], params[3])
yield self._check_validation, \
params[0], params[1], params[2], params[3]
class ValidatorTest(unittest.TestCase):
class ValidatorTest(Base):
"""
This test provides a basis for testing all validator classes. On
initialization, this class will make a request and a middleware
@@ -315,7 +325,8 @@ def test_validate(self):
if self.expected:
triples = six.moves.zip(self.attrs, self.params, self.expected)
for attrs, params, expected in triples:
self._check_validation(attrs, params, expected)
yield self._check_validation, \
attrs, params, expected
def test_from_python(self):
if self.from_python_expected:
@@ -325,8 +336,8 @@ def test_from_python(self):
self.from_python_expected,
)
for attrs, params, expected in triples:
self._check_validation(attrs, params,
expected, 'from_python')
yield self._check_validation, \
attrs, params, expected, 'from_python'
def test_to_python(self):
name = self.__class__.__name__
@@ -338,16 +349,16 @@ def test_to_python(self):
self.to_python_expected,
)
for attrs, params, expected in triples:
self._check_validation(attrs, params,
expected, 'to_python')
yield self._check_validation, \
attrs, params, expected, 'to_python'
import webob as wo
import webtest as wt
import tw2.core as twc
import os
class TestInPage(unittest.TestCase):
class TestInPage(Base):
content_type = 'text/html'
charset = 'UTF8'
@@ -483,6 +483,9 @@ def generate_output(self, displays_on):
if hasattr(self, p):
kwargs[p] = getattr(self, p)
if self.template is None:
raise ValueError("A template must be provided.")
return templating.render(
self.template,
displays_on,

0 comments on commit 30e4c4b

Please sign in to comment.