Skip to content

Commit

Permalink
Include examples in documentation, and add tests for that
Browse files Browse the repository at this point in the history
  • Loading branch information
steffann committed Jun 23, 2017
1 parent 07d2e65 commit 4be8e99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ZConfig/_schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
##############################################################################
from __future__ import print_function

from abc import abstractmethod
import argparse
import itertools
import sys
import textwrap
from abc import abstractmethod

try:
from itertools import ifilterfalse
Expand Down Expand Up @@ -279,6 +279,7 @@ def _visit_SectionInfo(self, name, info):
for sub in info.sectiontype:
self.visit(*sub)

self.fmt.example(info.example)

@TypeVisitor(AbstractType)
def _visit_AbstractType(self, name, info):
Expand Down
5 changes: 4 additions & 1 deletion ZConfig/tests/input/simplesections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<key name="var" required="yes" />
</sectiontype>

<multisection type="section" name="*" attribute="sections" />
<multisection type="section" name="*" attribute="sections">
<example>Multisection Example</example>
</multisection>
<section type="minimal" name="*" attribute="minimal" />
<section type="trivial" name="*" attribute="trivial" />
<section type="hasmin" name="+" attribute="hasmin" />
Expand Down Expand Up @@ -48,6 +50,7 @@
</sectiontype>
<section type="abstype" name="absinfo">
<description>Description</description>
<example>Section Example</example>
</section>
<section type="extabs" name="extabs" />
<section type="extabs" name="extabs2" />
Expand Down
18 changes: 15 additions & 3 deletions ZConfig/tests/test_schema2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import unittest

import docutils
import docutils.utils
import docutils.frontend
import docutils.parsers.rst
import docutils.parsers.rst.directives


import docutils.utils

try:
# Note that we're purposely using the old
Expand Down Expand Up @@ -100,6 +98,20 @@ def test_cover_all_schemas(self):
self.assertIn('</html>', res.getvalue())
run_transform_rst(input_file(name))

def test_html_section_example(self):
name = 'simplesections.xml'
res = run_transform(input_file(name))
out = res.getvalue()
self.assertIn('Section Example', out)
self.assertIn('Multisection Example', out)

def test_rst_section_example(self):
name = 'simplesections.xml'
res = run_transform_rst(input_file(name))
out = res.getvalue()
self.assertIn('Section Example', out)
self.assertIn('Multisection Example', out)

def test_cover_logging_components(self):
res = run_transform('--package', 'ZConfig.components.logger')
self.assertIn('eventlog', res.getvalue())
Expand Down

0 comments on commit 4be8e99

Please sign in to comment.