• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / grokcore.formlib / 16861221675

18 Jun 2025 06:33AM UTC coverage: 96.005%. Remained the same
16861221675

push

github

icemac
Back to development: 5.1

92 of 106 branches covered (86.79%)

Branch coverage included in aggregate %.

701 of 720 relevant lines covered (97.36%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/grokcore/formlib/tests/base/form/customautoform.py
1
"""
2
A form view can have a custom form_fields but reusing those fields that
3
were deduced automatically, using grok.AutoFields:
4

5
  >>> grok.testing.grok(__name__)
6

7
We only expect a single field to be present in the form, as we omitted 'size':
8

9
  >>> from zope import component
10
  >>> from zope.publisher.browser import TestRequest
11
  >>> request = TestRequest()
12
  >>> view = component.getMultiAdapter((Mammoth(), request), name='edit')
13
  >>> len(view.form_fields)
14
  1
15
  >>> [w.__name__ for w in view.form_fields]
16
  ['name']
17

18
  >>> view = component.getMultiAdapter((Mammoth2(), request), name='edit2')
19
  >>> len(view.form_fields)
20
  1
21
  >>> [w.__name__ for w in view.form_fields]
22
  ['size']
23

24
"""
25

26
from zope import schema
1✔
27
from zope.interface import Interface
1✔
28
from zope.interface import implementer
1✔
29

30
import grokcore.formlib as grok
1✔
31

32

33
class IMammoth(Interface):
1✔
34
    name = schema.TextLine(title="Name")
1✔
35
    size = schema.TextLine(title="Size", default="Quite normal")
1✔
36

37

38
@implementer(IMammoth)
1✔
39
class Mammoth(grok.Context):
1✔
40
    pass
1✔
41

42

43
class Edit(grok.EditForm):
1✔
44
    grok.context(Mammoth)
1✔
45

46
    form_fields = grok.AutoFields(Mammoth).omit('size')
1✔
47

48

49
class Mammoth2(grok.Context):
1✔
50

51
    class fields:
1✔
52
        name = schema.TextLine(title="Name")
1✔
53
        size = schema.TextLine(title="Size", default="Quite normal")
1✔
54

55

56
class Edit2(grok.EditForm):
1✔
57
    grok.context(Mammoth2)
1✔
58

59
    form_fields = grok.AutoFields(Mammoth).omit('name')
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc