[Checkins] SVN: lovely.buildouthttp/trunk/ version bump, see changes

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Sep 22 01:52:27 EDT 2009


Log message for revision 104414:
  version bump, see changes

Changed:
  U   lovely.buildouthttp/trunk/CHANGES.txt
  U   lovely.buildouthttp/trunk/bootstrap.py
  U   lovely.buildouthttp/trunk/buildout.cfg
  U   lovely.buildouthttp/trunk/setup.py
  U   lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py
  A   lovely.buildouthttp/trunk/src/lovely/buildouthttp/tests.py

-=-
Modified: lovely.buildouthttp/trunk/CHANGES.txt
===================================================================
--- lovely.buildouthttp/trunk/CHANGES.txt	2009-09-21 21:34:35 UTC (rev 104413)
+++ lovely.buildouthttp/trunk/CHANGES.txt	2009-09-22 05:52:27 UTC (rev 104414)
@@ -2,17 +2,25 @@
 Changes for lovely.buildouthttp
 ===============================
 
+
+2009/09/22 0.2.3:
+=================
+
+- added tests for the installer
+
 - fixed error when url can't be retrieved:
   AttributeError: 'NoneType' object has no attribute 'url'
   [naro]
 
 2008/03/22 0.2.2:
 =================
+
 - added try/except around the retry section
   protection against weird URLs
 
 2007/12/08 0.2.1:
 =================
+
 - avoid an error when the realm is wrong or the file on bad realms and a few
   other controls. Thanks to Tarek Ziade.
 

Modified: lovely.buildouthttp/trunk/bootstrap.py
===================================================================
--- lovely.buildouthttp/trunk/bootstrap.py	2009-09-21 21:34:35 UTC (rev 104413)
+++ lovely.buildouthttp/trunk/bootstrap.py	2009-09-22 05:52:27 UTC (rev 104414)
@@ -24,6 +24,8 @@
 
 tmpeggs = tempfile.mkdtemp()
 
+is_jython = sys.platform.startswith('java')
+
 try:
     import pkg_resources
 except ImportError:
@@ -34,23 +36,49 @@
 
     import pkg_resources
 
-cmd = 'from setuptools.command.easy_install import main; main()'
 if sys.platform == 'win32':
-    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
 
-ws = pkg_resources.working_set
-assert os.spawnle(
-    os.P_WAIT, sys.executable, sys.executable,
-    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
-    dict(os.environ,
-         PYTHONPATH=
-         ws.find(pkg_resources.Requirement.parse('setuptools')).location
-         ),
-    ) == 0
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
 
+if len(sys.argv) > 2 and sys.argv[1] == '--version':
+    VERSION = '==%s' % sys.argv[2]
+    args = sys.argv[3:] + ['bootstrap']
+else:
+    VERSION = ''
+    args = sys.argv[1:] + ['bootstrap']
+
+if is_jython:
+    import subprocess
+
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+           quote(tmpeggs), 'zc.buildout' + VERSION],
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ),
+        ) == 0
+
 ws.add_entry(tmpeggs)
-ws.require('zc.buildout')
+ws.require('zc.buildout' + VERSION)
 import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+zc.buildout.buildout.main(args)
 shutil.rmtree(tmpeggs)
-

Modified: lovely.buildouthttp/trunk/buildout.cfg
===================================================================
--- lovely.buildouthttp/trunk/buildout.cfg	2009-09-21 21:34:35 UTC (rev 104413)
+++ lovely.buildouthttp/trunk/buildout.cfg	2009-09-22 05:52:27 UTC (rev 104414)
@@ -1,12 +1,10 @@
 [buildout]
 develop = .
 parts = test
-find-links = http://download.zope.org/distribution
 extensions = lovely.buildouthttp
 
 [test]
-# test to download an egg
-recipe = zc.recipe.egg
-eggs = setuptools
+recipe = zc.recipe.testrunner
+defaults = ['--auto-color']
+eggs = lovely.buildouthttp [test]
 
-

Modified: lovely.buildouthttp/trunk/setup.py
===================================================================
--- lovely.buildouthttp/trunk/setup.py	2009-09-21 21:34:35 UTC (rev 104413)
+++ lovely.buildouthttp/trunk/setup.py	2009-09-22 05:52:27 UTC (rev 104414)
@@ -16,7 +16,7 @@
 name='lovely.buildouthttp'
 setup(
     name = name,
-    version = "0.2.2",
+    version = "0.2.3",
     author = "Lovely Systems GmbH",
     author_email = "office at lovelysystems.com",
     description = "Specialized zc.buildout plugin to add http basic" \
@@ -30,6 +30,9 @@
     package_dir = {'':'src'},
     namespace_packages = ['lovely'],
     install_requires = ['setuptools'],
+    extras_require = dict(
+        test = ['zope.testing']
+        ),
     entry_points = {'zc.buildout.extension':
                     ['default = %s.buildouthttp:install' % name]
                     },

Modified: lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py
===================================================================
--- lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py	2009-09-21 21:34:35 UTC (rev 104413)
+++ lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py	2009-09-22 05:52:27 UTC (rev 104414)
@@ -24,6 +24,18 @@
 
 class CredHandler(urllib2.HTTPBasicAuthHandler):
 
+    """This handler adds basic auth credentials to the request upon a 401
+
+    >>> auth_handler = CredHandler()
+    >>> auth_handler.add_password('myrealm', 'http://example.com',
+    ...                           'user', 'password')
+
+    >>> from StringIO import StringIO
+    >>> fp = StringIO('The error body')
+    >>> req = urllib2.Request('http://example.com')
+    >>> auth_handler.http_error_401(req, fp, 401, 'msg', {})
+    """
+
     def http_error_401(self, req, fp, code, msg, headers):
         log.debug('getting url: %r' % req.get_full_url())
         try:
@@ -45,19 +57,50 @@
                 log.debug('got url: %r %r' % (res.url, res.code))
             return res
 
-def install(buildout=None):
+def install(buildout=None, pwd_path=None):
+    """
+    By default the install function looks for the password file at
+    ~/.buildout/.httpauth and installs a basic auth opener.
+
+    It does not fail if the file cannot be found.
+    >>> install()
+
+    We can supply the path to the file for testing.
+
+    >>> install(pwd_path='a')
+
+    If the file cannot be parsed an exception is raised.
+
+    >>> fp = os.path.join(tmp,'pwd.txt')
+    >>> import os
+    >>> f = file(fp, 'w')
+    >>> f.write('The realm,https://example.com/ something')
+    >>> f.close()
+    >>> install(pwd_path=fp)
+    Traceback (most recent call last):
+    ...
+    RuntimeError: Authentication file cannot be parsed ...pwd.txt:1
+
+    >>> f = file(fp, 'w')
+    >>> f.write('The realm,https://example.com/,username,password')
+    >>> f.close()
+    >>> install(pwd_path=fp)
+    """
     try:
-        pwdsf = file(os.path.join(os.path.expanduser('~'),
+        pwd_path = pwd_path or os.path.join(os.path.expanduser('~'),
                                   '.buildout',
-                                  '.httpauth'))
+                                  '.httpauth')
+        pwdsf = file(pwd_path)
     except IOError, e:
         log.warn('Could not load authentication information: %s' % e)
         return
     reader = csv.reader(pwdsf)
     auth_handler = CredHandler()
-    for row in reader:
+    for l, row in enumerate(reader):
         if len(row) != 4:
-            continue
+            raise RuntimeError(
+                "Authentication file cannot be parsed %s:%s" % (
+                    pwd_path, l+1))
         realm, uris, user, password = (el.strip() for el in row)
         log.debug('Added credentials %r, %r' % (realm, uris))
         auth_handler.add_password(realm, uris, user, password)

Added: lovely.buildouthttp/trunk/src/lovely/buildouthttp/tests.py
===================================================================
--- lovely.buildouthttp/trunk/src/lovely/buildouthttp/tests.py	                        (rev 0)
+++ lovely.buildouthttp/trunk/src/lovely/buildouthttp/tests.py	2009-09-22 05:52:27 UTC (rev 104414)
@@ -0,0 +1,21 @@
+import doctest, unittest
+from zope.testing.doctest import DocTestSuite
+import tempfile
+import shutil
+
+def setUp(test):
+    test.globs['tmp'] = tempfile.mkdtemp()
+
+def tearDown(test):
+    shutil.rmtree(test.globs['tmp'])
+
+
+def test_suite():
+    uSuites = (
+        DocTestSuite('lovely.buildouthttp.buildouthttp',
+                     setUp=setUp, tearDown=tearDown,
+                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+                     ),
+        )
+    return unittest.TestSuite(uSuites)
+


Property changes on: lovely.buildouthttp/trunk/src/lovely/buildouthttp/tests.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list