[Checkins] SVN: z3c.dependencychecker/trunk/ Improved coverage. Our own module is now at 100%.
Reinout van Rees
reinout at vanrees.org
Thu Dec 10 10:19:25 EST 2009
Log message for revision 106402:
Improved coverage. Our own module is now at 100%.
Changed:
U z3c.dependencychecker/trunk/CHANGES.txt
U z3c.dependencychecker/trunk/TODO.txt
U z3c.dependencychecker/trunk/src/z3c/dependencychecker/dependencychecker.py
U z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/dependencychecker.txt
U z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/sample1/src/sample1.egg-info/requires.txt
U z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/test_setup.py
-=-
Modified: z3c.dependencychecker/trunk/CHANGES.txt
===================================================================
--- z3c.dependencychecker/trunk/CHANGES.txt 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/CHANGES.txt 2009-12-10 15:19:24 UTC (rev 106402)
@@ -6,8 +6,10 @@
- Documentation update.
-- Improved test coverage.
+- Improved test coverage. The dependencychecker module self is at 100%, the
+ original import checker module is at 91% coverage.
+
0.5 (2009-12-10)
----------------
Modified: z3c.dependencychecker/trunk/TODO.txt
===================================================================
--- z3c.dependencychecker/trunk/TODO.txt 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/TODO.txt 2009-12-10 15:19:24 UTC (rev 106402)
@@ -1,11 +1,11 @@
TODO
====
-- Improve test coverage.
+- Improve test coverage of original import checker module.
- Try it on more projects and gather feedback.
-- Add some extra fallbacks for often-used packages like PIL (which is really
- Imaging when you import it).
+- Optionally add some extra fallbacks for often-used packages like PIL (which
+ is really Imaging when you import it).
Modified: z3c.dependencychecker/trunk/src/z3c/dependencychecker/dependencychecker.py
===================================================================
--- z3c.dependencychecker/trunk/src/z3c/dependencychecker/dependencychecker.py 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/src/z3c/dependencychecker/dependencychecker.py 2009-12-10 15:19:24 UTC (rev 106402)
@@ -258,7 +258,7 @@
print
-def main():
+def determine_path():
if len(sys.argv) > 1:
path = sys.argv[1]
else:
@@ -268,7 +268,11 @@
if not os.path.isdir(path):
print "Unknown path:", path
sys.exit(1)
+ return path
+
+def main():
+ path = determine_path()
db = importchecker.ImportDatabase(path)
# TODO: find zcml files
db.findModules()
Modified: z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/dependencychecker.txt
===================================================================
--- z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/dependencychecker.txt 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/dependencychecker.txt 2009-12-10 15:19:24 UTC (rev 106402)
@@ -148,5 +148,102 @@
[]
+Grabbing the name from setup.py
+-------------------------------
+Mock that we print our name (provided that we're called with ``--name`` of
+course):
+
+ >>> import os
+ >>> import sys
+ >>> import tempfile
+ >>> newtempdir = tempfile.mkdtemp(prefix='depcheck')
+ >>> setup_py = os.path.join(newtempdir, 'setup.py')
+ >>> open(setup_py, 'w').write('\n'.join([
+ ... "import sys",
+ ... "assert '--name' in sys.argv",
+ ... "print 'my_name'"]))
+ >>> os.chdir(newtempdir)
+
+Grab the name:
+
+ >>> dependencychecker.name_from_setup()
+ 'my_name'
+
+Mock that something goes wrong:
+
+ >>> open(setup_py, 'w').write("raise UserError('raargh')")
+
+Grab the name, which results in a (mocked) sys.exit():
+
+ >>> dependencychecker.name_from_setup()
+ Traceback (most recent call last):
+ ...
+ MockExitException: 1
+
+
+Corner case: egg info contents and location
+-------------------------------------------
+
+We're in a temp dir. First restore the setup.py:
+
+ >>> open(setup_py, 'w').write('\n'.join([
+ ... "import sys",
+ ... "assert '--name' in sys.argv",
+ ... "print 'my_name'"]))
+
+The normal ``src/xyz.egg-info`` case is already handled by the main example.
+Here we create the egg info dir directly in the directory itself. Not the
+common case, but we support the lack of ``src/`` dir.
+
+ >>> os.mkdir('my_name.egg-info')
+
+If we grab the requirements now, we hit two corner cases:
+
+- The egg-info dir is here, not in src.
+
+- The requires.txt file is missing.
+
+Grab it and watch the fireworks:
+
+ >>> dependencychecker.existing_requirements()
+ Traceback (most recent call last):
+ ...
+ MockExitException: 1
+
+
+Determining the path
+--------------------
+
+The main test flow already finds the by-default src dir. We test two corner
+cases here:
+
+Pass the path on the command line:
+
+ >>> sys.argv[1:] = [newtempdir]
+ >>> dependencychecker.determine_path() == newtempdir
+ True
+
+Pass a non-existing path:
+
+ >>> sys.argv[1:] = ['/does/not/exist']
+ >>> dependencychecker.determine_path()
+ Traceback (most recent call last):
+ ...
+ MockExitException: 1
+
+Pass a file instead of a directory:
+
+ >>> sys.argv[1:] = [setup_py]
+ >>> dependencychecker.determine_path()
+ Traceback (most recent call last):
+ ...
+ MockExitException: 1
+
+
+Clean up the tempdir, btw:
+
+ >>> import shutil
+ >>> shutil.rmtree(newtempdir)
+
"""
Modified: z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/sample1/src/sample1.egg-info/requires.txt
===================================================================
--- z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/sample1/src/sample1.egg-info/requires.txt 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/sample1/src/sample1.egg-info/requires.txt 2009-12-10 15:19:24 UTC (rev 106402)
@@ -9,4 +9,7 @@
needed.by.test.zcml
z3c.testsetup>=0.3
zope.testbrowser
-zope.testing
\ No newline at end of file
+zope.testing
+
+[someotherextension]
+we don't bother with this
\ No newline at end of file
Modified: z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/test_setup.py
===================================================================
--- z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/test_setup.py 2009-12-10 14:39:21 UTC (rev 106401)
+++ z3c.dependencychecker/trunk/src/z3c/dependencychecker/tests/test_setup.py 2009-12-10 15:19:24 UTC (rev 106402)
@@ -45,11 +45,22 @@
print item
+class MockExitException(Exception):
+ pass
+
+
+def mock_exit(code=None):
+ # Mock for sys.exit
+ raise MockExitException(code)
+
+
def setup(test):
"""Set up tempdir with sample project"""
test.orig_sysargv = sys.argv[:]
+ test.orig_exit = sys.exit
test.orig_dir = os.getcwd()
sys.argv[1:] = []
+ sys.exit = mock_exit
test.tempdir = tempfile.mkdtemp(prefix='dependencychecker')
sample1_source = pkg_resources.resource_filename(
'z3c.dependencychecker.tests', 'sample1')
@@ -74,6 +85,7 @@
"""Clean up"""
#print "Not zapping", test.tempdir
shutil.rmtree(test.tempdir)
+ sys.exit = test.orig_exit
sys.argv[:] = test.orig_sysargv
os.chdir(test.orig_dir)
More information about the checkins
mailing list