Skip to content

Commit

Permalink
Merge pull request #24 from zopefoundation/to-str-with-list
Browse files Browse the repository at this point in the history
Fixed ``toStr`` to handle lists, for example a list of class names.
  • Loading branch information
davisagli committed Feb 3, 2017
2 parents f6f605c + 1d718d7 commit ab4bb47
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,9 @@ CHANGES
5.2 (unreleased)
----------------

- Fixed ``toStr`` to handle lists, for example a list of class names.
[maurits]

- Fixed browser to only follow redirects for HTTP statuses
301, 302, 303, and 307; not other 30x statuses such as 304.

Expand Down
6 changes: 6 additions & 0 deletions src/zope/testbrowser/browser.py
Expand Up @@ -528,6 +528,12 @@ def toStr(self, s):
return s
if s is None:
return None
# Might be an iterable, especially the 'class' attribute.
if isinstance(s, (list, tuple)):
subs = [self.toStr(sub) for sub in s]
if isinstance(s, tuple):
return tuple(subs)
return subs
if PYTHON2 and not isinstance(s, bytes):
return s.encode(self._response.charset)
if not PYTHON2 and isinstance(s, bytes):
Expand Down
18 changes: 18 additions & 0 deletions src/zope/testbrowser/tests/test_browser.py
Expand Up @@ -957,6 +957,24 @@ def test_controls_without_value(self):
"""


def test_multiple_classes(self):
"""
>>> app = TestApp()
>>> browser = Browser(wsgi_app=app)
>>> app.set_next_response(b'''\
... <html><body>
... <a href="" class="one two">A link</a>
... </body></html>
... ''')
>>> browser.open('http://localhost/')
GET / HTTP/1.1
...
>>> from pprint import pprint
>>> pprint(browser.getLink('A link').attrs)
{'class': ['one', 'two'], 'href': ''}
"""


def test_suite():
return doctest.DocTestSuite(
checker=zope.testbrowser.tests.helper.checker,
Expand Down

0 comments on commit ab4bb47

Please sign in to comment.