[py-svn] r6920 - in py/dist: doc py/execnet py/path py/path/local py/path/pypath py/path/svn py/path/svnwc py/path/test py/test

hpk at codespeak.net hpk at codespeak.net
Thu Oct 14 02:04:03 CEST 2004


Author: hpk
Date: Thu Oct 14 02:04:02 2004
New Revision: 6920

Removed:
   py/dist/py/path/test/test_svn_binding.py
Modified:
   py/dist/doc/test.txt
   py/dist/py/execnet/gateway.py
   py/dist/py/execnet/gateway_test.py
   py/dist/py/path/common.py
   py/dist/py/path/local/local.py
   py/dist/py/path/local/local_test.py
   py/dist/py/path/pypath/pypath_test.py
   py/dist/py/path/svn/command.py
   py/dist/py/path/svn/command_test.py
   py/dist/py/path/svn/common.py
   py/dist/py/path/svnwc/command.py
   py/dist/py/path/svnwc/command_test.py
   py/dist/py/path/test/_common.py
   py/dist/py/path/test/_svncommon.py
   py/dist/py/test/collect.py
   py/dist/py/test/collect_test.py
   py/dist/py/test/compat_test.py
   py/dist/py/test/raises_test.py
Log:
huge commit

- added copy method to filesystem path objects

- py.test: by default only collect classes that start
           with 'Test'

- py.test: fix bug that previously resulted in 
           running tests twice! 

- small cleanups here and there




Modified: py/dist/doc/test.txt
==============================================================================
--- py/dist/doc/test.txt	(original)
+++ py/dist/doc/test.txt	Thu Oct 14 02:04:02 2004
@@ -184,7 +184,10 @@
 dot (e.g.  ``.svn`` direcotries is ignored). 
 
 Another ``PyCollector`` then recurses into the test files and 
-collects functions and methods that have a leading ``test_`` 
+collects functions and methods that have a leading ``test_``. 
+By default, methods are only collected if their class starts 
+with ``Test``. 
+
 name, unless you provide a custom collector in your module. 
 
 

Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py	(original)
+++ py/dist/py/execnet/gateway.py	Thu Oct 14 02:04:02 2004
@@ -4,7 +4,7 @@
 # XXX the following line should not be here
 from py.__impl__.execnet.source import Source
 
-debug = 1
+debug = 0
 sysex = (KeyboardInterrupt, SystemExit) 
 
 class RemoteError(Exception):

Modified: py/dist/py/execnet/gateway_test.py
==============================================================================
--- py/dist/py/execnet/gateway_test.py	(original)
+++ py/dist/py/execnet/gateway_test.py	Thu Oct 14 02:04:02 2004
@@ -61,7 +61,6 @@
         py.test.raises(gateway.RemoteError, channel.waitclose, 0.01) 
 
 class PopenGatewayTestSetup: 
-    disabled = True 
     def setup_class(cls):
         cls.gw = py.execnet.PopenGateway() 
 
@@ -69,8 +68,6 @@
         cls.gw.exit()  
 
 class BasicRemoteExecution: 
-    disabled = True 
-
     def test_correct_setup(self):
         assert self.gw.workerthreads and self.gw.iothreads 
 
@@ -100,7 +97,6 @@
         py.test.raises(gateway.RemoteError, channel.receive) 
 
 class TestBasicPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution): 
-    disabled = False 
     def test_many_popen(self):
         num = 4
         l = []
@@ -122,9 +118,7 @@
             for x in channels: 
                 x.gateway.exit()
 
-class SocketGatewayTestSetup:
-    disabled = True
-
+class SocketGatewaySetup:
     def setup_class(cls):
         portrange = (7770, 7800)
         cls.proxygw = py.execnet.PopenGateway() 
@@ -179,6 +173,5 @@
         print "trying to tear proxy gateway" 
         cls.proxygw.exit() 
 
-class BasicSocketGatewayTest(SocketGatewayTestSetup, BasicRemoteExecution): 
-    disabled = False 
-
+class TestSocketGateway(SocketGatewaySetup, BasicRemoteExecution): 
+    pass

Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py	(original)
+++ py/dist/py/path/common.py	Thu Oct 14 02:04:02 2004
@@ -172,19 +172,20 @@
         except:
             self._except(sys.exc_info())
 
-    def visit(self, fil=None, rec=None, ignore=None):
+    def visit(self, fil=None, rec=None, ignore=None): 
         if isinstance(fil, str):
             fil = fnmatch(fil)
         if isinstance(rec, str):
             rec = fnmatch(fil)
-
-        reclist = []
-        try:
+        if ignore:
+            try:
+                dirlist = self.listdir()
+            except ignore:
+                return 
+        else:
             dirlist = self.listdir()
-        except ignore:
-            return 
-        
         checkdir = path.checker(dir=1)
+        reclist = []
         for p in dirlist: 
             if fil is None or fil(p):
                 yield p

Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py	(original)
+++ py/dist/py/path/local/local.py	Thu Oct 14 02:04:02 2004
@@ -53,15 +53,10 @@
         Note also that passing in a local path object will simply return 
         the exact same path object.
         """
-        #if isinstance(path, common.VPath):
-        #    path = path._impl
-
-        if isinstance(path, LocalPath):
+        if isinstance(path, cls): 
             if path.__class__ == cls:
                 return path
             path = path.strpath
-
-
         # initialize the path
         self = object.__new__(cls)
         if path is None:
@@ -246,10 +241,11 @@
             if self.check(dir=1, link=0):
                 if rec:
                     import shutil
-                    def call(*args):
-                        print args
+                    #def call(*args):
+                    #    print args
 
-                    shutil.rmtree(self.strpath, onerror=call)
+                    shutil.rmtree(self.strpath) 
+                    #, onerror=call)
                 else:
                     os.rmdir(self.strpath)
             else:
@@ -257,6 +253,30 @@
         except:
             self._except(sys.exc_info())
 
+    def copy(self, target, archive=False):
+        try:
+            assert not archive 
+            if self.check(file=1):
+                if target.check(dir=1):
+                    target = target.join(self.basename)
+                assert self!=target
+                copychunked(self, target)
+            else:
+                target.ensure(dir=1)
+                def rec(p):
+                    return rec.check(link=0)
+                for x in self.visit(rec=rec): 
+                    relpath = x.relto(self) 
+                    newx = target.join(relpath)
+                    if x.check(link=1):
+                        newx.mksymlinkto(x.readlink())
+                    elif x.check(file=1):
+                        copychunked(x, newx)
+                    elif x.check(dir=1):
+                        newx.ensure(dir=1) 
+        except:
+            self._except(sys.exc_info())
+                    
     def dumpobj(self, obj):
         """ pickle object into path location"""
         try:
@@ -364,7 +384,7 @@
 
 
     #"""
-    #Tool functions regarding local filesystem paths
+    #special class constructors for local filesystem paths
     #"""
     def get_temproot(cls):
         """ return the system's temporary directory (where tempfiles are usually created in)"""
@@ -444,3 +464,18 @@
     #        current = current.dirpath()
     #parentdirmatch = classmethod(parentdirmatch)
 
+def copychunked(src, dest): 
+    chunksize = 524288 # bytes
+    fsrc = src.open('rb')
+    try:
+        fdest = dest.open('wb')
+        try:
+            while 1:
+                buf = fsrc.read(chunksize)
+                if not buf:
+                    break
+                fdest.write(buf)
+        finally:
+            fdest.close()
+    finally:
+        fsrc.close()

Modified: py/dist/py/path/local/local_test.py
==============================================================================
--- py/dist/py/path/local/local_test.py	(original)
+++ py/dist/py/path/local/local_test.py	Thu Oct 14 02:04:02 2004
@@ -310,10 +310,10 @@
         oldmodes = {}
         for x in self.root.visit(rec=recfilter):
             oldmodes[x] = x.mode()
-        self.root.chmod(0577, rec=1)
+        self.root.chmod(0772, rec=1)
         try:
             for x in self.root.visit(rec=recfilter):
-                assert x.mode() & 0777 == 0577 
+                assert x.mode() & 0777 == 0772 
         finally:
             for x,y in oldmodes.items():
                 x.chmod(y) 

Modified: py/dist/py/path/pypath/pypath_test.py
==============================================================================
--- py/dist/py/path/pypath/pypath_test.py	(original)
+++ py/dist/py/path/pypath/pypath_test.py	Thu Oct 14 02:04:02 2004
@@ -132,7 +132,7 @@
         assert path.py('os.path') == l[2]
         assert path.py('os.path.abspath') == l[3]
         
-class EvalTest:
+class TestEval:
     disabled = True
     def test_funccall(self):
         p = path.py('os.path.join("a", "b")')
@@ -147,7 +147,7 @@
         p = path.py('os.path.qwe("a", ')
         s = test.raises(ValueError, "p.resolve()")
 
-class ErrorTests:
+class TestErrors: 
     def test_FileNotFound(self):
         p = path.py('somesuch')
         test.raises(path.NotFound, p.resolve)

Modified: py/dist/py/path/svn/command.py
==============================================================================
--- py/dist/py/path/svn/command.py	(original)
+++ py/dist/py/path/svn/command.py	Thu Oct 14 02:04:02 2004
@@ -56,6 +56,13 @@
         else:
             self._svnwrite('mkdir')
 
+    def copy(self, target, msg=None):
+        #if getattr(target, '_rev', -1) !=-1: 
+        #    raise path.Invalid("target can't have a revision: %r" % target)
+        if not msg:
+            msg = "auto"
+        process.cmdexec("svn copy -m %r %s %s" %(msg, str(self), str(target)))
+
     def _propget(self, name):
         res = self._svn('propget', name)
         return res[:-1] # strip trailing newline

Modified: py/dist/py/path/svn/command_test.py
==============================================================================
--- py/dist/py/path/svn/command_test.py	(original)
+++ py/dist/py/path/svn/command_test.py	Thu Oct 14 02:04:02 2004
@@ -1,12 +1,24 @@
 import sys, os
-from py import test, path
+import py
 from py.__impl__.path.test import _svncommon 
 from py.__impl__.path.svnwc.command_test import getrepowc 
 
+count = 0
 class TestSvnCommandPath(_svncommon.CommonCommandAndBindingTests):
     def __init__(self):
         repo, wc = getrepowc() 
-        self.root = path.svnurl(repo)
+        self.root = py.path.svnurl(repo)
+
+    def test_copy_file(self):
+        global count
+        count += 1
+        if count == 2:
+            raise ValueError
+        raise py.test.run.Skipped(msg="XXX fix svnurl first")
+
+    def test_copy_dir(self):
+        raise py.test.run.Skipped(msg="XXX fix svnurl first")
+        pass
 
     def XXXtest_info_log(self):
         url = self.root.join("samplefile")
@@ -15,6 +27,3 @@
         from time import gmtime
         t = gmtime(res[0].date)
         assert t.tm_year == 2003 and t.tm_mon == 7 and t.tm_mday == 17
-
-if __name__ == '__main__':
-    main()

Modified: py/dist/py/path/svn/common.py
==============================================================================
--- py/dist/py/path/svn/common.py	(original)
+++ py/dist/py/path/svn/common.py	Thu Oct 14 02:04:02 2004
@@ -223,7 +223,6 @@
 
         If the Path is not relative to the given base, return an empty string. 
         """
-
         relpath = rel.strpath
         if self.strpath.startswith(relpath):
             return self.strpath[len(relpath)+1:]

Modified: py/dist/py/path/svnwc/command.py
==============================================================================
--- py/dist/py/path/svnwc/command.py	(original)
+++ py/dist/py/path/svnwc/command.py	Thu Oct 14 02:04:02 2004
@@ -9,7 +9,8 @@
 """
 
 import os, sys, time, re
-from py import path, process
+from py import path
+import py 
 from py.__impl__.path import common 
 from py.__impl__.path.svn import cache
 from py.__impl__.path.svn import common as svncommon 
@@ -20,8 +21,6 @@
     sep = os.sep
 
     def __new__(cls, wcpath=None, url=None):
-        if isinstance(wcpath, XSvnWCCommandPath):
-            return wcpath
         self = object.__new__(cls)
         self.localpath = path.local(wcpath)
         self._url = url
@@ -30,13 +29,7 @@
     strpath = property(lambda x: str(x.localpath), None, None, "string path")
 
     def __eq__(self, other):
-        if self.localpath == other.localpath:
-            if self._url == other._url:
-                return True
-            else:
-                if self.url == other.url:
-                    return True
-        return False
+        return self.localpath == getattr(other, 'localpath', None) 
 
     def _geturl(self):
         if self._url is None:
@@ -70,7 +63,7 @@
         string = svncommon.fixlocale() + " ".join(l)
         if DEBUG:
             print "execing", string
-        out = process.cmdexec(string)
+        out = py.process.cmdexec(string)
         return out
 
     def checkout(self, rev = None, url=None):
@@ -129,7 +122,7 @@
     def add(self):
         self._svn('add')
 
-    def remove(self, force=0, rec=1):
+    def remove(self, rec=1, force=1): 
         """ remove a file or a directory tree. 'rec'ursive is 
             ignored and considered always true (because of 
             underlying svn semantics. 
@@ -139,6 +132,9 @@
             flags.append('--force')
         self._svn('remove', *flags)
 
+    def copy(self, target):
+        py.process.cmdexec("svn copy %s %s" %(str(self), str(target)))
+
     def status(self, updates=0, rec=0):
         """ return (collective) Status object for this file. """
         # http://svnbook.red-bean.com/book.html#svn-ch-3-sect-4.3.1 
@@ -305,7 +301,7 @@
         if not info:
             try:
                 output = self._svn('info')
-            except process.cmdexec.Error, e:
+            except py.process.cmdexec.Error, e:
                 if e.err.find('Path is not a working copy directory') != -1:
                     raise path.NotFound, e.err
                 raise
@@ -356,7 +352,7 @@
         def versioned(self):
             try:
                 s = self.svnwcpath.status()
-            except process.cmdexec.Error, e:
+            except py.process.cmdexec.Error, e:
                 if e.err.find('is not a working copy')!=-1:
                     return False
                 raise

Modified: py/dist/py/path/svnwc/command_test.py
==============================================================================
--- py/dist/py/path/svnwc/command_test.py	(original)
+++ py/dist/py/path/svnwc/command_test.py	Thu Oct 14 02:04:02 2004
@@ -198,8 +198,7 @@
     #   l = self.root.log()
     #   assert len(l) == 3  # might need to be upped if more tests are added
 
-class TestWCSvnCommandPathSpecial:
-    disabled = True
+class XTestWCSvnCommandPathSpecial:
 
     rooturl = 'http://codespeak.net/svn/py.path/trunk/dist/py.path/test/data'
     #def test_update_none_rev(self):
@@ -211,6 +210,3 @@
     #        assert wcpath.info().rev > 2100
     #    finally:
     #        wcpath.localpath.remove(rec=1)
-
-if __name__ == '__main__':
-    test.main()

Modified: py/dist/py/path/test/_common.py
==============================================================================
--- py/dist/py/path/test/_common.py	(original)
+++ py/dist/py/path/test/_common.py	Thu Oct 14 02:04:02 2004
@@ -56,10 +56,11 @@
         assert newpath.check(notbasename='xyz') 
         assert newpath.basename == 'sampledir'
 
-    #def test_ext_direct(self):
-    #    newpath = self.root.join('sampledir.ext')
-    #    check.true(newpath.check(basename='sampledir.ext'))
-    #    check.equal(newpath.ext(), '.ext')
+    def test_ext(self):
+        newpath = self.root.join('sampledir.ext')
+        assert newpath.ext == '.ext' 
+        newpath = self.root.join('sampledir')
+        assert not newpath.ext  
 
     def test_basename(self):
         newpath = self.root.join('sampledir')
@@ -293,3 +294,31 @@
         for name in dir(local.Checkers):
             if name[0] != '_':
                 assert name in doc 
+
+    def test_copy_file(self):
+        otherdir = self.root.join('otherdir') 
+        initpy = otherdir.join('__init__.py')
+        copied = otherdir.join('copied') 
+        initpy.copy(copied)
+        try:
+            assert copied.check()
+            s1 = initpy.read()
+            s2 = copied.read()
+            assert s1 == s2 
+        finally:
+            if copied.check():
+                copied.remove()
+
+    def test_copy_dir(self):
+        otherdir = self.root.join('otherdir') 
+        copied = self.root.join('newdir') 
+        try:
+            otherdir.copy(copied)
+            assert copied.check(dir=1)
+            assert copied.join('__init__.py').check(file=1)
+            s1 = otherdir.join('__init__.py').read()
+            s2 = copied.join('__init__.py').read()
+            assert s1 == s2 
+        finally:
+            if copied.check(dir=1):
+                copied.remove(rec=1)

Modified: py/dist/py/path/test/_svncommon.py
==============================================================================
--- py/dist/py/path/test/_svncommon.py	(original)
+++ py/dist/py/path/test/_svncommon.py	Thu Oct 14 02:04:02 2004
@@ -2,11 +2,9 @@
 
 from py import path, test, process
 from py.__impl__.path.test import _common 
-from py.__impl__.path.test import _common 
 from py.__impl__.path.svn import cache 
 
 class CommonSvnTests(_common.CommonFSTests):
-
     def test_propget(self):
         url = self.root.join("samplefile")
         value = url.propget('svn:eol-style')
@@ -31,7 +29,6 @@
         assert t.tm_year == 2003 and t.tm_mon == 7 and t.tm_mday == 17
 
 class CommonCommandAndBindingTests(CommonSvnTests):
-
     def test_trailing_slash_is_stripped(self):
         # XXX we need to test more normalizing properties
         url = self.root.join("/")

Deleted: /py/dist/py/path/test/test_svn_binding.py
==============================================================================
--- /py/dist/py/path/test/test_svn_binding.py	Thu Oct 14 02:04:02 2004
+++ (empty file)
@@ -1 +0,0 @@
-import sys, os

Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py	(original)
+++ py/dist/py/test/collect.py	Thu Oct 14 02:04:02 2004
@@ -67,7 +67,7 @@
     def __iter__(self):
         try:
             self.fspath.stat() # to throw correct filenotfound errors
-            name = self.fspath.get('purebasename')
+            name = "%s_%s" % (self.fspath.dirpath().basename, self.fspath.purebasename )
             mod = imp.load_source(name, str(self.fspath)) 
             mod.__name__ = name
             pypath = path.py('', ns=mod)
@@ -145,7 +145,7 @@
 
     def collect_class(self, pypath):
         #print "checking %r (pypath: %r)" % (pypath.resolve(), pypath)
-        if self.samemodule(pypath):
+        if pypath.check(basestarts='Test') and self.samemodule(pypath):
             obj = pypath.resolve()
             if inspect.isclass(obj) and not getattr(obj, 'disabled', 0):
                 yield Class(pypath)

Modified: py/dist/py/test/collect_test.py
==============================================================================
--- py/dist/py/test/collect_test.py	(original)
+++ py/dist/py/test/collect_test.py	Thu Oct 14 02:04:02 2004
@@ -58,7 +58,7 @@
         #    assert isinstance(x, Unit) 
         #    x.execute() 
         
-class someclass:
+class Testsomeclass:
     disabled = True
     def test_something():
         raise ValueError
@@ -70,15 +70,15 @@
     l.append(2)
 def test_3():
     assert l == [1,2]
-class mygroup:
+class Testmygroup:
     reslist = []
     def test_1(self):
-        mygroup.reslist.append(1)
+        self.reslist.append(1)
     def test_2(self):
-        mygroup.reslist.append(2)
+        self.reslist.append(2)
     def test_3(self):
-        mygroup.reslist.append(3)
+        self.reslist.append(3)
     def test_4(self):
-        assert mygroup.reslist == [1,2,3]
+        assert self.reslist == [1,2,3]
 
 test.main()

Modified: py/dist/py/test/compat_test.py
==============================================================================
--- py/dist/py/test/compat_test.py	(original)
+++ py/dist/py/test/compat_test.py	Thu Oct 14 02:04:02 2004
@@ -1,7 +1,7 @@
 from __future__ import generators
 from py import test, magic
 
-class CompatTestCaseSetupSemantics(test.compat.TestCase): 
+class TestCompatTestCaseSetupSemantics(test.compat.TestCase): 
     globlist = []
 
     def setUp(self):
@@ -27,7 +27,7 @@
         for x,y in zip(self.globlist, self.globlist[1:]):
             assert x is not y
 
-class DynTestCase(test.compat.TestCase):
+class TestCompatAssertions(test.compat.TestCase):
     nameparamdef = {
         'failUnlessEqual,assertEqual,assertEquals': ('1, 1', '1, 0'),
         'assertNotEquals,failIfEqual': ('0, 1', '0,0'),

Modified: py/dist/py/test/raises_test.py
==============================================================================
--- py/dist/py/test/raises_test.py	(original)
+++ py/dist/py/test/raises_test.py	Thu Oct 14 02:04:02 2004
@@ -3,7 +3,7 @@
 def somefunc(x, y):
     assert x == y
 
-class classes_are_arbitrary_grouping:
+class TestClass: 
     def test_raises(self):
         test.raises(ValueError, "int('qwe')")
 



More information about the pytest-commit mailing list