tests.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:python-npm-accel 作者: xolox 项目源码 文件源码
def test_cache_cleaning(self):
        """Make sure the automatic cache cleaning logic works as expected."""
        with TemporaryDirectory() as cache_directory:
            context = create_context()
            accelerator = NpmAccel(context=context, cache_directory=cache_directory)
            just_above_limit = accelerator.cache_limit + 1
            for i in range(just_above_limit):
                # Create a fake (empty) tar archive.
                fingerprint = random_string(length=40, characters=string.hexdigits)
                filename = os.path.join(cache_directory, '%s.tar' % fingerprint)
                context.write_file(filename, '')
                # Create the cache metadata.
                accelerator.write_metadata(filename)
            # Sanity check the cache entries.
            assert len(list(accelerator.find_archives())) == just_above_limit
            # Run the cleanup.
            accelerator.clean_cache()
            # Make sure the number of cache entries decreased.
            assert len(list(accelerator.find_archives())) == accelerator.cache_limit
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号