Skip to content

Commit 9ecbc38

Browse files
committed
Added benchmarks for SimpleTestCase assertions.
1 parent 3dd44e3 commit 9ecbc38

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

benchmarks/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"benchmarks.query_benchmarks.query_select_related",
5656
"benchmarks.req_resp_benchmarks.default_middleware",
5757
"benchmarks.req_resp_benchmarks.http_methods",
58+
"benchmarks.test_utils_benchmarks.assertions",
5859
]
5960

6061
SECRET_KEY = "NOT REALLY SECRET"

benchmarks/test_utils_benchmarks.py/__init__.py

Whitespace-only changes.

benchmarks/test_utils_benchmarks.py/assertions/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from django.forms import CharField, Form
2+
from django.test import SimpleTestCase
3+
4+
from ...utils import bench_setup
5+
6+
7+
class DummyForm(Form):
8+
name = CharField()
9+
10+
11+
class Assertions:
12+
def setup(self):
13+
bench_setup()
14+
self.html = "<div><p>Hello <strong>World</strong></p></div>"
15+
self.response_content = "<html><body><h1>Welcome</h1><p>Test</p></body></html>"
16+
self.form = DummyForm(data={})
17+
self.test_case = SimpleTestCase()
18+
19+
def time_assertContains(self):
20+
self.test_case.assertContains(self.response_content, "Welcome")
21+
22+
def time_assertNotContains(self):
23+
self.test_case.assertNotContains(self.response_content, "Goodbye")
24+
25+
def time_assertFormError(self):
26+
self.form.is_valid()
27+
self.test_case.assertFormError(self.form, "name", "This field is required.")
28+
29+
def time_assertInHTML(self):
30+
self.test_case.assertInHTML("<p>Hello <strong>World</strong></p>", self.html)
31+
32+
def time_assertNotInHTML(self):
33+
self.test_case.assertNotInHTML("<strong>Django</strong>", self.html)

0 commit comments

Comments
 (0)