Permalink
Browse files

Deal with faulout from the twc.Required enforcement.

  • Loading branch information...
ralphbean committed Jun 5, 2013
1 parent 94e61ec commit b5063a3c72b01f4ffd06bd4eec2f11e162ec4c35
Showing with 29 additions and 22 deletions.
  1. +23 −19 tests/test_hierarchy.py
  2. +1 −1 tests/test_params.py
  3. +3 −1 tests/test_widgets.py
  4. +2 −1 tw2/core/resources.py
@@ -1,6 +1,11 @@
from nose.tools import eq_
import tw2.core as twc, testapi
class Child(twc.Widget):
template = None
class TestHierarchy(object):
def setUp(self):
testapi.setup()
@@ -10,32 +15,32 @@ def setUp(self):
#--
def test_compound_id(self):
test = twc.CompoundWidget(id='x', children=[
twc.Widget(id='a'),
twc.Widget(id='b'),
Child(id='a'),
Child(id='b'),
])
assert(test.children.a.compound_id == 'x:a')
def test_invalid_id(self):
try:
a = twc.Widget(id=':')
a = Child(id=':')
assert(False)
except twc.ParameterError as e:
eq_(str(e), "Not a valid W3C id: ':'")
def test_id_none(self):
test = twc.Widget(id=None)
test = Child(id=None)
assert(test.compound_id == None)
def test_repeating_id(self):
test = twc.RepeatingWidget(id='x', child=twc.Widget)
test = twc.RepeatingWidget(id='x', child=Child)
assert(test.rwbc[3].compound_id == 'x:3')
#--
# CompoundWidget / WidgetBunch
#--
def test_widgetbunch(self):
a = twc.Widget(id='a')
b = twc.Widget(id='b')
a = Child(id='a')
b = Child(id='b')
test = twc.widgets.WidgetBunch([a, b])
assert(len(test) == 2)
assert([w for w in test] == [a, b])
@@ -58,15 +63,15 @@ def xxtest_wb_nonwidget(self):
def xxtest_wb_dupe(self):
try:
test = twc.widgets.WidgetBunch([twc.Widget(id='a'), twc.Widget(id='a')])
test = twc.widgets.WidgetBunch([Child(id='a'), Child(id='a')])
assert(False)
except twc.WidgetError as e:
assert(str(e) == "WidgetBunch contains a duplicate id 'a'")
def test_cw_propagate(self):
testb = twc.CompoundWidget(id='a', template='x', children=[
twc.Widget(id='b'),
twc.Widget(id='c'),
Child(id='b'),
Child(id='c'),
])
test = testb.req(value = {'b':1, 'c':2})
test.prepare()
@@ -88,7 +93,7 @@ class A:
# Repeating Widget Bunch
#--
def test_rwb(self):
test = twc.RepeatingWidget(child=twc.Widget).req()
test = twc.RepeatingWidget(child=Child(template=None)).req()
testapi.request(1)
test.value = ['a', 'b', 'c']
test.prepare()
@@ -97,15 +102,15 @@ def test_rwb(self):
assert(test.children[0] is not test.children[1])
def test_rw_propagate(self):
test = twc.RepeatingWidget(child=twc.Widget).req()
test = twc.RepeatingWidget(child=Child).req()
testapi.request(1)
test.value = ['a', 'b', 'c']
test.prepare()
assert(len(test.children) == 3)
assert([w.value for w in test.children] == ['a', 'b', 'c'])
def test_rw_length(self):
testb = twc.RepeatingWidget(child=twc.Widget)
testb = twc.RepeatingWidget(child=Child)
test = testb.req(value=list(range(10)))
test.repetitions = None
@@ -135,8 +140,8 @@ def test_rw_length(self):
# Display only
#--
def test_display_only(self):
a = twc.Widget(id='a')
test = twc.DisplayOnlyWidget(child=a, template='xyz')
a = Child(id='a')
test = twc.DisplayOnlyWidget(child=a, template='xyz', id_suffix='test')
assert(a.parent is None)
assert(test.child.parent.template == test.template)
testapi.request(1)
@@ -150,12 +155,11 @@ def test_display_only(self):
def test_display_only_inherit(self):
class a(twc.DisplayOnlyWidget):
child = twc.CompoundWidget
wdgt = twc.Widget()
wdgt = Child()
class b(a):
wdgt2 = twc.Widget()
wdgt2 = Child()
test = b()
assert 'wdgt' in [c.id for c in test.child.children]
assert 'wdgt2' in [c.id for c in test.child.children]
@@ -77,7 +77,7 @@ def test_child(self):
def test_required(self):
""" Ensure that twc.Required works. For issue #25. """
class TestWidget(Test7):
class TestWidget(twc.Widget):
template = "whatever"
inline_engine_name="mako"
some_param = twc.Param(default=twc.Required)
@@ -454,6 +454,7 @@ def from_python(self, value, state=None):
class T(wd.Widget):
validator = MockValidator()
template = ""
i = T.req()
i.prepare()
@@ -597,7 +598,8 @@ def testMaxRepitions(self):
truncate reps based on max_reps??
"""
class T(wd.RepeatingWidget):
child = wd.Widget()
template = ""
child = wd.Widget(template="")
max_reps = 1
extra_reps = 2
@@ -83,6 +83,7 @@ class Resource(ResourceBundle):
'None means the resource will not be injected, which is still '\
'useful, e.g. static images.', default=None)
id = None
template = None
def prepare(self):
super(Resource, self).prepare()
@@ -278,7 +279,7 @@ class _JSFuncCall(JSSource):
Please use tw2.core.js_function(...) externally.
"""
src = None
function = Param('Function name')
function = Param('Function name', default=None)
args = Param('Function arguments', default=None)
location = 'bodybottom' # TBD: afterwidget?

0 comments on commit b5063a3

Please sign in to comment.