[Checkins] SVN: zc.recipe.deployment/branches/jspaans-fix-to-match-docs/src/zc/recipe/deployment/README.txt Fix completely bogus tests (whoever approved those should actually try to run them next time...):

Jasper Spaans jspaans at thehealthagency.com
Tue Dec 23 10:53:50 EST 2008


Log message for revision 94286:
  Fix completely bogus tests (whoever approved those should actually try to run them next time...):
    - fix usage of usernames in tests
    - fix calling of 'join' where os.path.join was meant
    - fix doing stuff in /etc and /var by putting it in a tmpdir
    - allow the tests to be run by a normal user
    - allow the tests to be run on a system without a user named 'jim'
    - allow the tests to be run when the time is not 2007-02-06 09:50 (!)
    - sprinkle the test with NORMALIZE_WHITESPACE where appropriate
    - actually check run these tests
  

Changed:
  U   zc.recipe.deployment/branches/jspaans-fix-to-match-docs/src/zc/recipe/deployment/README.txt

-=-
Modified: zc.recipe.deployment/branches/jspaans-fix-to-match-docs/src/zc/recipe/deployment/README.txt
===================================================================
--- zc.recipe.deployment/branches/jspaans-fix-to-match-docs/src/zc/recipe/deployment/README.txt	2008-12-23 14:31:25 UTC (rev 94285)
+++ zc.recipe.deployment/branches/jspaans-fix-to-match-docs/src/zc/recipe/deployment/README.txt	2008-12-23 15:53:50 UTC (rev 94286)
@@ -3,6 +3,15 @@
 
 Let's add a deployment to a sample buildout:
 
+    >>> import os, pwd, tempfile
+    >>> runninguser = pwd.getpwuid(os.getuid())[0]
+    >>> tdir = tempfile.mkdtemp()
+    >>> os.mkdir(os.path.join(tdir, 'etc'))
+    >>> os.mkdir(os.path.join(tdir, 'log'))
+    >>> os.mkdir(os.path.join(tdir, 'run'))
+
+    >>> fixup = lambda x: x.replace(runninguser, 'jim').replace(tdir, '_tdir_')
+
     >>> write('buildout.cfg',
     ... '''
     ... [buildout]
@@ -10,71 +19,71 @@
     ...
     ... [foo]
     ... recipe = zc.recipe.deployment
-    ... user = jim
-    ... ''')
+    ... name = foo
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(join('bin', 'buildout'))), # doctest: +NORMALIZE_WHITESPACE
     Installing foo.
-    zc.recipe.deployment: 
-        Creating '/etc/foo',
-        mode 755, user 'root', group 'root'
-    zc.recipe.deployment: 
-        Creating '/var/log/foo',
+    zc.recipe.deployment:
+        Creating '_tdir_/etc/foo',
         mode 755, user 'jim', group 'jim'
-    zc.recipe.deployment: 
-        Creating '/var/run/foo',
+    zc.recipe.deployment:
+        Creating '_tdir_/log/foo',
+        mode 755, user 'jim', group 'jim'
+    zc.recipe.deployment:
+        Creating '_tdir_/run/foo',
         mode 750, user 'jim', group 'jim'
 
-
-(Note that we have to be running as root and must have a user jim for
-this to work.)
-
 Now we can see that directories named foo in /etc, /var/log and
 /var/run have been created:
 
-    >>> print system('ls -ld /etc/foo'), 
-    drwxr-xr-x 2 root root 4096 2007-02-06 09:50 /etc/foo
+    >>> print fixup(system('ls -ld %s/etc/foo' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-xr-x ... _tdir_/etc/foo
 
-    >>> print system('ls -ld /var/log/foo'), 
-    drwxr-xr-x 2 jim jim 4096 2007-02-06 09:50 /var/log/foo
+    >>> print fixup(system('ls -ld %s/log/foo' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-xr-x ... _tdir_/log/foo
 
-    >>> print system('ls -ld /var/run/foo'), 
-    drwxr-x--- 2 jim jim 40 2007-02-06 09:50 /var/run/foo
-    
+    >>> print fixup(system('ls -ld %s/run/foo' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-x--- ... _tdir_/run/foo
+
 By looking at .installed.cfg, we can see the options available for use
 by other recipes:
 
-    >>> cat('.installed.cfg') # doctest: +ELLIPSIS
+    >>> print fixup(file('.installed.cfg').read()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
     [buildout]
     ...
     [foo]
-    __buildout_installed__ = 
+    __buildout_installed__ =
     ...
     crontab-directory = /etc/cron.d
-    etc-directory = /etc/foo
-    log-directory = /var/log/foo
+    etc-directory = _tdir_/etc/foo
+    log-directory = _tdir_/log/foo
     logrotate-directory = /etc/logrotate.d
     name = foo
     rc-directory = /etc/init.d
     recipe = zc.recipe.deployment
-    run-directory = /var/run/foo
+    run-directory = _tdir_/run/foo
     user = jim
 
 If we ininstall, then the directories are removed.
 
-    >>> print system(join('bin', 'buildout')+' buildout:parts='),
+    >>> print fixup(system(os.path.join('bin', 'buildout')+' buildout:parts=')),
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/foo'
-    zc.recipe.deployment: Removing '/var/log/foo'.
-    zc.recipe.deployment: Removing '/var/run/foo'.
+    zc.recipe.deployment: Removing '_tdir_/etc/foo'
+    zc.recipe.deployment: Removing '_tdir_/log/foo'.
+    zc.recipe.deployment: Removing '_tdir_/run/foo'.
 
     >>> import os
-    >>> os.path.exists('/etc/foo')
+    >>> os.path.exists(os.path.join(tdir, '/etc/foo'))
     False
-    >>> os.path.exists('/var/log/foo')
+    >>> os.path.exists(os.path.join(tdir, '/log/foo'))
     False
-    >>> os.path.exists('/var/run/foo')
+    >>> os.path.exists(os.path.join(tdir, '/run/foo'))
     False
 
 The log and run directories are only removed if they are empty.
@@ -84,27 +93,27 @@
     Installing foo.
     ...
 
-    >>> write('/etc/foo/x', '')
-    >>> write('/var/log/foo/x', '')
-    >>> write('/var/run/foo/x', '')
+    >>> write(os.path.join(tdir, 'etc/foo/x'), '')
+    >>> write(os.path.join(tdir, 'log/foo/x'), '')
+    >>> write(os.path.join(tdir, 'run/foo/x'), '')
 
 And then uninstall:
 
-    >>> print system(join('bin', 'buildout')+' buildout:parts='),
+    >>> print fixup(system(join('bin', 'buildout')+' buildout:parts=')),
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/foo'
-    zc.recipe.deployment: Can't remove non-empty directory '/var/log/foo'.
-    zc.recipe.deployment: Can't remove non-empty directory '/var/run/foo'.
+    zc.recipe.deployment: Removing '_tdir_/etc/foo'
+    zc.recipe.deployment: Can't remove non-empty directory '_tdir_/log/foo'.
+    zc.recipe.deployment: Can't remove non-empty directory '_tdir_/run/foo'.
 
-    >>> os.path.exists('/etc/foo')
+    >>> os.path.exists(os.path.join(tdir, '/etc/foo'))
     False
 
-    >>> print system('ls -ld /var/log/foo'), 
-    drwxr-xr-x 2 jim jim 4096 2007-02-06 09:50 /var/log/foo
+    >>> print fixup(system('ls -ld %s' % (os.path.join(tdir, 'log/foo')))),  # doctest: +ELLIPSIS
+    drwxr-xr-x ... _tdir_/log/foo
 
-    >>> print system('ls -ld /var/run/foo'), 
-    drwxr-x--- 2 jim jim 40 2007-02-06 09:50 /var/run/foo
+    >>> print fixup(system('ls -ld %s' % (os.path.join(tdir, 'run/foo')))),  # doctest: +ELLIPSIS
+    drwxr-x--- ... _tdir_/run/foo
 
 Here we see that the var and run directories are kept. The etc
 directory is discarded because only buildout recipes should write to
@@ -113,33 +122,33 @@
 If we reinstall, remove the files, and uninstall, then the directories
 are removed:
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(os.path.join('bin', 'buildout'))), # doctest: +NORMALIZE_WHITESPACE
     Installing foo.
-    zc.recipe.deployment: 
-        Creating '/etc/foo',
-        mode 755, user 'root', group 'root'
-    zc.recipe.deployment: 
-        Updating '/var/log/foo',
+    zc.recipe.deployment:
+        Creating '_tdir_/etc/foo',
         mode 755, user 'jim', group 'jim'
-    zc.recipe.deployment: 
-        Updating '/var/run/foo',
+    zc.recipe.deployment:
+        Updating '_tdir_/log/foo',
+        mode 755, user 'jim', group 'jim'
+    zc.recipe.deployment:
+        Updating '_tdir_/run/foo',
         mode 750, user 'jim', group 'jim'
 
-    >>> os.remove('/var/log/foo/x')
-    >>> os.remove('/var/run/foo/x')
+    >>> os.remove(os.path.join(tdir, 'log/foo/x'))
+    >>> os.remove(os.path.join(tdir, 'run/foo/x'))
 
-    >>> print system(join('bin', 'buildout')+' buildout:parts='),
+    >>> print fixup(system(join('bin', 'buildout')+' buildout:parts=')),
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/foo'
-    zc.recipe.deployment: Removing '/var/log/foo'.
-    zc.recipe.deployment: Removing '/var/run/foo'.
+    zc.recipe.deployment: Removing '_tdir_/etc/foo'
+    zc.recipe.deployment: Removing '_tdir_/log/foo'.
+    zc.recipe.deployment: Removing '_tdir_/run/foo'.
 
-    >>> os.path.exists('/etc/foo')
+    >>> os.path.exists(os.path.join(tdir, '/etc/foo'))
     False
-    >>> os.path.exists('/var/log/foo')
+    >>> os.path.exists(os.path.join(tdir, '/log/foo'))
     False
-    >>> os.path.exists('/var/run/foo')
+    >>> os.path.exists(os.path.join(tdir, '/run/foo'))
     False
 
 Deployment Name
@@ -157,51 +166,54 @@
     ... [foo]
     ... recipe = zc.recipe.deployment
     ... name = bar
-    ... user = jim
-    ... ''')
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(os.path.join('bin', 'buildout'))), #doctest: +NORMALIZE_WHITESPACE
     Installing foo.
-    zc.recipe.deployment: 
-        Creating '/etc/bar',
-        mode 755, user 'root', group 'root'
-    zc.recipe.deployment: 
-        Creating '/var/log/bar',
+    zc.recipe.deployment:
+        Creating '_tdir_/etc/bar',
         mode 755, user 'jim', group 'jim'
-    zc.recipe.deployment: 
-        Creating '/var/run/bar',
+    zc.recipe.deployment:
+        Creating '_tdir_/log/bar',
+        mode 755, user 'jim', group 'jim'
+    zc.recipe.deployment:
+        Creating '_tdir_/run/bar',
         mode 750, user 'jim', group 'jim'
 
-    >>> print system('ls -ld /etc/bar'), 
-    drwxr-xr-x 2 root root 4096 2007-02-06 09:50 /etc/bar
+    >>> print fixup(system('ls -ld %s/etc/bar' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-xr-x ... _tdir_/etc/bar
 
-    >>> print system('ls -ld /var/log/bar'), 
-    drwxr-xr-x 2 jim jim 4096 2007-02-06 09:50 /var/log/bar
+    >>> print fixup(system('ls -ld %s/log/bar' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-xr-x ... _tdir_/log/bar
 
-    >>> print system('ls -ld /var/run/bar'), 
-    drwxr-x--- 2 jim jim 40 2007-02-06 09:50 /var/run/bar
+    >>> print fixup(system('ls -ld %s/run/bar' % (tdir))), #doctest: +ELLIPSIS
+    drwxr-x--- ... _tdir_/run/bar
 
-    >>> cat('.installed.cfg') # doctest: +ELLIPSIS
+    >>> print fixup(file('.installed.cfg').read()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
     [buildout]
-    installed_develop_eggs = 
+    installed_develop_eggs =
     parts = foo
     <BLANKLINE>
     [foo]
-    __buildout_installed__ = 
+    __buildout_installed__ =
     ...
     crontab-directory = /etc/cron.d
-    etc-directory = /etc/bar
-    log-directory = /var/log/bar
+    etc-directory = _tdir_/etc/bar
+    log-directory = _tdir_/log/bar
     logrotate-directory = /etc/logrotate.d
     name = bar
     rc-directory = /etc/init.d
     recipe = zc.recipe.deployment
-    run-directory = /var/run/bar
+    run-directory = _tdir_/run/bar
     user = jim
 
 Note (here and earlier) that the options include the name option,
 which defaults to the part name.  Other parts that use the deployment
-name should use the name option rather than the part name. 
+name should use the name option rather than the part name.
 
 Configuration files
 ===================
@@ -220,30 +232,33 @@
     ...
     ... [foo]
     ... recipe = zc.recipe.deployment
-    ... user = jim
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
     ...
     ... [x.cfg]
     ... recipe = zc.recipe.deployment:configuration
     ... text = xxx
     ...        yyy
     ...        zzz
-    ... ''')
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(os.path.join('bin', 'buildout'))), # doctest: +NORMALIZE_WHITESPACE
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/bar'
-    zc.recipe.deployment: Removing '/var/log/bar'.
-    zc.recipe.deployment: Removing '/var/run/bar'.
+    zc.recipe.deployment: Removing '_tdir_/etc/bar'
+    zc.recipe.deployment: Removing '_tdir_/log/bar'.
+    zc.recipe.deployment: Removing '_tdir_/run/bar'.
     Installing foo.
-    zc.recipe.deployment: 
-        Creating '/etc/foo',
-        mode 755, user 'root', group 'root'
-    zc.recipe.deployment: 
-        Creating '/var/log/foo',
+    zc.recipe.deployment:
+        Creating '_tdir_/etc/foo',
         mode 755, user 'jim', group 'jim'
-    zc.recipe.deployment: 
-        Creating '/var/run/foo',
+    zc.recipe.deployment:
+        Creating '_tdir_/log/foo',
+        mode 755, user 'jim', group 'jim'
+    zc.recipe.deployment:
+        Creating '_tdir_/run/foo',
         mode 750, user 'jim', group 'jim'
     Installing x.cfg.
 
@@ -264,7 +279,10 @@
     ...
     ... [foo]
     ... recipe = zc.recipe.deployment
-    ... user = jim
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
     ...
     ... [x.cfg]
     ... recipe = zc.recipe.deployment:configuration
@@ -272,17 +290,17 @@
     ...        yyy
     ...        zzz
     ... deployment = foo
-    ... ''')
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print system(os.path.join('bin', 'buildout')),
     Uninstalling x.cfg.
     Updating foo.
     Installing x.cfg.
 
-    >>> os.path.exists(join('parts', 'x.cfg'))
+    >>> os.path.exists(os.path.join('parts', 'x.cfg'))
     False
 
-    >>> cat('/etc/foo/x.cfg')
+    >>> cat(tdir, 'etc/foo/x.cfg')
     xxx
     yyy
     zzz
@@ -299,32 +317,35 @@
     ...
     ... [foo]
     ... recipe = zc.recipe.deployment
-    ... user = jim
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
     ...
     ... [x.cfg]
     ... recipe = zc.recipe.deployment:configuration
     ... file = x.in
     ... deployment = foo
-    ... ''')
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
     >>> print system(join('bin', 'buildout')),
     Uninstalling x.cfg.
     Updating foo.
     Installing x.cfg.
 
-    >>> cat('/etc/foo/x.cfg')
+    >>> cat(tdir, 'etc/foo/x.cfg')
     1
     2
     3
 
 The recipe sets a location option that can be used by other recipes:
 
-    >>> cat('.installed.cfg') # doctest: +ELLIPSIS
+    >>> print fixup(file('.installed.cfg').read()) # doctest: +ELLIPSIS
     [buildout]
     ...
     [x.cfg]
     ...
-    location = /etc/foo/x.cfg
+    location = _tdir_/etc/foo/x.cfg
     ...
 
 Cron support
@@ -341,23 +362,30 @@
     ...
     ... [foo]
     ... recipe = zc.recipe.deployment
-    ... user = jim
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
+    ... crontab-directory = %(tdir)s/etc
     ...
     ... [cron]
     ... recipe = zc.recipe.deployment:crontab
     ... times = 30 23 * * *
     ... command = echo hello world!
     ... deployment = foo
-    ... ''')
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(os.path.join('bin', 'buildout'))), # doctest: +ELLIPSIS
     Uninstalling x.cfg.
-    Updating foo.
+    Uninstalling foo.
+    ...
+    Installing foo.
+    ...
     Installing cron.
 
-This example creates /etc/cron.d/foo-cron
+This example creates _tdir_/etc/foo-cron
 
-    >>> open('/etc/cron.d/foo-cron').read()
+    >>> fixup(file(os.path.join(tdir,'etc/foo-cron'), 'r').read())
     '30 23 * * *\tjim\techo hello world!\n'
 
 .. make sure cron recipe honors deployment name option:
@@ -371,48 +399,55 @@
     ... [foo]
     ... recipe = zc.recipe.deployment
     ... name = bar
-    ... user = jim
+    ... user = %(user)s
+    ... etc-directory = %(tdir)s/etc
+    ... log-directory = %(tdir)s/log
+    ... run-directory = %(tdir)s/run
+    ... crontab-directory = %(tdir)s/etc
     ...
     ... [cron]
     ... recipe = zc.recipe.deployment:crontab
     ... times = 30 23 * * *
     ... command = echo hello world!
     ... deployment = foo
-    ... ''')
+    ... ''' % ({ 'user':runninguser, 'tdir':tdir}))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print fixup(system(os.path.join('bin', 'buildout'))), # doctest: +NORMALIZE_WHITESPACE
     Uninstalling cron.
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/foo'
-    zc.recipe.deployment: Removing '/var/log/foo'.
-    zc.recipe.deployment: Removing '/var/run/foo'.
+    zc.recipe.deployment: Removing '_tdir_/etc/foo'
+    zc.recipe.deployment: Removing '_tdir_/log/foo'.
+    zc.recipe.deployment: Removing '_tdir_/run/foo'.
     Installing foo.
-    zc.recipe.deployment: 
-        Creating '/etc/bar',
-        mode 755, user 'root', group 'root'
-    zc.recipe.deployment: 
-        Creating '/var/log/bar',
+    zc.recipe.deployment:
+        Creating '_tdir_/etc/bar',
         mode 755, user 'jim', group 'jim'
-    zc.recipe.deployment: 
-        Creating '/var/run/bar',
+    zc.recipe.deployment:
+        Creating '_tdir_/log/bar',
+        mode 755, user 'jim', group 'jim'
+    zc.recipe.deployment:
+        Creating '_tdir_/run/bar',
         mode 750, user 'jim', group 'jim'
     Installing cron.
 
-    >>> open('/etc/cron.d/bar-cron').read()
+    >>> fixup(open(os.path.join(tdir, 'etc/bar-cron')).read())
     '30 23 * * *\tjim\techo hello world!\n'
 
 
 .. cleanup
 
-    >>> print system(join('bin', 'buildout')+' buildout:parts='),
+    >>> print fixup(system(join('bin', 'buildout')+' buildout:parts=')),
     Uninstalling cron.
     Uninstalling foo.
     Running uninstall recipe.
-    zc.recipe.deployment: Removing '/etc/bar'
-    zc.recipe.deployment: Removing '/var/log/bar'.
-    zc.recipe.deployment: Removing '/var/run/bar'.
+    zc.recipe.deployment: Removing '_tdir_/etc/bar'
+    zc.recipe.deployment: Removing '_tdir_/log/bar'.
+    zc.recipe.deployment: Removing '_tdir_/run/bar'.
 
-    >>> os.path.exists('/etc/cron.d/bar-cron')
+    >>> os.path.exists(os.path.join(tdir, 'etc/bar-cron'))
     False
-    
+
+... and cleanup the tmpdir
+    >>> import shutil
+    >>> shutil.rmtree(tdir)



More information about the Checkins mailing list