tests.py (1443B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\lib\jinja2\_markupsafe\tests.py 2 import gc 3 import unittest 4 from jinja2._markupsafe import Markup, escape, escape_silent 5 6 class MarkupTestCase(unittest.TestCase): 7 8 def test_markup_operations(self): 9 unsafe = '<script type="application/x-some-script">alert("foo");</script>' 10 safe = Markup('<em>username</em>') 11 x = Markup('foo') 12 13 class Foo(object): 14 15 def __html__(self): 16 return '<em>awesome</em>' 17 18 def __unicode__(self): 19 return 'awesome' 20 21 def test_all_set(self): 22 import jinja2._markupsafe as markup 23 for item in markup.__all__: 24 getattr(markup, item) 25 26 def test_escape_silent(self): 27 pass 28 29 30 class MarkupLeakTestCase(unittest.TestCase): 31 32 def test_markup_leaks(self): 33 counts = set() 34 for count in xrange(20): 35 for item in xrange(1000): 36 escape('foo') 37 escape('<foo>') 38 escape(u'foo') 39 escape(u'<foo>') 40 41 counts.add(len(gc.get_objects())) 42 43 44 def suite(): 45 suite = unittest.TestSuite() 46 suite.addTest(unittest.makeSuite(MarkupTestCase)) 47 if not hasattr(escape, 'func_code'): 48 suite.addTest(unittest.makeSuite(MarkupLeakTestCase)) 49 return suite 50 51 52 if __name__ == '__main__': 53 unittest.main(defaultTest='suite')