コード例 #1
0
ファイル: test_misc.py プロジェクト: sjl421/pony-build
def test_create_cache_dir():
    """
    Test to make sure that create_cache_dir() does the right path calculation.
    """
    
    # build a fake cache_dir location
    tempdir = tempfile.mkdtemp()
    fake_dir = os.path.join(tempdir, 'CACHE_DIR')
    fake_pkg = os.path.join(fake_dir, 'SOME_PACKAGE')
    
    # use dependency injection to replace 'os.path.isdir' and 'os.mkdir'
    # in order to test create_cache_dir.
    def false(X):
        return False

    def noop(Y, expected_dirname=fake_dir):
        print 'NOOP GOT', Y
        Y = Y.rstrip(os.path.sep)
        expected_dirname = expected_dirname.rstrip(os.path.sep)
        
        assert Y == expected_dirname, \
               'fake mkdir got %s, expected %s' % (Y, expected_dirname)

    # replace stdlib functions
    _old_isdir, os.path.isdir = os.path.isdir, false
    _old_mkdir, os.mkdir = os.mkdir, noop

    try:
        pony_client.create_cache_dir(fake_pkg, 'SOME_PACKAGE')
        # here, the 'noop' function is actually doing the test.
    finally:
        # put stdlib functions back
        os.path.isdir, os.mkdir = _old_isdir, _old_mkdir
        shutil.rmtree(tempdir)
コード例 #2
0
def create_cache_location(repository_url):
    # use os.environ to specify a new place for VCS cache stuff
    temp_cache_parent = tempfile.mkdtemp()
    temp_cache_location = os.path.join(temp_cache_parent, "the_cache")
    os.environ['PONY_BUILD_CACHE'] = temp_cache_location

    # figure out what the end checkout result should be
    repository_path = urlparse.urlparse(repository_url)[2]
    repository_dirname = repository_path.rstrip('/').split('/')[-1]

    print 'calculated repository dirname as:', repository_dirname

    (_, repository_cache) = pony_client.guess_cache_dir(repository_dirname)
    assert repository_cache.startswith(temp_cache_location)

    # this will create 'the_cache' directory that contains individual
    # pkg caches.
    pony_client.create_cache_dir(repository_cache, repository_dirname)
    assert os.path.isdir(temp_cache_location)

    return (temp_cache_parent, temp_cache_location)