Exemplo n.º 1
0
 def test_cache_iterator(self):
     """Test that files added to the cache show up in the iterator
     and are accessed correctly via 'in'
     """
     cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
     make_path_to(cache.file_path('sha-1:someotherid'))
     open(cache.file_path('sha-1:someotherid'), 'w')\
             .write('helloalso')
     make_path_to(cache.file_path('md5:yetanotherid'))
     open(cache.file_path('md5:yetanotherid'), 'w') \
             .write('helloalso')
     contents = [x for x in cache]
     assert 'sha-1:someotherid' in cache
     assert 'sha-1:someotherid' in contents
     assert 'md5:yetanotherid' in cache
     assert 'md5:yetanotherid' in contents
Exemplo n.º 2
0
    def test_cache_files(self):
        # This is being invalidated by changes in cache layout

        # Open a local file
        open('hi.txt', 'w').write('hello')

        # Copy it into the cache
        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        cache.import_file(FileLocator('', 'hi.txt', None, None, None),
                          NullMassProgress())
        expected_blob_id = 'sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
        cache_file = cache.file_path(expected_blob_id)
        assert os.path.exists(cache_file), cache_file + " expected"
        assert (expected_blob_id in cache)
        self.assert_equal(os.path.abspath('cache/md5/th/md5:this-one-md5'),
                          os.path.abspath(cache.file_path('md5:this-one-md5')))
Exemplo n.º 3
0
 def test_cache_iterator(self):
     """Test that files added to the cache show up in the iterator
     and are accessed correctly via 'in'
     """
     cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
     make_path_to(cache.file_path('sha-1:someotherid'))
     open(cache.file_path('sha-1:someotherid'), 'w')\
             .write('helloalso')
     make_path_to(cache.file_path('md5:yetanotherid'))
     open(cache.file_path('md5:yetanotherid'), 'w') \
             .write('helloalso')
     contents = [ x for x in cache ]
     assert 'sha-1:someotherid' in cache
     assert 'sha-1:someotherid' in contents
     assert 'md5:yetanotherid' in cache
     assert 'md5:yetanotherid' in contents
Exemplo n.º 4
0
    def test_cache_files(self):
        # This is being invalidated by changes in cache layout

        # Open a local file
        open('hi.txt', 'w').write('hello')

        # Copy it into the cache
        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        cache.import_file(FileLocator('', 'hi.txt', None, None, None),
                          NullMassProgress())
        expected_blob_id = 'sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
        cache_file = cache.file_path(expected_blob_id)
        assert os.path.exists(cache_file), cache_file+" expected"
        assert(expected_blob_id in cache)
        self.assert_equal(
            os.path.abspath('cache/md5/th/md5:this-one-md5')
            , os.path.abspath(cache.file_path('md5:this-one-md5'))
            )
Exemplo n.º 5
0
    def test_acquire_file(self):
        """acquire file downloads the contents of the file_object.

        The contents should end up under the given tempoarary id.
        The return value should be new blob_ids."""

        open('test', 'w').write('hello')
        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        cache.import_file(FileLocator('', 'test', None, None, None),
                          NullMassProgress())
        expected_ids = ('sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d',
                        'md5:5d41402abc4b2a76b9719d911017c592')
        for expected_id in expected_ids:
            assert os.path.exists(cache.file_path(expected_id))
Exemplo n.º 6
0
    def test_acquire_file(self):
        """acquire file downloads the contents of the file_object.

        The contents should end up under the given tempoarary id.
        The return value should be new blob_ids."""

        open ('test', 'w').write('hello')
        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        cache.import_file(FileLocator('', 'test', None, None, None),
                          NullMassProgress())
        expected_ids = ('sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d',
                        'md5:5d41402abc4b2a76b9719d911017c592')
        for expected_id in expected_ids:
            assert os.path.exists(cache.file_path(expected_id))
Exemplo n.º 7
0
    def test_incorporate_file(self):
        """incorporate_file renames a blob to its new blob_ids"""

        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        blob_ids = ('sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d',
                    'md5:5d41402abc4b2a76b9719d911017c592')
        filepath = cache.make_download_filename()
        open(filepath, 'w').write('hello')
        cache.incorporate_file(filepath, blob_ids[0])

        for blob_id in blob_ids:
            filename = cache.file_path(blob_id)
            assert os.path.exists(filename)
            self.assert_equal('hello', open(filename).read())
        assert not os.path.exists('cache/oldid')
Exemplo n.º 8
0
    def test_incorporate_file(self):
        """incorporate_file renames a blob to its new blob_ids"""

        cache = pdk.cache.Cache(os.path.join(self.work_dir, 'cache'))
        blob_ids = ('sha-1:aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d',
                    'md5:5d41402abc4b2a76b9719d911017c592')
        filepath = cache.make_download_filename()
        open(filepath, 'w').write('hello')
        cache.incorporate_file(filepath, blob_ids[0])

        for blob_id in blob_ids:
            filename = cache.file_path(blob_id)
            assert os.path.exists(filename)
            self.assert_equal('hello', open(filename).read())
        assert not os.path.exists('cache/oldid')