[py-svn] r11663 - in py/dist/py: path path/local path/local/testing test/terminal

hpk at codespeak.net hpk at codespeak.net
Sat Apr 30 23:51:42 CEST 2005


Author: hpk
Date: Sat Apr 30 23:51:42 2005
New Revision: 11663

Modified:
   py/dist/py/path/common.py
   py/dist/py/path/local/local.py
   py/dist/py/path/local/testing/test_local.py
   py/dist/py/test/terminal/terminal.py
Log:
- fixed chdir() invocations in test_local

- fixed dumpobj() method and add a 'bin' parameter 
  added tests
 


Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py	(original)
+++ py/dist/py/path/common.py	Sat Apr 30 23:51:42 2005
@@ -158,12 +158,9 @@
 
     def __cmp__(self, other):
         try:
-            try:
-                return cmp(self.strpath, other.strpath)
-            except AttributeError:
-                return cmp(str(self), str(other)) # self.path, other.path)
-        except:
-            self._except(sys.exc_info())
+            return cmp(self.strpath, other.strpath)
+        except AttributeError:
+            return cmp(str(self), str(other)) # self.path, other.path)
 
     def __repr__(self):
         return repr(str(self))
@@ -308,15 +305,12 @@
 
     def loadobj(self):
         """ return object unpickled from self.read() """
+        f = self.open('rb')
         try:
-            f = self.open('rb')
-            try:
-                from cPickle import load
-                return load(f)
-            finally:
-                f.close()
-        except:
-            self._except(sys.exc_info())
+            from cPickle import load
+            return self._callex(load, f)
+        finally:
+            f.close()
 
     def move(self, target):
         if target.relto(self):

Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py	(original)
+++ py/dist/py/path/local/local.py	Sat Apr 30 23:51:42 2005
@@ -231,11 +231,11 @@
     def rename(self, target):
         return self._callex(os.rename, str(self), str(target))
 
-    def dumpobj(self, obj):
+    def dumpobj(self, obj, bin=1):
         """ pickle object into path location"""
         f = self.open('wb')
         try:
-            self._callex(py.std.cPickle.dump, obj, f)
+            self._callex(py.std.cPickle.dump, obj, f, bin)
         finally:
             f.close()
 

Modified: py/dist/py/path/local/testing/test_local.py
==============================================================================
--- py/dist/py/path/local/testing/test_local.py	(original)
+++ py/dist/py/path/local/testing/test_local.py	Sat Apr 30 23:51:42 2005
@@ -19,13 +19,12 @@
         assert str(local()) == py.std.os.getcwd()
 
     def test_initialize_reldir(self):
-        curdir = py.std.os.curdir
+        old = self.root.chdir()
         try:
-            py.std.os.chdir(str(self.root))
             p = local('samplefile')
             assert p.check()
         finally:
-            py.std.os.chdir(curdir)
+            old.chdir()
 
     def test_eq_with_strings(self):
         path1 = self.root.join('sampledir')
@@ -38,22 +37,23 @@
 
     def test_dump(self):
         import tempfile
-        try:
-            fd, name = tempfile.mkstemp()
-            f = py.std.os.fdopen(fd)
-        except AttributeError:
-            name = tempfile.mktemp()
-            f = open(name, 'w+')
-        try:
-            d = {'answer' : 42}
-            path = local(name)
-            path.dumpobj(d)
-            from cPickle import load
-            dnew = load(f)
-            assert d == dnew
-        finally:
-            f.close()
-            py.std.os.remove(name)
+        for bin in 0, 1: 
+            try:
+                fd, name = tempfile.mkstemp()
+                f = py.std.os.fdopen(fd)
+            except AttributeError:
+                name = tempfile.mktemp()
+                f = open(name, 'w+')
+            try:
+                d = {'answer' : 42}
+                path = local(name)
+                path.dumpobj(d, bin=bin)
+                from cPickle import load
+                dnew = load(f)
+                assert d == dnew
+            finally:
+                f.close()
+                py.std.os.remove(name)
 
     def test_setmtime(self):
         import tempfile
@@ -179,7 +179,7 @@
     def test_sysexec(self):
         x = py.path.local.sysfind('ls')
         out = x.sysexec()
-        for x in py.path.local():
+        for x in py.path.local().listdir(lambda x: x.check(dir=0)): 
             assert out.find(x.basename) != -1
 
     def test_sysexec_failing(self):

Modified: py/dist/py/test/terminal/terminal.py
==============================================================================
--- py/dist/py/test/terminal/terminal.py	(original)
+++ py/dist/py/test/terminal/terminal.py	Sat Apr 30 23:51:42 2005
@@ -9,10 +9,10 @@
     if not base: 
         return None 
     # with posix local paths '/' is always a common base
-    relsource = source.__class__(dest).relto(base)
-    reldest = source.relto(base)
-    n = reldest.count(source.sep)
-    target = source.sep.join(('..', )*n + (relsource, ))
+    relsource = source.relto(base)
+    reldest = dest.relto(base)
+    n = relsource.count(source.sep)
+    target = dest.sep.join(('..', )*n + (reldest, ))
     return target 
 
 class TerminalSession(py.test.Session): 



More information about the pytest-commit mailing list