[Python-checkins] r61734 - in python/trunk/Doc: Makefile conf.py library/decimal.rst
georg.brandl
python-checkins at python.org
Sat Mar 22 11:56:24 CET 2008
Author: georg.brandl
Date: Sat Mar 22 11:56:23 2008
New Revision: 61734
Modified:
python/trunk/Doc/Makefile
python/trunk/Doc/conf.py
python/trunk/Doc/library/decimal.rst
Log:
Activate the Sphinx doctest extension and convert howto/functional to use it.
Modified: python/trunk/Doc/Makefile
==============================================================================
--- python/trunk/Doc/Makefile (original)
+++ python/trunk/Doc/Makefile Sat Mar 22 11:56:23 2008
@@ -82,6 +82,11 @@
coverage: build
@echo "Coverage finished; see c.txt and python.txt in build/coverage"
+doctest: BUILDER = doctest
+doctest: build
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in build/doctest/output.txt"
+
clean:
-rm -rf build/*
-rm -rf tools/sphinx
Modified: python/trunk/Doc/conf.py
==============================================================================
--- python/trunk/Doc/conf.py (original)
+++ python/trunk/Doc/conf.py Sat Mar 22 11:56:23 2008
@@ -13,7 +13,8 @@
# General configuration
# ---------------------
-extensions = ['sphinx.ext.refcounting', 'sphinx.ext.coverage']
+extensions = ['sphinx.ext.refcounting', 'sphinx.ext.coverage',
+ 'sphinx.ext.doctest']
templates_path = ['tools/sphinxext']
# General substitutions.
Modified: python/trunk/Doc/library/decimal.rst
==============================================================================
--- python/trunk/Doc/library/decimal.rst (original)
+++ python/trunk/Doc/library/decimal.rst Sat Mar 22 11:56:23 2008
@@ -15,9 +15,12 @@
.. sectionauthor:: Raymond D. Hettinger <python at rcn.com>
-
.. versionadded:: 2.4
+.. testsetup:: *
+
+ from decimal import *
+
The :mod:`decimal` module provides support for decimal floating point
arithmetic. It offers several advantages over the :class:`float` datatype:
@@ -47,7 +50,7 @@
* Unlike hardware based binary floating point, the decimal module has a user
alterable precision (defaulting to 28 places) which can be as large as needed for
- a given problem::
+ a given problem:
>>> getcontext().prec = 6
>>> Decimal(1) / Decimal(7)
@@ -115,7 +118,9 @@
The usual start to using decimals is importing the module, viewing the current
context with :func:`getcontext` and, if necessary, setting new values for
-precision, rounding, or enabled traps::
+precision, rounding, or enabled traps:
+
+.. doctest:: newcontext
>>> from decimal import *
>>> getcontext()
@@ -130,7 +135,7 @@
serves as an explicit reminder of the details of the conversion (including
representation error). Decimal numbers include special values such as
:const:`NaN` which stands for "Not a number", positive and negative
-:const:`Infinity`, and :const:`-0`. ::
+:const:`Infinity`, and :const:`-0`.
>>> Decimal(10)
Decimal('10')
@@ -149,7 +154,9 @@
The significance of a new Decimal is determined solely by the number of digits
input. Context precision and rounding only come into play during arithmetic
-operations. ::
+operations.
+
+.. doctest:: newcontext
>>> getcontext().prec = 6
>>> Decimal('3.0')
More information about the Python-checkins
mailing list