[Python-checkins] r65076 - in doctools/branches/0.4.x: sphinx/quickstart.py sphinx/util/console.py tests/test_quickstart.py tests/util.py
georg.brandl
python-checkins at python.org
Thu Jul 17 22:43:02 CEST 2008
Author: georg.brandl
Date: Thu Jul 17 22:43:01 2008
New Revision: 65076
Log:
Add a test for sphinx.quickstart.
Added:
doctools/branches/0.4.x/tests/test_quickstart.py (contents, props changed)
Modified:
doctools/branches/0.4.x/sphinx/quickstart.py
doctools/branches/0.4.x/sphinx/util/console.py
doctools/branches/0.4.x/tests/util.py
Modified: doctools/branches/0.4.x/sphinx/quickstart.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/quickstart.py (original)
+++ doctools/branches/0.4.x/sphinx/quickstart.py Thu Jul 17 22:43:01 2008
@@ -16,6 +16,8 @@
from sphinx.util.console import purple, bold, red, nocolor
+PROMPT_PREFIX = '> '
+
QUICKSTART_CONF = '''\
# -*- coding: utf-8 -*-
#
@@ -328,9 +330,9 @@
def do_prompt(d, key, text, default=None, validator=nonempty):
while True:
if default:
- prompt = purple('> %s [%s]: ' % (text, default))
+ prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
else:
- prompt = purple('> ' + text + ': ')
+ prompt = purple(PROMPT_PREFIX + text + ': ')
x = raw_input(prompt)
if default and not x:
x = default
@@ -359,7 +361,7 @@
You have two options for placing the build directory for Sphinx output.
Either, you use a directory ".build" within the root path, or you separate
"source" and "build" directories within the root path.'''
- do_prompt(d, 'sep', 'Separate source and build directories (y/n)', 'n',
+ do_prompt(d, 'sep', 'Separate source and build directories (y/N)', 'n',
boolean)
print '''
Inside the root directory, two more directories will be created; ".templates"
@@ -394,14 +396,14 @@
print '''
Please indicate if you want to use one of the following Sphinx extensions:'''
do_prompt(d, 'ext_autodoc', 'autodoc: automatically insert docstrings '
- 'from modules (y/n)', 'n', boolean)
+ 'from modules (y/N)', 'n', boolean)
do_prompt(d, 'ext_doctest', 'doctest: automatically test code snippets '
- 'in doctest blocks (y/n)', 'n', boolean)
+ 'in doctest blocks (y/N)', 'n', boolean)
print '''
If you are under Unix, a Makefile can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.'''
- do_prompt(d, 'makefile', 'Create Makefile? (y/n)',
+ do_prompt(d, 'makefile', 'Create Makefile? (Y/n)',
os.name == 'posix' and 'y' or 'n', boolean)
d['project_fn'] = make_filename(d['project'])
Modified: doctools/branches/0.4.x/sphinx/util/console.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/util/console.py (original)
+++ doctools/branches/0.4.x/sphinx/util/console.py Thu Jul 17 22:43:01 2008
@@ -38,6 +38,9 @@
def nocolor():
codes.clear()
+def coloron():
+ codes.update(_orig_codes)
+
def colorize(name, text):
return codes.get(name, '') + text + codes.get('reset', '')
@@ -73,5 +76,7 @@
codes[dark] = '\x1b[%im' % (i+30)
codes[light] = '\x1b[%i;01m' % (i+30)
+_orig_codes = codes.copy()
+
for _name in codes:
create_color_func(_name)
Added: doctools/branches/0.4.x/tests/test_quickstart.py
==============================================================================
--- (empty file)
+++ doctools/branches/0.4.x/tests/test_quickstart.py Thu Jul 17 22:43:01 2008
@@ -0,0 +1,144 @@
+# -*- coding: utf-8 -*-
+"""
+ test_quickstart
+ ~~~~~~~~~~~~~~~
+
+ Test the sphinx.quickstart module.
+
+ :copyright: 2008 by Georg Brandl.
+ :license: BSD.
+"""
+
+import sys
+import time
+import __builtin__
+
+from util import *
+
+from sphinx import quickstart as qs
+from sphinx.util.console import nocolor, coloron
+
+def setup_module():
+ nocolor()
+
+def mock_raw_input(answers, needanswer=False):
+ called = set()
+ def raw_input(prompt):
+ if prompt in called:
+ raise AssertionError('answer for %r missing and no default '
+ 'present' % prompt)
+ called.add(prompt)
+ for question in answers:
+ if prompt.startswith(qs.PROMPT_PREFIX + question):
+ return answers[question]
+ if needanswer:
+ raise AssertionError('answer for %r missing' % prompt)
+ return ''
+ return raw_input
+
+def teardown_module():
+ qs.raw_input = __builtin__.raw_input
+ coloron()
+
+
+def test_do_prompt():
+ d = {}
+ answers = {
+ 'Q2': 'v2',
+ 'Q3': 'v3',
+ 'Q4': 'yes',
+ 'Q5': 'no',
+ 'Q6': 'foo',
+ }
+ qs.raw_input = mock_raw_input(answers)
+ try:
+ qs.do_prompt(d, 'k1', 'Q1')
+ except AssertionError:
+ assert 'k1' not in d
+ else:
+ assert False, 'AssertionError not raised'
+ qs.do_prompt(d, 'k1', 'Q1', default='v1')
+ assert d['k1'] == 'v1'
+ qs.do_prompt(d, 'k3', 'Q3', default='v3_default')
+ assert d['k3'] == 'v3'
+ qs.do_prompt(d, 'k2', 'Q2')
+ assert d['k2'] == 'v2'
+ qs.do_prompt(d, 'k4', 'Q4', validator=qs.boolean)
+ assert d['k4'] == 'yes'
+ qs.do_prompt(d, 'k5', 'Q5', validator=qs.boolean)
+ assert d['k5'] == 'no'
+ raises(AssertionError, qs.do_prompt, d, 'k6', 'Q6', validator=qs.boolean)
+
+ at with_tempdir
+def test_quickstart_defaults(tempdir):
+ answers = {
+ 'Root path': tempdir,
+ 'Project name': 'Sphinx Test',
+ 'Author name': 'Georg Brandl',
+ 'Project version': '0.1',
+ }
+ qs.raw_input = mock_raw_input(answers)
+ qs.inner_main([])
+
+ conffile = tempdir / 'conf.py'
+ assert conffile.isfile()
+ ns = {}
+ execfile(conffile, ns)
+ assert ns['extensions'] == []
+ assert ns['templates_path'] == ['.templates']
+ assert ns['source_suffix'] == '.rst'
+ assert ns['master_doc'] == 'index'
+ assert ns['project'] == 'Sphinx Test'
+ assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
+ assert ns['version'] == '0.1'
+ assert ns['release'] == '0.1'
+ assert ns['html_static_path'] == ['.static']
+ assert ns['latex_documents'] == [
+ ('index', 'SphinxTest.tex', 'Sphinx Test Documentation',
+ 'Georg Brandl', 'manual')]
+
+ assert (tempdir / '.static').isdir()
+ assert (tempdir / '.templates').isdir()
+ assert (tempdir / 'index.rst').isfile()
+ assert (tempdir / 'Makefile').isfile()
+
+ at with_tempdir
+def test_quickstart_all_answers(tempdir):
+ answers = {
+ 'Root path': tempdir,
+ 'Separate source and build': 'y',
+ 'Name prefix for templates': '_',
+ 'Project name': 'Sphinx Test',
+ 'Author name': 'Georg Brandl',
+ 'Project version': '0.1',
+ 'Project release': '0.1.1',
+ 'Source file suffix': '.txt',
+ 'Name of your master document': 'contents',
+ 'autodoc': 'y',
+ 'doctest': 'yes',
+ 'Create Makefile': 'no',
+ }
+ qs.raw_input = mock_raw_input(answers, needanswer=True)
+ qs.inner_main([])
+
+ conffile = tempdir / 'source' / 'conf.py'
+ assert conffile.isfile()
+ ns = {}
+ execfile(conffile, ns)
+ assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
+ assert ns['templates_path'] == ['_templates']
+ assert ns['source_suffix'] == '.txt'
+ assert ns['master_doc'] == 'contents'
+ assert ns['project'] == 'Sphinx Test'
+ assert ns['copyright'] == '%s, Georg Brandl' % time.strftime('%Y')
+ assert ns['version'] == '0.1'
+ assert ns['release'] == '0.1.1'
+ assert ns['html_static_path'] == ['_static']
+ assert ns['latex_documents'] == [
+ ('contents', 'SphinxTest.tex', 'Sphinx Test Documentation',
+ 'Georg Brandl', 'manual')]
+
+ assert (tempdir / 'build').isdir()
+ assert (tempdir / 'source' / '_static').isdir()
+ assert (tempdir / 'source' / '_templates').isdir()
+ assert (tempdir / 'source' / 'contents.txt').isfile()
Modified: doctools/branches/0.4.x/tests/util.py
==============================================================================
--- doctools/branches/0.4.x/tests/util.py (original)
+++ doctools/branches/0.4.x/tests/util.py Thu Jul 17 22:43:01 2008
@@ -19,7 +19,7 @@
__all__ = [
'raises', 'raises_msg',
'ErrorOutput', 'TestApp',
- 'with_tempdir', 'write_file',
+ 'path', 'with_tempdir', 'write_file',
]
More information about the Python-checkins
mailing list