[pypy-svn] r15585 - in pypy/dist/pypy/rpython: . module/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 4 09:34:22 CEST 2005


Author: arigo
Date: Thu Aug  4 09:34:21 2005
New Revision: 15585

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/test/test_ll_os_path.py
Log:
Test the os.path functions used in PyPy: join() and isdir().
Testing both ntpath.join() and posixpath.join().
Hackish fix for ntpath.join().


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Thu Aug  4 09:34:21 2005
@@ -109,3 +109,13 @@
 
 for name in simple_math_functions:
     declare(getattr(math, name), float, 'll_math/%s' % name)
+
+# ___________________________________________________________
+# win/NT hack: patch ntpath.isabs() to be RPythonic
+
+import ntpath
+def isabs(s):
+    """Test whether a path is absolute"""
+    s = ntpath.splitdrive(s)[1]
+    return s != '' and s[0] in '/\\'
+ntpath.isabs = isabs

Modified: pypy/dist/pypy/rpython/module/test/test_ll_os_path.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_os_path.py	(original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_os_path.py	Thu Aug  4 09:34:21 2005
@@ -4,9 +4,37 @@
 
 from pypy.rpython.module.ll_os_path import *
 from pypy.rpython.module.support import to_rstr, from_rstr, ll_strcpy
+from pypy.rpython.test.test_llinterp import interpret
+from pypy.tool.udir import udir
 
 def test_exists():
     filename = to_rstr(str(py.magic.autopath()))
     assert ll_os_path_exists(filename) == True
     assert not ll_os_path_exists(to_rstr(
         "strange_filename_that_looks_improbable.sde"))
+
+def test_posixpath():
+    import posixpath
+    def f():
+        assert posixpath.join("/foo", "bar") == "/foo/bar"
+        assert posixpath.join("/foo", "spam/egg") == "/foo/spam/egg"
+        assert posixpath.join("/foo", "/bar") == "/bar"
+    interpret(f, [])
+
+def test_ntpath():
+    import ntpath
+    def f():
+        assert ntpath.join("\\foo", "bar") == "\\foo\\bar"
+        assert ntpath.join("c:\\foo", "spam\\egg") == "c:\\foo\\spam\\egg"
+        assert ntpath.join("c:\\foo", "d:\\bar") == "d:\\bar"
+    interpret(f, [])
+
+def test_isdir():
+    s = str(udir.join('test_isdir'))
+    def f():
+        return os.path.isdir(s)
+    res = interpret(f, [])
+    assert res == os.path.isdir(s)
+    os.mkdir(s)
+    res = interpret(f, [])
+    assert res is True



More information about the Pypy-commit mailing list