-
-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathconftest.py
123 lines (85 loc) · 2.45 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import pytest
from wtforms.i18n import DummyTranslations
@pytest.fixture
def dummy_form():
return DummyForm()
@pytest.fixture
def dummy_field():
return DummyField()
@pytest.fixture
def dummy_field_class():
return DummyField
@pytest.fixture
def dummy_grouped_field_class():
return DummyGroupedField
@pytest.fixture
def basic_widget_dummy_field(dummy_field_class):
return dummy_field_class("foo", name="bar", label="label", id="id")
@pytest.fixture
def select_dummy_field(dummy_field_class):
return dummy_field_class([("foo", "lfoo", True, {}), ("bar", "lbar", False, {})])
@pytest.fixture
def select_dummy_grouped_field(dummy_grouped_field_class):
return dummy_grouped_field_class(
{
"g1": [("foo", "lfoo", True, {}), ("bar", "lbar", False, {})],
"g2": [("baz", "lbaz", False, {})],
None: [("abc", "labc", False, {})],
}
)
@pytest.fixture
def html5_dummy_field(dummy_field_class):
return dummy_field_class("42", name="bar", id="id")
@pytest.fixture
def really_lazy_proxy():
return ReallyLazyProxy()
class DummyField:
_translations = DummyTranslations()
def __init__(
self,
data=None,
name=None,
errors=(),
raw_data=None,
label=None,
id=None,
field_type="StringField",
):
self.data = data
self.name = name
self.errors = list(errors)
self.raw_data = raw_data
self.label = label
self.id = id if id else ""
self.type = field_type
def __call__(self, **other):
return self.data
def __str__(self):
return self.data
def __iter__(self):
return iter(self.data)
def _value(self):
return self.data
def iter_choices(self):
return iter(self.data)
def iter_groups(self):
return []
def has_groups(self):
return False
def gettext(self, string):
return self._translations.gettext(string)
def ngettext(self, singular, plural, n):
return self._translations.ngettext(singular, plural, n)
class DummyGroupedField(DummyField):
def iter_groups(self):
return self.data.items()
def has_groups(self):
return True
class DummyForm(dict):
pass
class ReallyLazyProxy:
def __str__(self):
raise Exception(
"Translator function called during form declaration: it"
" should be called at response time."
)