Example #1
0
class TestBuildcostAccess(BasicCacheAPITest):
    cache = BuildcostAccessCache(maxentries=128)

    def test_cache_works_somewhat_simple(self):
        cache = BuildcostAccessCache()
        # the default ._time() call used by
        # BuildcostAccessCache.build can
        # result into time()-time() == 0 which makes the below
        # test fail randomly.  Let's rather use incrementing
        # numbers instead.
        cache._time = py.std.itertools.count().next
        for x in range(cache.maxentries):
            y = cache.getorbuild(x, lambda: x)
            assert x == y
        for x in range(cache.maxentries):
            assert cache.getorbuild(x, None) == x
        for x in range(cache.maxentries / 2):
            assert cache.getorbuild(x, None) == x
            assert cache.getorbuild(x, None) == x
            assert cache.getorbuild(x, None) == x
        val = cache.getorbuild(cache.maxentries * 2, lambda: 42)
        assert val == 42
        # check that recently used ones are still there
        # and are not build again
        for x in range(cache.maxentries / 2):
            assert cache.getorbuild(x, None) == x
        assert cache.getorbuild(cache.maxentries * 2, None) == 42
Example #2
0
 def test_cache_works_somewhat_simple(self):
     cache = BuildcostAccessCache()
     for x in range(cache.maxentries):
         y = cache.getorbuild(x, lambda: x)
         assert x == y
     for x in range(cache.maxentries):
         assert cache.getorbuild(x, None) == x
     for x in range(cache.maxentries/2):
         assert cache.getorbuild(x, None) == x
         assert cache.getorbuild(x, None) == x
         assert cache.getorbuild(x, None) == x
     val = cache.getorbuild(cache.maxentries * 2, lambda: 42)
     assert val == 42
     # check that recently used ones are still there
     # and are not build again
     for x in range(cache.maxentries/2):
         assert cache.getorbuild(x, None) == x
     assert cache.getorbuild(cache.maxentries*2, None) == 42
Example #3
0
 def test_cache_works_somewhat_simple(self):
     cache = BuildcostAccessCache()
     # the default ._time() call used by
     # BuildcostAccessCache.build can 
     # result into time()-time() == 0 which makes the below
     # test fail randomly.  Let's rather use incrementing
     # numbers instead. 
     cache._time = py.std.itertools.count().next
     for x in range(cache.maxentries):
         y = cache.getorbuild(x, lambda: x)
         assert x == y
     for x in range(cache.maxentries):
         assert cache.getorbuild(x, None) == x
     for x in range(cache.maxentries/2):
         assert cache.getorbuild(x, None) == x
         assert cache.getorbuild(x, None) == x
         assert cache.getorbuild(x, None) == x
     val = cache.getorbuild(cache.maxentries * 2, lambda: 42)
     assert val == 42
     # check that recently used ones are still there
     # and are not build again
     for x in range(cache.maxentries/2):
         assert cache.getorbuild(x, None) == x
     assert cache.getorbuild(cache.maxentries*2, None) == 42
Example #4
0
class SvnCommandPath(svncommon.SvnPathBase):
    """ path implementation that offers access to (possibly remote) subversion
    repositories. """

    _lsrevcache = BuildcostAccessCache(maxentries=128)
    _lsnorevcache = AgingCache(maxentries=1000, maxseconds=60.0)

    def __new__(cls, path, rev=None, auth=None):
        self = object.__new__(cls)
        if isinstance(path, cls):
            rev = path.rev
            auth = path.auth
            path = path.strpath
        svncommon.checkbadchars(path)
        path = path.rstrip('/')
        self.strpath = path
        self.rev = rev
        self.auth = auth
        return self

    def __repr__(self):
        if self.rev == -1:
            return 'svnurl(%r)' % self.strpath
        else:
            return 'svnurl(%r, %r)' % (self.strpath, self.rev)

    def _svnwithrev(self, cmd, *args):
        """ execute an svn command, append our own url and revision """
        if self.rev is None:
            return self._svnwrite(cmd, *args)
        else:
            args = ['-r', self.rev] + list(args)
            return self._svnwrite(cmd, *args)

    def _svnwrite(self, cmd, *args):
        """ execute an svn command, append our own url """
        l = ['svn %s' % cmd]
        args = ['"%s"' % self._escape(item) for item in args]
        l.extend(args)
        l.append('"%s"' % self._encodedurl())
        # fixing the locale because we can't otherwise parse
        string = " ".join(l)
        if DEBUG:
            print "execing", string
        out = self._svncmdexecauth(string)
        return out

    def _svncmdexecauth(self, cmd):
        """ execute an svn command 'as is' """
        cmd = svncommon.fixlocale() + cmd
        if self.auth is not None:
            cmd += ' ' + self.auth.makecmdoptions()
        return self._cmdexec(cmd)

    def _cmdexec(self, cmd):
        try:
            out = process.cmdexec(cmd)
        except py.process.cmdexec.Error, e:
            if (e.err.find('File Exists') != -1
                    or e.err.find('File already exists') != -1):
                raise py.error.EEXIST(self)
            raise
        return out