本文整理汇总了Python中nengo.cache.DecoderCache.get_files方法的典型用法代码示例。如果您正苦于以下问题:Python DecoderCache.get_files方法的具体用法?Python DecoderCache.get_files怎么用?Python DecoderCache.get_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nengo.cache.DecoderCache
的用法示例。
在下文中一共展示了DecoderCache.get_files方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decoder_cache_shrinking
# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import get_files [as 别名]
def test_decoder_cache_shrinking(tmpdir):
cache_dir = str(tmpdir)
solver_mock = SolverMock()
another_solver = SolverMock('another_solver')
cache = DecoderCache(cache_dir=cache_dir)
cache.wrap_solver(solver_mock)(**get_solver_test_args())
# Ensure differing time stamps (depending on the file system the timestamp
# resolution might be as bad as 1 day).
for path in cache.get_files():
timestamp = os.stat(path).st_atime
timestamp -= 60 * 60 * 24 * 2 # 2 days
os.utime(path, (timestamp, timestamp))
cache.wrap_solver(another_solver)(**get_solver_test_args())
cache_size = cache.get_size_in_bytes()
assert cache_size > 0
cache.shrink(cache_size - 1)
# check that older cached result was removed
assert SolverMock.n_calls[solver_mock] == 1
cache.wrap_solver(another_solver)(**get_solver_test_args())
cache.wrap_solver(solver_mock)(**get_solver_test_args())
assert SolverMock.n_calls[solver_mock] == 2
assert SolverMock.n_calls[another_solver] == 1
示例2: test_decoder_cache_size_includes_overhead
# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import get_files [as 别名]
def test_decoder_cache_size_includes_overhead(tmpdir):
cache_dir = str(tmpdir)
solver_mock = SolverMock()
cache = DecoderCache(cache_dir=cache_dir)
cache.wrap_solver(solver_mock)(**get_solver_test_args())
fragment_size = get_fragment_size(cache_dir)
actual_size = sum(os.stat(p).st_size for p in cache.get_files())
assert actual_size % fragment_size != 0, (
'Test succeeded by chance. Adjust get_solver_test_args() to produce '
'date not aligned with the files system fragment size.')
assert cache.get_size_in_bytes() % fragment_size == 0
示例3: test_corrupted_decoder_cache
# 需要导入模块: from nengo.cache import DecoderCache [as 别名]
# 或者: from nengo.cache.DecoderCache import get_files [as 别名]
def test_corrupted_decoder_cache(tmpdir):
cache_dir = str(tmpdir)
cache = DecoderCache(cache_dir=cache_dir)
solver_mock = SolverMock()
cache.wrap_solver(solver_mock)(**get_solver_test_args())
assert SolverMock.n_calls[solver_mock] == 1
# corrupt the cache
for path in cache.get_files():
with open(path, 'w') as f:
f.write('corrupted')
cache.wrap_solver(solver_mock)(**get_solver_test_args())
assert SolverMock.n_calls[solver_mock] == 2