[pypy-svn] rev 2439 - in pypy/trunk/src/pypy: module/test objspace/std/test tool
hpk at codespeak.net
hpk at codespeak.net
Wed Dec 17 14:43:21 CET 2003
Author: hpk
Date: Wed Dec 17 14:43:20 2003
New Revision: 2439
Modified:
pypy/trunk/src/pypy/module/test/test_newstyleclasses.py
pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
pypy/trunk/src/pypy/tool/test.py
Log:
- added a basic test for properties
- added an equality test for dictobjects
- converted testsuite_from_dir to use vpath
(yeah, i could have done that in individual checkins)
Modified: pypy/trunk/src/pypy/module/test/test_newstyleclasses.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_newstyleclasses.py (original)
+++ pypy/trunk/src/pypy/module/test/test_newstyleclasses.py Wed Dec 17 14:43:20 2003
@@ -36,6 +36,17 @@
self.assertEquals(d.f("abc"), (D, "abc"))
self.assertEquals(D.f("abc"), (D, "abc"))
+ def test_property_simple(self):
+
+ class a(object):
+ def _get(self): return 42
+ def _set(self, value): raise AttributeError
+ def _del(self, value): raise KeyError
+ name = property(_get, _set, _del)
+ a1 = a()
+ self.assertEquals(a1.name, 42)
+ self.assertRaises(AttributeError, setattr, a1, 'name')
+ self.assertRaises(KeyError, delattr, a1, 'name')
if __name__ == '__main__':
test.main()
Modified: pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py (original)
+++ pypy/trunk/src/pypy/objspace/std/test/test_dictobject.py Wed Dec 17 14:43:20 2003
@@ -172,7 +172,13 @@
def setUp(self):
self.space = test.objspace('std')
-
+
+ def test_equality(self):
+ d = {1:2}
+ f = {1:2}
+ self.assert_(d == f)
+ self.assert_(d != {1:3})
+
def test_clear(self):
d = {1:2, 3:4}
d.clear()
Modified: pypy/trunk/src/pypy/tool/test.py
==============================================================================
--- pypy/trunk/src/pypy/tool/test.py (original)
+++ pypy/trunk/src/pypy/tool/test.py Wed Dec 17 14:43:20 2003
@@ -109,7 +109,7 @@
def printErrorList(self, flavour, errors):
from pypy.interpreter.baseobjspace import OperationError
for test, err in errors:
- if showinterplevelexceptions:
+ if Options.showinterplevelexceptions:
self.stream.writeln(self.separator1)
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
self.stream.writeln(self.separator2)
@@ -117,7 +117,7 @@
t2 = ''
if isinstance(err[1], OperationError) and \
test.space.full_exceptions:
- if showinterplevelexceptions:
+ if Options.showinterplevelexceptions:
t2 = '\nand at app-level:\n\n'
else:
t2 = ''
@@ -225,40 +225,34 @@
Additionally, their fully qualified python module path has
to be accepted by filterfunc (if it is not None).
"""
+ from vpath import getlocal, nodotfile
+ root = getlocal(root)
+
if Options.verbose > 2:
print >> sys.stderr, "scanning for test files in", root
if loader is None:
loader = unittest.TestLoader()
- root = os.path.abspath(root)
-
+ def testfilefilter(path):
+ return path.isfile() and path.fnmatch('test_*.py')
+ def recfilter(path):
+ return recursive and nodotfile(path)
+
suite = unittest.TestLoader.suiteClass()
- names = os.listdir(root)
- names.sort()
- for fn in names:
- # ignore "hidden" files
- if fn.startswith('.'):
- continue
- fullfn = os.path.join(root, fn)
- if os.path.isfile(fullfn) and fnmatch.fnmatch(fn, 'test_*.py'):
- # strip the leading pypy directory and the .py suffix
- modpath = fullfn[len(autopath.pypydir)+1:-3]
- modpath = 'pypy.' + modpath.replace(os.sep, '.')
- if (filterfunc is None) or filterfunc(modpath):
- try:
- subsuite = loader.loadTestsFromName(modpath)
- except:
- print "skipping testfile (failed loading it)", modpath
- else:
- suite.addTest(subsuite, modpath)
- # possibly, collect tests from subdirectories recursively
- elif recursive and os.path.isdir(fullfn):
- subsuite = testsuite_from_dir(fullfn, filterfunc, 1, loader)
- if subsuite:
- suite._tests.extend(subsuite._tests)
- return suite
+ for testfn in root.visit(testfilefilter, recfilter):
+ # strip the leading pypy directory and the .py suffix
+ modpath = str(testfn)[len(autopath.pypydir)+1:-3]
+ modpath = 'pypy.' + modpath.replace(os.sep, '.')
+ if (filterfunc is None) or filterfunc(modpath):
+ try:
+ subsuite = loader.loadTestsFromName(modpath)
+ except:
+ print "skipping testfile (failed loading it)", modpath
+ else:
+ suite.addTest(subsuite, modpath)
+ return suite
class Options(option.Options):
testreldir = 0
@@ -270,6 +264,7 @@
def ensure_value(*args):
return 0
ensure_value = staticmethod(ensure_value)
+ showinterplevelexceptions = 1
class TestSkip(Exception):
More information about the Pypy-commit
mailing list