[Checkins] SVN: Sandbox/ulif/grok-with-testing/src/grok/ Added
unittests for grok.testing.file directive.
Uli Fouquet
uli at gnufix.de
Wed Aug 15 09:49:13 EDT 2007
Log message for revision 78847:
Added unittests for grok.testing.file directive.
Changed:
U Sandbox/ulif/grok-with-testing/src/grok/admin/Another.txt
U Sandbox/ulif/grok-with-testing/src/grok/admin/app.py
A Sandbox/ulif/grok-with-testing/src/grok/admin/app_tests/
A Sandbox/ulif/grok-with-testing/src/grok/admin/app_tests/app.py
U Sandbox/ulif/grok-with-testing/src/grok/tests/test_grok.py
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/SampleDocTest.txt
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/__init__.py
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/file_directive.py
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subdir/
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subdir/empty_doc_test.txt
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/__init__.py
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/doctest_in_subpkg.txt
A Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/mod_declaring_a_doctest.py
-=-
Modified: Sandbox/ulif/grok-with-testing/src/grok/admin/Another.txt
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/admin/Another.txt 2007-08-15 13:11:52 UTC (rev 78846)
+++ Sandbox/ulif/grok-with-testing/src/grok/admin/Another.txt 2007-08-15 13:49:13 UTC (rev 78847)
@@ -3,11 +3,11 @@
>>> a = 1
>>> b = 1
>>> a + b
- 3
+ 2
Ooh, this was not the question.
>>> 5*7
- 42
+ 35
Ah! Found it!
\ No newline at end of file
Modified: Sandbox/ulif/grok-with-testing/src/grok/admin/app.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/admin/app.py 2007-08-15 13:11:52 UTC (rev 78846)
+++ Sandbox/ulif/grok-with-testing/src/grok/admin/app.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -15,7 +15,7 @@
class MyTest2(grok.testing.FunctionalDocTest):
"""A test with two files."""
- grok.testing.file('README.txt')
+ grok.testing.file('app_tests/app.py')
grok.testing.file('Another.txt')
class MyTest3(grok.testing.FunctionalDocTest):
Added: Sandbox/ulif/grok-with-testing/src/grok/admin/app_tests/app.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/admin/app_tests/app.py (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/admin/app_tests/app.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1,8 @@
+"""
+ Tests in a subpackage.
+
+ >>> a = 1
+ >>> a
+ 1
+
+"""
Modified: Sandbox/ulif/grok-with-testing/src/grok/tests/test_grok.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/test_grok.py 2007-08-15 13:11:52 UTC (rev 78846)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/test_grok.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -34,8 +34,8 @@
suite = unittest.TestSuite()
for name in ['adapter', 'error', 'view', 'event', 'security',
'zcml', 'static', 'utility', 'xmlrpc', 'json', 'container',
- 'traversal', 'form', 'site', 'grokker', 'directive', 'util',
- 'baseclass', 'annotation', 'application']:
+ 'testing', 'traversal', 'form', 'site', 'grokker', 'directive',
+ 'util', 'baseclass', 'annotation', 'application']:
suite.addTest(suiteFromPackage(name))
return suite
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/SampleDocTest.txt
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/testing/SampleDocTest.txt (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/testing/SampleDocTest.txt 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1,4 @@
+
+Just a pseudo doctest.
+
+ >>> 1 == 1
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/__init__.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/testing/__init__.py (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/testing/__init__.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1 @@
+# this is a package
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/file_directive.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/testing/file_directive.py (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/testing/file_directive.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1,89 @@
+"""
+Tests for the ``grok.testing.file`` directive.
+
+Declaring a not existent file makes Grok unhappy:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Doctest file ''Not existent file name'' declared in 'grok.tests.testing.file_directive' does not exist in '.../grok/tests/testing/'.
+
+We don't *have* to use the ``grok.testing.file`` directive:
+
+ >>> klass = DoctestWithoutFileDirective
+ >>> hasattr(klass, '__grok_testing_file__')
+ False
+
+We can declare one or more doctest files per FunctionalDoctest. By
+default doctestfiles are assumed to reside in the package of the
+module in which the doctest was defined:
+
+ >>> klass = DoctestInCurrentDir
+ >>> hasattr(klass, '__grok_testing_file__')
+ True
+
+ >>> klassdoctests = getattr(klass, '__grok_testing_file__', [])
+ >>> 'SampleDocTest.txt' in klassdoctests
+ True
+
+We can register doctests in subdirectories relative to the package of
+the module, where the ``FunctionalDocTest`` was defined. To make use
+of this feature, split path elements by the simple slash ('/').
+
+The subdirectories do not have to be Python packages (although they
+can), which is handy for functional tests, that should not be grokked
+when running in non-testing mode:
+
+ >>> klass = DoctestInSubDir
+ >>> klassdoctests = getattr(klass, '__grok_testing_file__', [])
+ >>> 'subdir/empty_doc_test.txt' in klassdoctests
+ True
+
+We can also register several docfiles per ``FunctionalDocTest``:
+
+ >>> klass = DoctestWithSeveralTests
+ >>> klassdoctests = getattr(klass, '__grok_testing_file__', [])
+ >>> 'SampleDocTest.txt' in klassdoctests
+ True
+
+ >>> 'subdir/empty_doc_test.txt' in klassdoctests
+ True
+
+Make sure, that doctest paths are looked up relative to the package,
+where the declaring ``FunctionalDocTest`` was defined. To test this,
+we grok the module in the subpackage and expect no ``GrokError`` to be
+raised. This means, that the doctestfile was found, although it
+resides in a different package and its path was declared relative to
+the subpackage module.
+
+ >>> dotted_subpkg_path = __name__.rsplit('.', 1)[0] + '.subpkg'
+ >>> grok.grok(dotted_subpkg_path)
+
+No output here is good. Just to make sure, the class was really
+grokked:
+
+ >>> from grok.tests.testing.subpkg.mod_declaring_a_doctest import DoctestDeclaredInSubpkg
+ >>> klass = DoctestDeclaredInSubpkg
+ >>> klassdoctests = getattr(klass, '__grok_testing_file__', [])
+ >>> 'doctest_in_subpkg.txt' in klassdoctests
+ True
+
+"""
+
+import grok
+
+class DoctestWithoutFileDirective(grok.testing.FunctionalDocTest):
+ pass
+
+class NotExistentTestFile(grok.testing.FunctionalDocTest):
+ grok.testing.file('Not existent file name')
+
+class DoctestInCurrentDir(grok.testing.FunctionalDocTest):
+ grok.testing.file('SampleDocTest.txt')
+
+class DoctestInSubDir(grok.testing.FunctionalDocTest):
+ grok.testing.file('subdir/empty_doc_test.txt')
+
+class DoctestWithSeveralTests(grok.testing.FunctionalDocTest):
+ grok.testing.file('SampleDocTest.txt')
+ grok.testing.file('subdir/empty_doc_test.txt')
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subdir/empty_doc_test.txt
===================================================================
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/__init__.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/__init__.py (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/__init__.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1 @@
+# this is a package
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/doctest_in_subpkg.txt
===================================================================
Added: Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/mod_declaring_a_doctest.py
===================================================================
--- Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/mod_declaring_a_doctest.py (rev 0)
+++ Sandbox/ulif/grok-with-testing/src/grok/tests/testing/subpkg/mod_declaring_a_doctest.py 2007-08-15 13:49:13 UTC (rev 78847)
@@ -0,0 +1,5 @@
+import grok
+
+class DoctestDeclaredInSubpkg(grok.testing.FunctionalDocTest):
+ grok.testing.file('doctest_in_subpkg.txt')
+
More information about the Checkins
mailing list