rearrangement of doc test

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3597 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-10-20 21:14:46 +00:00
parent ebd14c67af
commit 9caf7ab727

View file

@ -1,12 +1,16 @@
======================= ==================================
Dynamic Plug-in Modules Dynamically Loaded Plug-in Modules
======================= ==================================
($Id$) ($Id$)
>>> import os >>> import os
>>> basePath = os.path.join(os.path.dirname(__file__), 'testing') >>> basePath = os.path.join(os.path.dirname(__file__), 'testing')
Create, Modify, and Reload Plug-in Modules
==========================================
Let's first create a module with a function we'll call later. Let's first create a module with a function we'll call later.
>>> mod1Path = os.path.join(basePath, 'mod1.py') >>> mod1Path = os.path.join(basePath, 'mod1.py')
@ -21,9 +25,9 @@ Let's first create a module with a function we'll call later.
>>> f.write(src) >>> f.write(src)
>>> f.close() >>> f.close()
We could import this module now but in order to be able to automatically We could import this module now immediately but in order to be able to
reload it later (and be able to look it up in the plug-in module registry) automatically reload it later (and to be able to look it up in the plug-in
we use a loader module. module registry) we include it in a loader module.
>>> loadPath = os.path.join(basePath, 'load.py') >>> loadPath = os.path.join(basePath, 'load.py')
>>> src = ''' >>> src = '''
@ -46,15 +50,7 @@ the function in it.
>>> mod1.show() >>> mod1.show()
mod1.show() executed mod1.show() executed
We now append additional code to mod1 and see if it is reloaded automatically; We now append additional code to mod1 and see if it is reloaded automatically.
in order to create a sufficient time difference we change the stored setting.
We also have to remove the .pyc file, otherwise Python will refuse to
recompile the source file because the modification time is not changed
during the run of the test script.
>>> from cybertools.plugin.manage import modules
>>> modules['cybertools.plugin.testing.mod1'].timeStamp -= 2
>>> os.remove(os.path.join(basePath, 'mod1.pyc'))
>>> src = ''' print 'now changed...' >>> src = ''' print 'now changed...'
... ...
@ -63,11 +59,20 @@ during the run of the test script.
>>> f.write(src) >>> f.write(src)
>>> f.close() >>> f.close()
(In order to create a sufficient time difference during testing we patch the
stored setting. We also have to remove the .pyc file, otherwise Python will
refuse to recompile the source file because the modification time is not changed
significantly during the run of the test script.)
>>> from cybertools.plugin.manage import modules
>>> modules['cybertools.plugin.testing.mod1'].timeStamp -= 2
>>> os.remove(os.path.join(basePath, 'mod1.pyc'))
>>> mod1.show() >>> mod1.show()
mod1.show() executed mod1.show() executed
now changed... now changed...
We now append another function to the source file. Let's append another function to the source file.
>>> src = ''' >>> src = '''
... @register() ... @register()
@ -82,7 +87,7 @@ We now append another function to the source file.
>>> modules['cybertools.plugin.testing.mod1'].timeStamp -= 2 >>> modules['cybertools.plugin.testing.mod1'].timeStamp -= 2
>>> os.remove(os.path.join(basePath, 'mod1.pyc')) >>> os.remove(os.path.join(basePath, 'mod1.pyc'))
When we now try to call the new function, the module will not be reloaded When we try to call the new function, the module will not be reloaded
automatically. automatically.
>>> mod1.another() >>> mod1.another()
@ -97,6 +102,7 @@ But just reloading the load module will also update the mod1 application module.
>>> mod1.another() >>> mod1.another()
executing another function. executing another function.
Fin de partie Fin de partie
============= =============