widget attribute order and unittests...

12 views
Skip to first unread message

jens

unread,
May 17, 2011, 9:32:14 AM5/17/11
to Django developers
Check the path output in unittests are difficult, if a form widget
should be checked.

The Problem:
The widget html attribute order is not contingent and may change from
test to tests, because they come from a python dict witch is
unordered...

A simple patch could fix this, by adding sorted() to
forms.util.flatatt():

-------------------------------------------------------------------------------------------------------------------
diff --git a/django/forms/util.py b/django/forms/util.py
index 1a1d823..8a48009 100644
--- a/django/forms/util.py
+++ b/django/forms/util.py
@@ -13,7 +13,7 @@ def flatatt(attrs):
XML-style pairs. It is assumed that the keys do not need to be
XML-escaped.
If the passed dictionary is empty, then return an empty string.
"""
- return u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k,
v in attrs.items()])
+ return u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k,
v in sorted(attrs.items())])

class ErrorDict(dict, StrAndUnicode):
"""
-------------------------------------------------------------------------------------------------------------------
see also: https://gist.github.com/976467

Should i open a ticked for this?

Mfg.

Jens D.
Reply all
Reply to author
Forward
0 new messages