[Zope3-checkins]
SVN: zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner
Make test.py -s subdir pay attention to the directory ->
package mappings.
Marius Gedminas
marius at pov.lt
Fri Jan 12 17:37:36 EST 2007
Log message for revision 71986:
Make test.py -s subdir pay attention to the directory -> package mappings.
The goal is to make test.py -s src/zope/subpackage be an alternative
way of specifying -s zope.subpackage, if I'm in the root of a Zope 3 checkout.
Why is that useful? This way you can use shell tab-completion to specify
a package name. The current "backwards compatibility" code that replaces
slashes with dots is not sufficient for that.
I would appreciate testing on various platforms (e.g. Windows) and in various
checkout layouts (e.g. those that use zc.buildout and stich multiple zope_foo
packages from different subdirectories into one namespace).
Changed:
U zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner-test-selection.txt
U zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner-test-selection.txt
===================================================================
--- zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner-test-selection.txt 2007-01-12 22:33:13 UTC (rev 71985)
+++ zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner-test-selection.txt 2007-01-12 22:37:36 UTC (rev 71986)
@@ -154,6 +154,39 @@
Ran 128 tests with 0 failures and 0 errors in 0.025 seconds.
False
+You can specify directory names instead of packages (useful for
+tab-completion):
+
+ >>> subdir = os.path.join(directory_with_tests, 'sample1')
+ >>> sys.argv = ('test --layer 122 -s %s -vv' % subdir).split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ Running tests at level 1
+ Running samplelayers.Layer122 tests:
+ Set up samplelayers.Layer1 in 0.000 seconds.
+ Set up samplelayers.Layer12 in 0.000 seconds.
+ Set up samplelayers.Layer122 in 0.000 seconds.
+ Running:
+ test_x1 (sample1.sampletests.test122.TestA)
+ test_y0 (sample1.sampletests.test122.TestA)
+ test_z0 (sample1.sampletests.test122.TestA)
+ test_x0 (sample1.sampletests.test122.TestB)
+ test_y1 (sample1.sampletests.test122.TestB)
+ test_z0 (sample1.sampletests.test122.TestB)
+ test_1 (sample1.sampletests.test122.TestNotMuch)
+ test_2 (sample1.sampletests.test122.TestNotMuch)
+ test_3 (sample1.sampletests.test122.TestNotMuch)
+ test_x0 (sample1.sampletests.test122)
+ test_y0 (sample1.sampletests.test122)
+ test_z1 (sample1.sampletests.test122)
+ testrunner-ex/sample1/sampletests/../../sampletestsl.txt
+ Ran 17 tests with 0 failures and 0 errors in 0.005 seconds.
+ Tearing down left over layers:
+ Tear down samplelayers.Layer122 in 0.000 seconds.
+ Tear down samplelayers.Layer12 in 0.000 seconds.
+ Tear down samplelayers.Layer1 in 0.000 seconds.
+ False
+
We can select by test module name using the --module (-m) option:
>>> sys.argv = 'test -u -vv -ssample1 -m_one -mtest1'.split()
Modified: zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner.py 2007-01-12 22:33:13 UTC (rev 71985)
+++ zope.testing/branches/filter-by-dirs/src/zope/testing/testrunner.py 2007-01-12 22:37:36 UTC (rev 71986)
@@ -1802,14 +1802,6 @@
options.test = map(compile_filter, options.test or ('.'))
options.module = map(compile_filter, options.module or ('.'))
- if options.package:
- options.package = [p.replace('/', '.').replace('\\', '.')
- for p in options.package]
- # Remove useless dot ('.') at the end of the package. bash
- # adds a `/` by default using completion. Otherweise, it
- # raises an exception trying to import an empty package
- # because of this.
- options.package = [re.sub(r'\.$', '', p) for p in options.package]
options.path = map(os.path.abspath, options.path or ())
options.test_path = map(os.path.abspath, options.test_path or ())
options.test_path += options.path
@@ -1820,6 +1812,10 @@
for (path, package) in options.package_path or ()
])
+ if options.package:
+ pkgmap = dict(options.test_path)
+ options.package = [normalize_package(p, pkgmap)
+ for p in options.package]
options.prefix = [(path + os.path.sep, package)
for (path, package) in options.test_path]
@@ -1860,6 +1856,50 @@
return options
+def normalize_package(package, package_map={}):
+ r"""Normalize package name passed to the --package option.
+
+ >>> normalize_package('zope.testing')
+ 'zope.testing'
+
+ Converts path names into package names for compatibility with the old
+ test runner.
+
+ >>> normalize_package('zope/testing')
+ 'zope.testing'
+ >>> normalize_package('zope/testing/')
+ 'zope.testing'
+ >>> normalize_package('zope\\testing')
+ 'zope.testing'
+
+ Can use a map of absolute pathnames to package names
+
+ >>> a = os.path.abspath
+ >>> normalize_package('src/zope/testing/',
+ ... {a('src'): ''})
+ 'zope.testing'
+ >>> normalize_package('src/zope_testing/',
+ ... {a('src/zope_testing'): 'zope.testing'})
+ 'zope.testing'
+ >>> normalize_package('src/zope_something/tests',
+ ... {a('src/zope_something'): 'zope.something',
+ ... a('src'): ''})
+ 'zope.something.tests'
+
+ """
+ package = package.replace('\\', '/')
+ if package.endswith('/'):
+ package = package[:-1]
+ bits = package.split('/')
+ for n in range(len(bits), 0, -1):
+ pkg = package_map.get(os.path.abspath('/'.join(bits[:n])))
+ if pkg is not None:
+ bits = bits[n:]
+ if pkg:
+ bits = [pkg] + bits
+ return '.'.join(bits)
+ return package.replace('/', '.')
+
# Command-line UI
###############################################################################
More information about the Zope3-Checkins
mailing list