1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Added more tests for strip_tags utility

Refs #19237.
This commit is contained in:
Claude Paroz
2013-04-01 16:42:31 +02:00
parent b474ffe63a
commit a01361b5ae
3 changed files with 1436 additions and 0 deletions

View File

@@ -1,8 +1,12 @@
from __future__ import unicode_literals
from datetime import datetime
import os
import unittest
from django.utils import html
from django.utils._os import upath
class TestUtilsHtml(unittest.TestCase):
@@ -73,6 +77,18 @@ class TestUtilsHtml(unittest.TestCase):
for value, output in items:
self.check_output(f, value, output)
# Test with more lengthy content (also catching performance regressions)
for filename in ('strip_tags1.html', 'strip_tags2.txt'):
path = os.path.join(os.path.dirname(upath(__file__)), 'files', filename)
with open(path, 'r') as fp:
start = datetime.now()
stripped = html.strip_tags(fp.read())
elapsed = datetime.now() - start
self.assertEqual(elapsed.seconds, 0)
self.assertLess(elapsed.microseconds, 100000)
self.assertIn("Please try again.", stripped)
self.assertNotIn('<', stripped)
def test_strip_spaces_between_tags(self):
f = html.strip_spaces_between_tags
# Strings that should come out untouched.