[Checkins] SVN: grokproject/trunk/ Added tests

Reinout van Rees reinout at vanrees.org
Fri May 2 13:24:49 EDT 2008


Log message for revision 86108:
  Added tests

Changed:
  U   grokproject/trunk/CHANGES.txt
  U   grokproject/trunk/setup.py
  A   grokproject/trunk/tests.py
  A   grokproject/trunk/tests.txt

-=-
Modified: grokproject/trunk/CHANGES.txt
===================================================================
--- grokproject/trunk/CHANGES.txt	2008-05-02 17:21:05 UTC (rev 86107)
+++ grokproject/trunk/CHANGES.txt	2008-05-02 17:24:49 UTC (rev 86108)
@@ -4,6 +4,8 @@
 0.8 (unreleased)
 ------------------
 
+* Added test.
+
 * Copy the run_buildout function from zopeproject and put it in
   utils.py.  Call that in the post hook of our paste template.  In the
   grokproject command after calling paster just quit.

Modified: grokproject/trunk/setup.py
===================================================================
--- grokproject/trunk/setup.py	2008-05-02 17:21:05 UTC (rev 86107)
+++ grokproject/trunk/setup.py	2008-05-02 17:24:49 UTC (rev 86108)
@@ -21,6 +21,8 @@
     include_package_data=True,
     zip_safe=False,
     install_requires=['PasteScript>=1.6',],
+    tests_require=['zope.testing', 'zc.buildout', 'Cheetah', 'PasteScript'],
+    test_suite='tests.test_suite',
     entry_points={
     'console_scripts': ['grokproject = grokproject:main'],
     'paste.paster_create_template': ['grok = grokproject:GrokProject']},

Added: grokproject/trunk/tests.py
===================================================================
--- grokproject/trunk/tests.py	                        (rev 0)
+++ grokproject/trunk/tests.py	2008-05-02 17:24:49 UTC (rev 86108)
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+"""
+Grabs the tests in doctest
+
+Taken virtually verbatim from zopeskel with permission (for zpl) from Tarek
+Ziade. (c) Tarek Ziade
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import doctest
+import sys
+import os
+import shutil
+import popen2
+import StringIO
+
+from zope.testing import doctest
+
+current_dir = os.path.abspath(os.path.dirname(__file__))
+
+def rmdir(*args):
+    dirname = os.path.join(*args)
+    if os.path.isdir(dirname):
+        shutil.rmtree(dirname)
+
+def read_sh(cmd):
+    _cmd = cmd
+    old = sys.stdout
+    child_stdout_and_stderr, child_stdin = popen2.popen4(_cmd)
+    child_stdin.close()
+    return child_stdout_and_stderr.read()
+
+def sh(cmd):
+    _cmd = cmd
+    print cmd
+    # launch command 2 times to see what append and be able
+    # to test in doc tests
+    os.system(_cmd)
+    child_stdout_and_stderr, child_stdin = popen2.popen4(_cmd)
+    child_stdin.close()
+    print child_stdout_and_stderr.read()
+
+def ls(*args):
+    dirname = os.path.join(*args)
+    if os.path.isdir(dirname):
+        filenames = os.listdir(dirname)
+        for filename in sorted(filenames):
+            print filename
+    else:
+        print 'No directory named %s' % dirname
+
+def cd(*args):
+    dirname = os.path.join(*args)
+    os.chdir(dirname)
+
+
+def config(filename):
+    return os.path.join(current_dir, filename)
+
+def cat(*args):
+    filename = os.path.join(*args)
+    if os.path.isfile(filename):
+        print open(filename).read()
+    else:
+        print 'No file named %s' % filename
+
+def touch(*args, **kwargs):
+    filename = os.path.join(*args)
+    open(filename, 'w').write(kwargs.get('data',''))
+
+execdir = os.path.abspath(os.path.dirname(sys.executable))
+tempdir = os.getenv('TEMP','/tmp')
+
+def doc_suite(package_dir, setUp=None, tearDown=None, globs=None):
+    """Returns a test suite, based on doctests found in /doctest."""
+    suite = []
+    if globs is None:
+        globs = globals()
+
+    flags = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE |
+             doctest.REPORT_ONLY_FIRST_FAILURE)
+
+    if package_dir not in sys.path:
+        sys.path.append(package_dir)
+
+    docs = [os.path.join(package_dir, 'tests.txt')]
+
+    for test in docs:
+        suite.append(doctest.DocFileSuite(test, optionflags=flags,
+                                          globs=globs, setUp=setUp,
+                                          tearDown=tearDown,
+                                          module_relative=False))
+
+    return unittest.TestSuite(suite)
+
+def test_suite():
+    """returns the test suite"""
+    return doc_suite(current_dir)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: grokproject/trunk/tests.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: grokproject/trunk/tests.txt
===================================================================
--- grokproject/trunk/tests.txt	                        (rev 0)
+++ grokproject/trunk/tests.txt	2008-05-02 17:24:49 UTC (rev 86108)
@@ -0,0 +1,38 @@
+Grokproject tests
+=================
+
+Go to a directory::
+
+    >>> cd(tempdir)
+
+Check that the directory does not exist::
+
+    >>> rmdir('grokexample')
+
+Then use paster::
+
+    >>> sh('paster create -t grok grokexample user=a passwd=a --no-interactive')
+    paster create -t grok grokexample user=a passwd=a --no-interactive
+    ...
+
+Let's check the contents
+
+    >>> package_dir = os.path.join(tempdir, 'grokexample')
+    >>> ls(package_dir)
+    .installed.cfg
+    bin
+    buildout.cfg
+    develop-eggs
+    parts
+    setup.py
+    src
+
+    >>> sofware_dir = os.path.join(package_dir, 'src', 'grokexample')
+    >>> ls(sofware_dir)
+    __init__.py
+    app.py
+    app_templates
+    configure.zcml
+    ftesting.zcml
+    static
+    testing.py


Property changes on: grokproject/trunk/tests.txt
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list