Permalink
Browse files

More descriptive ParameterError for invalid ids.

  • Loading branch information...
ralphbean committed Mar 13, 2012
1 parent b795f3f commit 6c06384ff72e306029bcef3f8cdde00e7b833690
Showing with 7 additions and 2 deletions.
  1. +2 −1 tests/test_hierarchy.py
  2. +5 −1 tw2/core/widgets.py
@@ -1,3 +1,4 @@
from nose.tools import eq_
import tw2.core as twc, testapi
class TestHierarchy(object):
@@ -19,7 +20,7 @@ def test_invalid_id(self):
a = twc.Widget(id=':')
assert(False)
except twc.ParameterError, e:
assert(str(e) == "Not a valid identifier: ':'")
eq_(str(e), "Not a valid W3C id: ':'")
def test_id_none(self):
test = twc.Widget(id=None)
@@ -177,12 +177,16 @@ def post_define(cls):
abstract class. There is no need to call super(), the metaclass will do
this automatically.
"""
if getattr(cls, 'id', None):
if not cls._valid_id_re.match(cls.id):
# http://www.w3schools.com/tags/att_standard_id.asp
raise pm.ParameterError(
"Not a valid identifier: '%s'" % cls.id)
"Not a valid W3C id: '%s'" % cls.id)
if hasattr(cls, 'id') and not getattr(cls, 'key', None):
cls.key = cls.id
cls.compound_id = cls._gen_compound_id(for_url=False)
if cls.compound_id:
cls.attrs = cls.attrs.copy()

0 comments on commit 6c06384

Please sign in to comment.