[Python-checkins] python/nondist/sandbox/path path.py, 1.5, 1.6 test_path.py, 1.5, 1.6

birkenfeld@users.sourceforge.net birkenfeld at users.sourceforge.net
Mon Jul 25 18:06:35 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/path
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21228
Modified Files:
	path.py test_path.py 
Log Message:
Don't accept anything except a basestring as constructor argument.
Index: path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/path.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- path.py	25 Jul 2005 07:34:21 -0000	1.5
+++ path.py	25 Jul 2005 16:06:32 -0000	1.6
@@ -60,6 +60,10 @@
 """
 if not args:
 return Path(os.curdir)
+ if len(args) > 1:
+ raise TypeError("Path() takes at most 1 argument (%i given)" % len(args))
+ if not isinstance(args[0], basestring):
+ raise ValueError("Path() argument must be str or unicode")
 return _base.__new__(typ, *args)
 
 # Iterating over a string yields its parts
Index: test_path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/test_path.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_path.py	25 Jul 2005 07:34:23 -0000	1.5
+++ test_path.py	25 Jul 2005 16:06:32 -0000	1.6
@@ -27,6 +27,18 @@
 return choices[os.name]
 
 class BasicTestCase(unittest.TestCase):
+ def testConstructor(self):
+ # constructor can only be called with zero or one arguments
+ p = Path()
+ self.assert_(p.base() == os.curdir)
+
+ self.assertRaises(TypeError, Path, "a", "b")
+ self.assertRaises(TypeError, Path, 1, 2)
+ 
+ # constructor can only be called with basestring as argument
+ self.assertRaises(ValueError, Path, None)
+ self.assertRaises(ValueError, Path, 1)
+
 def testRelpath(self):
 root = Path(p(nt='C:\\',
 posix='/'))


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /