[Checkins] SVN: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/ Renaming references to old name 'fake_module' to 'fakemodule'

Paul Wilson paulalexwilson at gmail.com
Thu Dec 10 05:57:24 EST 2009


Log message for revision 106372:
  Renaming references to old name 'fake_module' to 'fakemodule'

Changed:
  U   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/README.txt
  U   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/__init__.py
  D   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.py
  D   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.txt
  A   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.py
  A   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.txt
  U   manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/tests.py

-=-
Modified: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/README.txt
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/README.txt	2009-12-10 10:54:12 UTC (rev 106371)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/README.txt	2009-12-10 10:57:24 UTC (rev 106372)
@@ -1,7 +1,7 @@
 Intro and Motivation
 ====================
 
-`manuelpi.fake_module` is a plugin for `Manuel`_ that supports syntax 
+`manuelpi.fakemodule` is a plugin for `Manuel`_ that supports syntax 
 for creating modules within a doctest. The module, once defined, is then
 usable by subsequent doctest statements.
 
@@ -55,11 +55,11 @@
 the objects within it. Notice how the module becomes immediately available
 to the doctet after its definition. 
 
-To use `manualpi.fake_module` in your application, set up your tests as
+To use `manualpi.fakemodule` in your application, set up your tests as
 described in the Manuel documentation and import the `Manuel` class from
-`manuelpi.fake_module`::
+`manuelpi.fakemodule`::
 
   ...
-  import manuelpi.fake_module
+  import manuelpi.fakemodule
   ...
-  m += manuelpi.fake_module.Manuel()
+  m += manuelpi.fakemodule.Manuel()

Modified: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/__init__.py
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/__init__.py	2009-12-10 10:54:12 UTC (rev 106371)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/__init__.py	2009-12-10 10:57:24 UTC (rev 106372)
@@ -1 +1 @@
-from manuelpi.fake_module.fake_module import Manuel
+from manuelpi.fakemodule.fakemodule import Manuel

Deleted: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.py
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.py	2009-12-10 10:54:12 UTC (rev 106371)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.py	2009-12-10 10:57:24 UTC (rev 106372)
@@ -1,62 +0,0 @@
-import manuel
-import re
-import sys
-import new
-import textwrap
-
-FAKE_MODULE_START = re.compile(
-        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"
-
-# To store our fake module's lines
-class FakeModuleSnippet(object):
-    def __init__(self, code, module_name):
-        self.code = code
-        self.module_name = module_name
-
-def find_fakes(document):
-    for region in document.find_regions(FAKE_MODULE_START, FAKE_MODULE_END):
-        if region.parsed:
-            continue
-
-        module_name = region.start_match.group('module_name')
-        # Sanitise indentation
-        source = textwrap.dedent('\n'.join(region.source.splitlines()[1:]))
-        source_location = '%s:%d' % (document.location, region.lineno)
-
-        code = compile(source, source_location, 'exec')
-        document.claim_region(region)
-        region.parsed = FakeModuleSnippet(code, module_name)
-
-def execute_into_module(region, document, doc_globs):
-    if not isinstance(region.parsed, FakeModuleSnippet):
-        return
-
-    # build a suitable module
-    module_name = region.parsed.module_name
-    full_module_name = MODULE_NS + "." + module_name
-    module = new.module(full_module_name)
-    module_name_parts = full_module_name.split('.')
-    module.__file__ = '/' + '/'.join(module_name_parts)
-
-    # Make the module also available through normal import
-    if not MODULE_NS in sys.modules:
-        sys.modules['manueltest'] = new.module('manueltest')
-        sys.modules['manueltest.fake'] = new.module('manueltest.fake')
-        sys.modules['manueltest'].fake = sys.modules['manueltest.fake']
-
-    exec region.parsed.code in module.__dict__
-    # XXX Do I want del module['__builtin__']??
-
-    # Make the module visible and usable in the given name
-    doc_globs[module_name] =  module
-
-    sys.modules[full_module_name] = module
-    setattr(sys.modules['manueltest.fake'], full_module_name.split('.')[-1],
-            module)
-
-class Manuel(manuel.Manuel):
-    def __init__(self):
-        manuel.Manuel.__init__(self, [find_fakes], [execute_into_module])

Deleted: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.txt
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.txt	2009-12-10 10:54:12 UTC (rev 106371)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.txt	2009-12-10 10:57:24 UTC (rev 106372)
@@ -1,192 +0,0 @@
-Details
-=======
-
-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:
-
-   >>> import manuel
-   >>> import manuelpi.fake_module
-
-The following string shows what this might look like::
-
-   This is a module doc-test:
-   
-   .. module-block:: test_module
-
-         import pprint
-         
-         class Something:
-            pass
-         
-         def my_function(): pass
-         
-         a = 1 + 2
-   
-   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:
-
-   >>> for region in doc:
-   ...    if region.parsed:
-   ...       print region.parsed.module_name
-   ...       print region.source
-   test_module
-   .. module-block:: test_module
-        import pprint
-   <BLANKLINE>
-        class Something:
-           pass
-   <BLANKLINE>
-        def my_function(): pass
-   <BLANKLINE>
-        a = 1 + 2
-   <BLANKLINE>
-   <BLANKLINE>
-
-The code can correctly parse multiple modules:
-
-   Our system has a few modules:
-  
-   .. module-block:: some_module
-        class Foo:
-           pass
-  
-   and:
-   
-   .. module-block:: an_other_module
-        class Bar:
-            pass
-   
-   fin
-
-.. -> source
-
-   >>> doc = manuel.Document(source)
-   >>> find_fakes(doc)
-   
-Again, we extract the various parsed regions:
-
-   >>> for region in doc:
-   ...     if region.parsed:
-   ...         print region.parsed.module_name
-   ...         print region.source
-   some_module
-   .. module-block:: some_module
-        class Foo:
-           pass
-   <BLANKLINE>
-   <BLANKLINE>
-   an_other_module
-   .. module-block:: an_other_module
-        class Bar:
-            pass
-   <BLANKLINE>
-   <BLANKLINE>
-
-We can use `execute_into_module` to execute these regions into a 
-glob dictionary of our own:
-
-  >>> from manuelpi.fake_module.fake_module import execute_into_module
-  >>> glob = {}
-  >>> for region in doc:
-  ...     if region.parsed:
-  ...         execute_into_module(region, doc, glob)
-
-Let's check that our glob contains the modules with their names:
-
-  >>> for module in glob.values(): 
-  ...     print module.__name__, ":", type(module)
-  manueltest.fake.some_module : <type 'module'>
-  manueltest.fake.an_other_module : <type 'module'>
-
-and also confirm that the modules contain their respective class
-definitions:
-
-  >>> for module in glob.values():
-  ...     print dir(module)
-  ['Foo', '__builtins__', '__doc__', '__file__', '__name__']
-  ['Bar', '__builtins__', '__doc__', '__file__', '__name__']
-
-We would also want to ensure that we can import the module correctly 
-too. The fake_module system also adds the modules under their own 
-namespace `manueltest.fake`, as you can see from the previous tests:
-
-  >>> import manueltest.fake.some_module
-  >>> import manueltest.fake.an_other_module
-  >>> manueltest.fake.some_module.Foo
-  <class manueltest.fake.some_module.Foo at ...>
-  >>> manueltest.fake.an_other_module.Bar
-  <class manueltest.fake.an_other_module.Bar at ...>
-
-Note: There is no checking done to ensure that the module definition
-hasn't overridden any previous modules defined in the doctest. 
-
-Now that we can see objects in our modules, we need to ensure that
-they are fully 'module-aware'. In other words, are they aware that
-they are existing in a module? Let's create a new module with
-classes and functions to test this:
-
-  .. module-block:: cls_n_func
-       class Baz:
-         def __init__(self):
-             pass
-
-       def faz_func(): pass
-
-.. -> source
-
-We will now go through the usual steps to create the module in our
-own glob:
-
-  >>> doc = manuel.Document(source)
-  >>> find_fakes(doc)
-  >>> glob = {}
-  >>> for region in doc:
-  ...    if region.parsed:
-  ...        execute_into_module(region, doc, glob)
-
-The class must be aware that it exists within the `manuelfake.test.
-cls_n_func` module:
-
-  >>> print glob['cls_n_func'].Baz.__module__
-  manueltest.fake.cls_n_func
-
-In addition, functions must also be aware of their module:
-
-  >>> 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.

Copied: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.py (from rev 106371, manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.py)
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.py	                        (rev 0)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.py	2009-12-10 10:57:24 UTC (rev 106372)
@@ -0,0 +1,62 @@
+import manuel
+import re
+import sys
+import new
+import textwrap
+
+FAKE_MODULE_START = re.compile(
+        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"
+
+# To store our fake module's lines
+class FakeModuleSnippet(object):
+    def __init__(self, code, module_name):
+        self.code = code
+        self.module_name = module_name
+
+def find_fakes(document):
+    for region in document.find_regions(FAKE_MODULE_START, FAKE_MODULE_END):
+        if region.parsed:
+            continue
+
+        module_name = region.start_match.group('module_name')
+        # Sanitise indentation
+        source = textwrap.dedent('\n'.join(region.source.splitlines()[1:]))
+        source_location = '%s:%d' % (document.location, region.lineno)
+
+        code = compile(source, source_location, 'exec')
+        document.claim_region(region)
+        region.parsed = FakeModuleSnippet(code, module_name)
+
+def execute_into_module(region, document, doc_globs):
+    if not isinstance(region.parsed, FakeModuleSnippet):
+        return
+
+    # build a suitable module
+    module_name = region.parsed.module_name
+    full_module_name = MODULE_NS + "." + module_name
+    module = new.module(full_module_name)
+    module_name_parts = full_module_name.split('.')
+    module.__file__ = '/' + '/'.join(module_name_parts)
+
+    # Make the module also available through normal import
+    if not MODULE_NS in sys.modules:
+        sys.modules['manueltest'] = new.module('manueltest')
+        sys.modules['manueltest.fake'] = new.module('manueltest.fake')
+        sys.modules['manueltest'].fake = sys.modules['manueltest.fake']
+
+    exec region.parsed.code in module.__dict__
+    # XXX Do I want del module['__builtin__']??
+
+    # Make the module visible and usable in the given name
+    doc_globs[module_name] =  module
+
+    sys.modules[full_module_name] = module
+    setattr(sys.modules['manueltest.fake'], full_module_name.split('.')[-1],
+            module)
+
+class Manuel(manuel.Manuel):
+    def __init__(self):
+        manuel.Manuel.__init__(self, [find_fakes], [execute_into_module])

Copied: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.txt (from rev 106371, manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fake_module.txt)
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.txt	                        (rev 0)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/fakemodule.txt	2009-12-10 10:57:24 UTC (rev 106372)
@@ -0,0 +1,192 @@
+Details
+=======
+
+The `fakemodule` 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:
+
+   >>> import manuel
+   >>> import manuelpi.fakemodule
+
+The following string shows what this might look like::
+
+   This is a module doc-test:
+   
+   .. module-block:: test_module
+
+         import pprint
+         
+         class Something:
+            pass
+         
+         def my_function(): pass
+         
+         a = 1 + 2
+   
+   As you can see, it does nothing much!!
+
+.. -> source
+::
+   >>> doc = manuel.Document(source)
+   >>> from manuelpi.fakemodule.fakemodule import find_fakes
+   >>> find_fakes(doc)
+
+Let's extract the module name and its source:
+
+   >>> for region in doc:
+   ...    if region.parsed:
+   ...       print region.parsed.module_name
+   ...       print region.source
+   test_module
+   .. module-block:: test_module
+        import pprint
+   <BLANKLINE>
+        class Something:
+           pass
+   <BLANKLINE>
+        def my_function(): pass
+   <BLANKLINE>
+        a = 1 + 2
+   <BLANKLINE>
+   <BLANKLINE>
+
+The code can correctly parse multiple modules:
+
+   Our system has a few modules:
+  
+   .. module-block:: some_module
+        class Foo:
+           pass
+  
+   and:
+   
+   .. module-block:: an_other_module
+        class Bar:
+            pass
+   
+   fin
+
+.. -> source
+
+   >>> doc = manuel.Document(source)
+   >>> find_fakes(doc)
+   
+Again, we extract the various parsed regions:
+
+   >>> for region in doc:
+   ...     if region.parsed:
+   ...         print region.parsed.module_name
+   ...         print region.source
+   some_module
+   .. module-block:: some_module
+        class Foo:
+           pass
+   <BLANKLINE>
+   <BLANKLINE>
+   an_other_module
+   .. module-block:: an_other_module
+        class Bar:
+            pass
+   <BLANKLINE>
+   <BLANKLINE>
+
+We can use `execute_into_module` to execute these regions into a 
+glob dictionary of our own:
+
+  >>> from manuelpi.fakemodule.fakemodule import execute_into_module
+  >>> glob = {}
+  >>> for region in doc:
+  ...     if region.parsed:
+  ...         execute_into_module(region, doc, glob)
+
+Let's check that our glob contains the modules with their names:
+
+  >>> for module in glob.values(): 
+  ...     print module.__name__, ":", type(module)
+  manueltest.fake.some_module : <type 'module'>
+  manueltest.fake.an_other_module : <type 'module'>
+
+and also confirm that the modules contain their respective class
+definitions:
+
+  >>> for module in glob.values():
+  ...     print dir(module)
+  ['Foo', '__builtins__', '__doc__', '__file__', '__name__']
+  ['Bar', '__builtins__', '__doc__', '__file__', '__name__']
+
+We would also want to ensure that we can import the module correctly 
+too. The `fakemodule` system also adds the modules under their own 
+namespace `manueltest.fake`, as you can see from the previous tests:
+
+  >>> import manueltest.fake.some_module
+  >>> import manueltest.fake.an_other_module
+  >>> manueltest.fake.some_module.Foo
+  <class manueltest.fake.some_module.Foo at ...>
+  >>> manueltest.fake.an_other_module.Bar
+  <class manueltest.fake.an_other_module.Bar at ...>
+
+Note: There is no checking done to ensure that the module definition
+hasn't overridden any previous modules defined in the doctest. 
+
+Now that we can see objects in our modules, we need to ensure that
+they are fully 'module-aware'. In other words, are they aware that
+they are existing in a module? Let's create a new module with
+classes and functions to test this:
+
+  .. module-block:: cls_n_func
+       class Baz:
+         def __init__(self):
+             pass
+
+       def faz_func(): pass
+
+.. -> source
+
+We will now go through the usual steps to create the module in our
+own glob:
+
+  >>> doc = manuel.Document(source)
+  >>> find_fakes(doc)
+  >>> glob = {}
+  >>> for region in doc:
+  ...    if region.parsed:
+  ...        execute_into_module(region, doc, glob)
+
+The class must be aware that it exists within the `manuelfake.test.
+cls_n_func` module:
+
+  >>> print glob['cls_n_func'].Baz.__module__
+  manueltest.fake.cls_n_func
+
+In addition, functions must also be aware of their module:
+
+  >>> 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.fakemodule.fakemodule import FakeModuleSnippet
+  >>> any([isinstance(x.parsed, FakeModuleSnippet) for x in doc])
+  False
+
+There are none - therefore the module definition has been ignored.

Modified: manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/tests.py
===================================================================
--- manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/tests.py	2009-12-10 10:54:12 UTC (rev 106371)
+++ manuelpi.fakemodule/trunk/src/manuelpi/fakemodule/tests.py	2009-12-10 10:57:24 UTC (rev 106372)
@@ -2,7 +2,7 @@
 import manuel.doctest
 import manuel.ignore
 import manuel.capture
-import manuelpi.fake_module
+import manuelpi.fakemodule
 import re
 import unittest
 
@@ -15,12 +15,12 @@
         (re.compile(r'<zope\.testing\.doctest\.'), '<doctest.'),
         ])
 
-    tests = ['README.txt', 'fake_module.txt']
+    tests = ['README.txt', 'fakemodule.txt']
 
     m = manuel.ignore.Manuel()
     m += manuel.doctest.Manuel(optionflags=optionflags, checker=checker)
     m += manuel.capture.Manuel()
-    m += manuelpi.fake_module.Manuel()
+    m += manuelpi.fakemodule.Manuel()
     return manuel.testing.TestSuite(m, *tests)
 
 if __name__ == '__main__':



More information about the checkins mailing list