Skip to content

Commit da1f18a

Browse files
authoredJun 1, 2022
Form validation benchmark added (django#6)
1 parent b3cd06f commit da1f18a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
 

‎benchmarks/form_benchmarks/__init__.py

Whitespace-only changes.

‎benchmarks/form_benchmarks/form_validate/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django import forms
2+
from django.core.exceptions import ValidationError
3+
4+
from ...utils import bench_setup
5+
6+
7+
def form_validator(title):
8+
if title != "hi":
9+
raise ValidationError("title is not hi")
10+
11+
12+
class BookForm(forms.Form):
13+
title = forms.CharField(max_length=100, validators=[form_validator])
14+
15+
16+
class FormValidate:
17+
def setup(self):
18+
bench_setup()
19+
self.form = BookForm({"title": "hi"})
20+
self.invalid_form = BookForm({"title": "abc"})
21+
22+
def time_form_validate(self):
23+
self.form.is_valid()
24+
25+
def time_form_invalid(self):
26+
self.invalid_form.is_valid()

0 commit comments

Comments
 (0)
Please sign in to comment.