Skip to content

Commit

Permalink
Add ability to specify which component file to read to RST directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Feb 24, 2017
1 parent db93bb0 commit 53d5309
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ZConfig/_schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def load_schema(schema, package, package_file):
schema_reader = argparse.FileType('r')(schema)
else:
schema_template = "<schema><import package='%s' file='%s' /></schema>" % (
schema, package_file)
schema, package_file or 'component.xml')
from ZConfig._compat import TextIO
schema_reader = TextIO(schema_template)

Expand Down
8 changes: 6 additions & 2 deletions ZConfig/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ def printSchema(self):

class SchemaToRstDirective(Directive):
required_arguments = 1

optional_arguments = 1
option_spec = {
'file': str,
}
def run(self):
schema = load_schema(self.arguments[0], True, 'component.xml')
schema = load_schema(self.arguments[0],
True, self.options.get('file'))

printer = RstSchemaPrinter(schema)
printer.fmt.settings = self.state.document.settings
Expand Down
29 changes: 24 additions & 5 deletions ZConfig/tests/test_schema2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,44 @@ def test_cover_logging_components(self):

class TestRst(unittest.TestCase):

def test_parse_package(self):
def _parse(self, text):
document = docutils.utils.new_document(
"Schema",
settings=docutils.frontend.OptionParser(
components=(docutils.parsers.rst.Parser,)
).get_default_values())

parser = docutils.parsers.rst.Parser()
text = textwrap.dedent(text)
parser.parse(text, document)
return document

def test_parse_package(self):
text = """
Document
========
.. zconfig:: ZConfig.components.logger
"""
text = textwrap.dedent(text)
parser.parse(text, document)
astext = document.astext()
document = self._parse(text)
doc_text = document.astext()
# Check that it produced output
self.assertIn("SMTPHandler", astext)
self.assertIn("SMTPHandler", doc_text)

def test_parse_package_file(self):
text = """
Document
========
.. zconfig:: ZConfig.components.logger
:file: base-logger.xml
"""
document = self._parse(text)
doc_text = document.astext()
# Check that it produced output, limited to
# just that one file.
self.assertNotIn("SMTPHandler", doc_text)
self.assertIn("base-logger", doc_text)


def test_suite():
Expand Down
1 change: 1 addition & 0 deletions doc/using-zconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,4 @@ Configuring Logging
===================

.. zconfig:: ZConfig.components.logger
:file: component.xml

0 comments on commit 53d5309

Please sign in to comment.