[Checkins] SVN: manuelpi.fake_module/trunk/src/manuelpi/fake_module/ Expanded the tests to include invalid module definitions
Paul Wilson
paulalexwilson at gmail.com
Mon Nov 23 06:17:04 EST 2009
Log message for revision 105959:
Expanded the tests to include invalid module definitions
Changed:
U manuelpi.fake_module/trunk/src/manuelpi/fake_module/README.txt
U manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.py
U manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.txt
-=-
Modified: manuelpi.fake_module/trunk/src/manuelpi/fake_module/README.txt
===================================================================
--- manuelpi.fake_module/trunk/src/manuelpi/fake_module/README.txt 2009-11-23 09:21:37 UTC (rev 105958)
+++ manuelpi.fake_module/trunk/src/manuelpi/fake_module/README.txt 2009-11-23 11:17:04 UTC (rev 105959)
@@ -3,12 +3,12 @@
`manuelpi.fake_module` is a plugin for `Manuel`_ that supports syntax
for creating modules within a doctest. The module, once defined, is then
-usable by supporting doctest statements.
+usable by subsequent doctest statements.
This functionality is useful for packages that you might describe as
being 'meta'; they operate on modules. Thus, being able to define
and then process modules within the same doctest using a clean and
-uncluttered syntax delivers is extremely beneficial.
+uncluttered syntax is extremely beneficial.
One such package to benefit from this sort of facility is `Martian`_,
which scans modules for configuration directives, registering them as
@@ -19,6 +19,7 @@
Usage
=====
+
The special REStructure Text directive::
'.. module-block:: <MODULE_NAME>'
@@ -28,7 +29,7 @@
indentation level after this directive. What follows is an example of a
full doctest::
-We create a new module with a main function to perform this task::
+ We create a new module with a main function to perform this task::
.. module-block:: test_module
@@ -52,7 +53,7 @@
The above doctest creates a new module `test_module` and then exercises
the objects within it. Notice how the module becomes immediately available
-to the doctet after definition.
+to the doctet after its definition.
To use `manualpi.fake_module` in your application, set up your tests as
described in the Manuel documentation and import the `Manuel` class from
Modified: manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.py
===================================================================
--- manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.py 2009-11-23 09:21:37 UTC (rev 105958)
+++ manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.py 2009-11-23 11:17:04 UTC (rev 105959)
@@ -5,7 +5,7 @@
import textwrap
FAKE_MODULE_START = re.compile(
- r'^\.\.\s*module-block::?\s*(?P<module_name>[a-zA-Z_]*)',
+ r'^\.\.\s*module-block::?\s*(?P<module_name>[a-zA-Z_]+)',
re.MULTILINE)
FAKE_MODULE_END = re.compile(r'(\n\Z|\n(?=\S))')
MODULE_NS = "manueltest.fake"
Modified: manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.txt
===================================================================
--- manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.txt 2009-11-23 09:21:37 UTC (rev 105958)
+++ manuelpi.fake_module/trunk/src/manuelpi/fake_module/fake_module.txt 2009-11-23 11:17:04 UTC (rev 105959)
@@ -4,7 +4,7 @@
The `fake_module` plugin defines a `module-block` directive that takes
a single Python identifier as an argument. One or more lines of Python
code indented will then form the body of the module, which is later
-referenced by its identifier::
+referenced by its identifier:
>>> import manuel
>>> import manuelpi.fake_module
@@ -24,16 +24,15 @@
a = 1 + 2
- As you can see, it does much!!
+ As you can see, it does nothing much!!
.. -> source
-
::
>>> doc = manuel.Document(source)
>>> from manuelpi.fake_module.fake_module import find_fakes
>>> find_fakes(doc)
-Let's extract the module name and its source::
+Let's extract the module name and its source:
>>> for region in doc:
... if region.parsed:
@@ -164,3 +163,30 @@
>>> print glob['cls_n_func'].faz_func.__module__
manueltest.fake.cls_n_func
+
+Invalid Modules
+===============
+
+The module name must be a valid Python identifier. If, say, it
+begins with a number, the module block will not be matched as a
+module definition and will be simply ignored as a comment::
+
+ What follows is an invalid module definition...
+
+ .. module-block:: 123invalid_module_name
+ def foo(): pass
+
+ It is not legal to precede Python identifiers with numbers.
+
+.. -> source
+
+We can confirm this be checking if there is any instance of
+`FakeModuleSnippet` in the document's parsed regions:
+
+ >>> doc = manuel.Document(source)
+ >>> find_fakes(doc)
+ >>> from manuelpi.fake_module.fake_module import FakeModuleSnippet
+ >>> any([isinstance(x.parsed, FakeModuleSnippet) for x in doc])
+ False
+
+There are none - therefore the module definition has been ignored.
More information about the checkins
mailing list