Commits

Sergey Schetinin committed 09d4a81

convert html_escape doctest into nose-based unittest

Comments (0)

Files changed (3)

 from mext.test_suite import TestSuite
 suite = TestSuite('tests', coverage=True, pkg='webob')
 
-doctests = ['test_dec', 'test_request', 'test_response', 'html_escape', 'multidict']
+doctests = ['test_dec', 'test_request', 'test_response', 'multidict']
 doctests += map('../docs/'.__add__, ['do-it-yourself', 'file-example', 'index', 'reference'])
 map(suite.add_doctest, doctests)
-map(suite.add_nosetest, ['test_request', 'test_response', 'test_multidict'])
+map(suite.add_nosetest, ['test_request', 'test_response', 'test_multidict', 'test_misc'])
 
 
 if __name__ == '__main__':

tests/html_escape.txt

-
-
-  >>> from webob import html_escape
-  >>> html_escape(None)
-  ''
-  >>> html_escape(' ')
-  ' '
-  >>> html_escape('è')
-  'è'
-  >>> html_escape(u'\xe9')
-  'é'
-
-  >>> class HTML(object):
-  ...   def __html__(self):
-  ...       return '<div>hello</div>'
-
-  >>> html_escape(HTML())
-  '<div>hello</div>'
-
-  >>> class Unicode(object):
-  ...   def __unicode__(self):
-  ...       return u'\xe9'
-
-  >>> html_escape(Unicode())
-  '&#233;'
-
-  >>> class UnsafeAttrs(object):
-  ...     attr = 'value'
-  ...     def __getattr__(self):
-  ...         return self.attr
-  ...     def __repr__(self):
-  ...         return '<UnsafeAttrs>'
-
-  >>> html_escape(UnsafeAttrs())
-  '&lt;UnsafeAttrs&gt;'

tests/test_misc.py

+from webob import html_escape
+from nose.tools import eq_
+
+
+def test_html_escape():
+    for v, s in [
+        (None, ''),
+        (' ', ' '),
+        ('&egrave;', '&amp;egrave;'),
+        (u'\xe9', '&#233;'),
+        (t_esc_HTML(), '<div>hello</div>'),
+        (t_esc_Unicode(), '&#233;'),
+        (t_esc_UnsafeAttrs(), '&lt;UnsafeAttrs&gt;'),
+    ]:
+        eq_(html_escape(v), s)
+
+
+class t_esc_HTML(object):
+    def __html__(self):
+        return '<div>hello</div>'
+
+
+class t_esc_Unicode(object):
+    def __unicode__(self):
+        return u'\xe9'
+
+class t_esc_UnsafeAttrs(object):
+    attr = 'value'
+    def __getattr__(self):
+        return self.attr
+    def __repr__(self):
+        return '<UnsafeAttrs>'
+
+