Andriy Kornatskyy avatar Andriy Kornatskyy committed 15c1df2

Sort widget attributes so the render is consistent across python versions.

Comments (0)

Files changed (7)

src/wheezy/html/builder.py

         >>> errors = None
         >>> h = WidgetBuilder('age', '33', errors)
         >>> h.textbox(class_='b')
-        <input class="b" type="text" id="age" value="33" name="age" />
+        <input class="b" id="age" name="age" type="text" value="33" />
         >>> h.error()
         ''
         >>> errors = ['required']
         >>> h = WidgetBuilder('age', '0', errors)
         >>> h.textbox()
-        <input class="error" type="text" id="age" value="0" name="age" />
+        <input class="error" id="age" name="age" type="text" value="0" />
         >>> h.textbox(class_='b')
-        <input class="error b" type="text" id="age" value="0" name="age" />
+        <input class="error b" id="age" name="age" type="text" value="0" />
         >>> h.error()
         <span class="error">required</span>
     """

src/wheezy/html/ext/lexer.py

         if kwargs:
             return ' ' + ' '.join([
                 '%s="%s"' % (k, self.expression(kwargs[k]))
-                for k in kwargs])
+                for k in sorted(kwargs.keys())])
         else:
             return ''
 

src/wheezy/html/ext/parser.py

 
         >>> parse_kwargs('choices=account_types')
         {'choices': 'account_types'}
-        >>> parse_kwargs('autocomplete="off", maxlength=12')
-        {'autocomplete': '"off"', 'maxlength': '12'}
+        >>> sorted(parse_kwargs('autocomplete="off", maxlength=12').items())
+        [('autocomplete', '"off"'), ('maxlength', '12')]
     """
     kwargs = {}
     for m in RE_KWARGS.finditer(text + ','):

src/wheezy/html/ext/tests/test_lexer.py

             id = comment
             name = comment
             value = model.comment|f
-            attrs =  autocomplete="off" rows="9" cols="40"
+            attrs =  autocomplete="off" cols="40" rows="9"
             class = comment x
         """ == self.p.textarea('model.comment',
                                'class="x", autocomplete="off"', '|f')
         """
         assert """
             name = user_name
-            attrs =  cursor="auto" class="error"
+            attrs =  class="error" cursor="auto"
             expr_filter = |f
         """ == self.p.error('model.user_name',
                             'cursor="auto"', '|f')
         assert """
             name = user_name
-            attrs =  cursor="auto" class="error x"
+            attrs =  class="error x" cursor="auto"
             expr_filter = |f
         """ == self.p.error('model.user_name',
                             'class="x", cursor="auto"', '|f')
         assert """
             name = __ERROR__
-            attrs =  cursor="auto" class="error-message"
+            attrs =  class="error-message" cursor="auto"
             expr_filter = |f
         """ == self.p.error('model',
                             'cursor="auto"', '|f')
         assert """
             name = __ERROR__
-            attrs =  cursor="auto" class="error-message x"
+            attrs =  class="error-message x" cursor="auto"
             expr_filter = |f
         """ == self.p.error('model',
                             'class="x", cursor="auto"', '|f')
         assert """
             value = model.username
             info = model.username|f
-            attrs =  cursor="auto" class="info"
+            attrs =  class="info" cursor="auto"
         """ == self.p.info('model.username', 'cursor="auto"', '|f')
         assert """
             value = model.username
             info = model.username|f
-            attrs =  cursor="auto" class="info x"
+            attrs =  class="info x" cursor="auto"
         """ == self.p.info('model.username', 'class="x", cursor="auto"', '|f')
         assert """
             value = model
             info = model|f
-            attrs =  cursor="auto" class="info-message"
+            attrs =  class="info-message" cursor="auto"
         """ == self.p.info('model', 'cursor="auto"', '|f')
         assert """
             value = model
             info = model|f
-            attrs =  cursor="auto" class="info-message x"
+            attrs =  class="info-message x" cursor="auto"
         """ == self.p.info('model', 'class="x", cursor="auto"', '|f')
 
     def test_warning(self):
         assert """
             value = model.username
             info = model.username|f
-            attrs =  cursor="auto" class="warning"
+            attrs =  class="warning" cursor="auto"
         """ == self.p.warning('model.username', 'cursor="auto"', '|f')
         assert """
             value = model.username
             info = model.username|f
-            attrs =  cursor="auto" class="warning x"
+            attrs =  class="warning x" cursor="auto"
         """ == self.p.warning('model.username',
                               'class="x", cursor="auto"', '|f')
         assert """
             value = model
             info = model|f
-            attrs =  cursor="auto" class="warning-message"
+            attrs =  class="warning-message" cursor="auto"
         """ == self.p.warning('model', 'cursor="auto"', '|f')
         assert """
             value = model
             info = model|f
-            attrs =  cursor="auto" class="warning-message x"
+            attrs =  class="warning-message x" cursor="auto"
         """ == self.p.warning('model', 'class="x", cursor="auto"', '|f')
 
 
         self.m.comment = 'x'
         self.render(self.TEXTAREA,
                     '<textarea id="comment" name="comment" '
-                    'rows="9" cols="40">x</textarea>')
+                    'cols="40" rows="9">x</textarea>')
         self.e['comment'] = 'Error'
         self.render(self.TEXTAREA,
                     '<textarea id="comment" name="comment" '
-                    'rows="9" cols="40" class="error">x</textarea>')
+                    'cols="40" rows="9" class="error">x</textarea>')
 
     def test_checkbox(self):
         """ checkbox widget.

src/wheezy/html/factory.py

         HTML tags
 
         >>> user.id.hidden()
-        <input type="hidden" name="id" value="12345" />
+        <input name="id" type="hidden" value="12345" />
 
         >>> user.name.textbox(maxlength='30')  #doctest: +NORMALIZE_WHITESPACE
-        <input maxlength="30" type="text" id="name"
-            value="John" name="name" />
+        <input id="name" maxlength="30" name="name" type="text"
+            value="John" />
 
         >>> user.name.textarea(rows='10')  #doctest: +NORMALIZE_WHITESPACE
-        <textarea rows="10" cols="40" id="name"
-            name="name">John</textarea>
+        <textarea cols="40" id="name" name="name"
+            rows="10">John</textarea>
 
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input type="checkbox" id="accept" value="1" name="accept" />
+        <input id="accept" name="accept" type="checkbox" value="1" />
 
         >>> user = widget(model, errors)  # widget builders are cached
         >>> user.model.accept = True
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" type="checkbox" id="accept" value="1"
-            name="accept" />
+        <input checked="checked" id="accept" name="accept" type="checkbox"
+            value="1" />
 
         >>> user.favorite_color.label('Color:')
         <label for="favorite-color">Color:</label>
         HTML tags got class ``error``.
 
         >>> user.name.textbox(class_='x')  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error x" type="text" id="name" value="John"
-            name="name" />
+        <input class="error x" id="name" name="name" type="text"
+            value="John" />
         >>> user.name.textarea()  #doctest: +NORMALIZE_WHITESPACE
-        <textarea class="error" rows="9" cols="40" id="name"
-            name="name">John</textarea>
+        <textarea class="error" cols="40" id="name" name="name"
+            rows="9">John</textarea>
         >>> user.accept.checkbox()  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" name="accept" type="checkbox" id="accept"
-            value="1" class="error" />
+        <input checked="checked" class="error" id="accept" name="accept"
+            type="checkbox" value="1" />
         >>> user.favorite_color.label('Color:')
         <label class="error" for="favorite-color">Color:</label>
 

src/wheezy/html/markup.py

         name = self.name
         attrs = self.attrs
         t = '<' + name + ' ' + ' '.join(
-            [k.rstrip('_') + '="' + attrs[k] + '"' for k in attrs])
+            [k.rstrip('_') + '="' + attrs[k] + '"'
+                for k in sorted(attrs.keys())])
         inner = self.inner
         if inner is None:
             return t + ' />'

src/wheezy/html/widgets.py

     """ HTML element input of type hidden.
 
         >>> hidden('pref', 'abc')
-        <input type="hidden" name="pref" value="abc" />
+        <input name="pref" type="hidden" value="abc" />
     """
     return Tag('input', None, {
         'name': name,
 
         >>> items = ('a', 'b')
         >>> multiple_hidden('pref', items)  #doctest: +NORMALIZE_WHITESPACE
-        <input type="hidden" name="pref" value="a" /><input
-            type="hidden" name="pref" value="b" />
+        <input name="pref" type="hidden" value="a" /><input name="pref"
+            type="hidden" value="b" />
     """
     return Fragment([hidden(name, item) for item in value])
 
 
         >>> emptybox('zip_code', '',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="text" id="zip-code" name="zip_code" />
+        <input class="error" id="zip-code" name="zip_code" type="text" />
 
         >>> emptybox('zip_code', '79053',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="text" id="zip-code"
-            value="79053" name="zip_code" />
+        <input class="error" id="zip-code" name="zip_code" type="text"
+            value="79053" />
     """
     tag_attrs = {
         'id': html_id(name),
 
         >>> textbox('zip_code', '',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="text" id="zip-code" name="zip_code" />
+        <input class="error" id="zip-code" name="zip_code" type="text" />
 
         >>> textbox('zip_code', '79053',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="text" id="zip-code" value="79053"
-            name="zip_code" />
+        <input class="error" id="zip-code" name="zip_code" type="text"
+            value="79053" />
     """
     tag_attrs = {
         'id': html_id(name),
 
         >>> password('passwd', '',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="password" id="passwd" name="passwd" />
+        <input class="error" id="passwd" name="passwd" type="password" />
 
         >>> password('passwd', 'x',
         ...         attrs={'class': 'error'})  #doctest: +NORMALIZE_WHITESPACE
-        <input class="error" type="password" id="passwd" value="x"
-            name="passwd" />
+        <input class="error" id="passwd" name="passwd" type="password"
+            value="x" />
     """
     tag_attrs = {
         'id': html_id(name),
     """ HTML element textarea.
 
         >>> textarea('message_text', 'x', {})  #doctest: +NORMALIZE_WHITESPACE
-        <textarea rows="9" cols="40" id="message-text"
-            name="message_text">x</textarea>
+        <textarea cols="40" id="message-text" name="message_text"
+            rows="9">x</textarea>
 
         ``value`` is empty.
 
         >>> textarea('message_text', '', attrs={
         ...    'class': 'error', 'rows': '10'
         ... })  #doctest: +NORMALIZE_WHITESPACE
-        <textarea rows="10" name="message_text" class="error" cols="40"
-            id="message-text"></textarea>
+        <textarea class="error" cols="40" id="message-text"
+            name="message_text" rows="10"></textarea>
     """
     tag_attrs = {
         'id': html_id(name),
     """ HTML element input of type checkbox.
 
         >>> checkbox('accept', 'True', {})  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" type="checkbox" id="accept" value="1"
-            name="accept" />
+        <input checked="checked" id="accept" name="accept" type="checkbox"
+            value="1" />
         >>> checkbox('accept', 'False', {})  #doctest: +NORMALIZE_WHITESPACE
-        <input type="checkbox" id="accept" value="1" name="accept" />
+        <input id="accept" name="accept" type="checkbox" value="1" />
 
         >>> checkbox('accept', 'True',
         ...         attrs={'class': 'b'})  #doctest: +NORMALIZE_WHITESPACE
-        <input checked="checked" name="accept" type="checkbox" id="accept"
-            value="1" class="b" />
+        <input checked="checked" class="b" id="accept" name="accept"
+            type="checkbox" value="1" />
      """
     tag_attrs = {
         'id': html_id(name),
         >>> multiple_checkbox('scm', ['hg', 'git'], attrs={
         ...     'choices': scm, 'class': 'error'
         ... })  #doctest: +NORMALIZE_WHITESPACE
-        <label class="error"><input checked="checked" type="checkbox"
-            name="scm" value="git" class="error" />Git</label><label
-            class="error"><input checked="checked" type="checkbox"
-            name="scm" value="hg" class="error" />Mercurial</label><label
-            class="error"><input type="checkbox" name="scm" value="svn"
-            class="error" />SVN</label>
+        <label class="error"><input checked="checked" class="error"
+            name="scm" type="checkbox" value="git" />Git</label><label
+            class="error"><input checked="checked" class="error" name="scm"
+            type="checkbox" value="hg" />Mercurial</label><label
+            class="error"><input class="error" name="scm" type="checkbox"
+            value="svn" />SVN</label>
     """
     choices = attrs.pop('choices')
     elements = []
         ...     'choices': colors,
         ...     'class': 'error'
         ... })  #doctest: +NORMALIZE_WHITESPACE
-        <select class="error" multiple="multiple" id="favorite-color"
+        <select class="error" id="favorite-color" multiple="multiple"
             name="favorite_color"><option selected="selected"
             value="3">Blue</option><option value="2">Red</option><option
             selected="selected" value="1">Yellow</option></select>
         >>> radio('scm', 'hg', attrs={
         ...     'choices': scm, 'class': 'error'
         ... })  #doctest: +NORMALIZE_WHITESPACE
-        <label class="error"><input type="radio" name="scm" value="git"
-            class="error" />Git</label><label class="error"><input
-            checked="checked" type="radio" name="scm" value="hg"
-            class="error" />Mercurial</label>
+        <label class="error"><input class="error" name="scm" type="radio"
+            value="git" />Git</label><label class="error"><input
+            checked="checked" class="error" name="scm" type="radio"
+            value="hg" />Mercurial</label>
     """
     choices = attrs.pop('choices')
     elements = []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.