本文整理汇总了Python中ulif.openoffice.cachemanager.CacheManager类的典型用法代码示例。如果您正苦于以下问题:Python CacheManager类的具体用法?Python CacheManager怎么用?Python CacheManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CacheManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_all_sources
def test_get_all_sources(self):
cm = CacheManager(self.workdir)
result1 = cm.getAllSources()
self.assertTrue(isinstance(result1, types.GeneratorType))
self.assertEqual(list(result1), [])
cm.registerDoc(
self.src_path1, self.result_path1, suffix=None)
cm.registerDoc(
self.src_path2, self.result_path2, suffix='foo')
result2 = list(cm.getAllSources())
self.assertTrue(len(result2) == 2)
open(os.path.join(self.workdir, 'crapfile'), 'wb').write('crap')
result3 = list(cm.getAllSources())
self.assertFalse('crap' in result3)
os.mkdir(os.path.join(self.workdir, 'crapdir'))
result4 = list(cm.getAllSources())
self.assertFalse('crapdir' in result4)
os.makedirs(os.path.join(self.workdir, '66', 'invalid_hashdir'))
result5 = list(cm.getAllSources())
self.assertFalse('66' in result5)
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:25,代码来源:test_cachemanager.py
示例2: test_get_cached_file_by_src_failed
def test_get_cached_file_by_src_failed(self, cache_env):
# uncached files result in `None` as result
cm = CacheManager(str(cache_env))
result, key = cm.get_cached_file_by_source(
str(cache_env / "src1.txt"))
assert result is None
assert key is None
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:7,代码来源:test_cachemanager.py
示例3: test_prepare_cache_dir_broken
def test_prepare_cache_dir_broken(self, tmpdir):
# we fail loudly if we cannot create a cache dir
cm = CacheManager(str(tmpdir))
tmpdir.join("not-a-dir.txt").write("foo") # broken dir
cm.cache_dir = str(tmpdir / "not-a-dir.txt")
with pytest.raises(IOError):
cm._prepare_cache_dir()
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:7,代码来源:test_cachemanager.py
示例4: test_prepare_cache_dir
def test_prepare_cache_dir(self, tmpdir):
# _prepare_cache_dir creates a cache dir normally
cm = CacheManager(str(tmpdir.join("cache")))
new_dir = tmpdir.join("new_dir")
cm.cache_dir = str(new_dir)
cm._prepare_cache_dir()
assert new_dir.isdir() is True
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:7,代码来源:test_cachemanager.py
示例5: test_get_bucket_path
def test_get_bucket_path(self, tmpdir):
# we can get a bucket path from a hash value
cm = CacheManager(str(tmpdir.join("cache")))
tmpdir.join("src.txt").write("source1\n")
hash_val = cm.get_hash(str(tmpdir / "src.txt"))
assert cm._get_bucket_path(hash_val) == (
tmpdir / "cache" / "73" / "737b337e605199de28b3b64c674f9422")
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:7,代码来源:test_cachemanager.py
示例6: test_get_cached_file_by_src
def test_get_cached_file_by_src(self):
# we can get a cached file by source file and options
cm = CacheManager(self.workdir)
# without a cache key
my_id1 = cm.register_doc(self.src_path1, self.result_path1)
result, key = cm.get_cached_file_by_source(self.src_path1)
assert filecmp.cmp(result, self.result_path1, shallow=False)
assert key == '737b337e605199de28b3b64c674f9422_1_1'
开发者ID:sennoy,项目名称:ulif.openoffice,代码行数:8,代码来源:test_cachemanager.py
示例7: test_get_bucket_path_from_path
def test_get_bucket_path_from_path(self):
cm = CacheManager(self.workdir)
path = cm._getBucketPathFromPath(self.src_path1)
expected_path_end = os.path.join(
'73', '737b337e605199de28b3b64c674f9422')
self.assertEqual(os.listdir(self.workdir), [])
self.assertTrue(path.endswith(expected_path_end))
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:8,代码来源:test_cachemanager.py
示例8: test_get_bucket_from_path
def test_get_bucket_from_path(self):
cache_dir_len1 = len(os.listdir(self.workdir))
cm = CacheManager(self.workdir)
bucket1 = cm.getBucketFromPath(self.src_path1)
cache_dir_len2 = len(os.listdir(self.workdir))
self.assertTrue(isinstance(bucket1, Bucket))
self.assertTrue(cache_dir_len2 == cache_dir_len1+1)
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:8,代码来源:test_cachemanager.py
示例9: test_get_hash
def test_get_hash(self):
cm = CacheManager(self.workdir)
hash1 = cm.getHash(self.src_path1)
hash2 = cm.getHash(self.src_path2)
self.assertEqual(hash1, '737b337e605199de28b3b64c674f9422')
self.assertEqual(hash2, 'd5aa51d7fb180729089d2de904f7dffe')
self.assertRaises(TypeError, cm.getHash)
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:8,代码来源:test_cachemanager.py
示例10: register_fakedoc_in_cache
def register_fakedoc_in_cache(self, src, options):
# register a fake doc in cache. Result cache_key is based on
# path to src document and options given.
cm = CacheManager(self.cachedir)
fake_result_path = os.path.join(self.workdir, 'result.html')
open(fake_result_path, 'w').write('A fake result.')
marker = get_marker(options)
cache_key = cm.register_doc(src, fake_result_path, repr_key=marker)
return cache_key
开发者ID:ulif,项目名称:psj.policy,代码行数:9,代码来源:test_odt_to_html.py
示例11: test_get_cached_file
def test_get_cached_file(self, cache_env):
# we can get a file cached before.
cm = CacheManager(str(cache_env / "cache"))
cache_key = cm.register_doc(
str(cache_env / "src1.txt"),
str(cache_env / "result1.txt"))
path = cm.get_cached_file(cache_key)
assert path is not None
assert open(path, 'r').read() == (
cache_env / "result1.txt").read()
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:10,代码来源:test_cachemanager.py
示例12: test_markerhandling
def test_markerhandling(self, tmpdir):
# we can dissolve markers from cache_keys.
cm = CacheManager(str(tmpdir))
marker_string = cm._compose_cache_key('somefakedhash', 3)
assert marker_string == "somefakedhash_3"
hash_val, bucket_marker = cm._dissolve_cache_key("somefakedhash_3")
assert hash_val == "somefakedhash"
assert bucket_marker == "3"
assert cm._dissolve_cache_key("asd") == (None, None)
assert cm._dissolve_cache_key(None) == (None, None)
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:10,代码来源:test_cachemanager.py
示例13: test_get_hash
def test_get_hash(self, cache_env, samples_dir):
# we can compute a hash for a source file.
cm = CacheManager(str(cache_env))
hash1 = cm.get_hash(str(cache_env / "src1.txt"))
hash2 = cm.get_hash(str(cache_env / "src2.txt"))
hash3 = cm.get_hash(str(samples_dir / "testdoc1.doc"))
assert hash1 == '737b337e605199de28b3b64c674f9422'
assert hash2 == 'd5aa51d7fb180729089d2de904f7dffe'
assert hash3 == '443a07e0e92b7dc6b21f8be6a388f05f'
with pytest.raises(TypeError):
cm.get_hash()
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:11,代码来源:test_cachemanager.py
示例14: test_get_cached_file_w_key_from_file
def test_get_cached_file_w_key_from_file(self, cache_env):
# we can get a cached file, stored under a key, which is a file
cm = CacheManager(str(cache_env / "cache"))
cache_key = cm.register_doc(
str(cache_env / "src1.txt"),
str(cache_env / "result1.txt"),
repr_key=StringIO('foo'))
path = cm.get_cached_file(cache_key)
assert path is not None
assert open(path, 'r').read() == (
cache_env / "result1.txt").read()
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:11,代码来源:test_cachemanager.py
示例15: test_get_cached
def test_get_cached(self):
# we can get cached docs
cm = CacheManager(self.cachedir)
fake_result_path = os.path.join(self.src_dir, 'result.txt')
open(fake_result_path, 'wb').write('The Result\n')
key = cm.register_doc(self.src_path, fake_result_path, 'somekey')
assert key == '2b87e29fca6ee7f1df6c1a76cb58e101_1_1'
result_path = self.proxy.get_cached(key)
assert result_path is not None
assert result_path != fake_result_path
assert filecmp.cmp(result_path, fake_result_path, shallow=False)
开发者ID:sennoy,项目名称:ulif.openoffice,代码行数:11,代码来源:test_xmlrpc.py
示例16: test_markerhandling
def test_markerhandling(self):
cm = CacheManager(self.workdir)
marker_string = cm._composeMarker(
'somefakedhash', 3)
self.assertEqual(marker_string, 'somefakedhash_3')
hash, bucket_marker = cm._dissolveMarker('somefakedhash_3')
self.assertEqual(hash, 'somefakedhash')
self.assertEqual(bucket_marker, '3')
self.assertEqual(cm._dissolveMarker('asd'), (None, None))
self.assertEqual(cm._dissolveMarker(object()), (None, None))
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:11,代码来源:test_cachemanager.py
示例17: test_get_bucket_path_from_hash
def test_get_bucket_path_from_hash(self):
cm = CacheManager(self.workdir)
hash_val = cm.getHash(self.src_path1)
path = cm._getBucketPathFromHash(hash_val)
expected_path_end = os.path.join(
'73', '737b337e605199de28b3b64c674f9422')
self.assertEqual(os.listdir(self.workdir), [])
self.assertTrue(path.endswith(expected_path_end))
path = cm._getBucketPathFromHash('nonsense')
self.assertEqual(path, None)
return
开发者ID:silviot,项目名称:ulif.openoffice,代码行数:12,代码来源:test_cachemanager.py
示例18: test_get_hash
def test_get_hash(self):
cm = CacheManager(self.workdir)
hash1 = cm.get_hash(self.src_path1)
hash2 = cm.get_hash(self.src_path2)
src = os.path.join( # a binary stream not convertible to utf-8
os.path.dirname(__file__), 'input', 'testdoc1.doc')
hash3 = cm.get_hash(src)
self.assertEqual(hash1, '737b337e605199de28b3b64c674f9422')
self.assertEqual(hash2, 'd5aa51d7fb180729089d2de904f7dffe')
self.assertEqual(hash3, '443a07e0e92b7dc6b21f8be6a388f05f')
self.assertRaises(TypeError, cm.get_hash)
return
开发者ID:sennoy,项目名称:ulif.openoffice,代码行数:12,代码来源:test_cachemanager.py
示例19: test_get_cached_file_by_src
def test_get_cached_file_by_src(self, cache_env):
# we can get a cached file by source file and options
cm = CacheManager(str(cache_env / "cache"))
# without a cache key
my_id = cm.register_doc(
str(cache_env / "src1.txt"),
str(cache_env / "result1.txt"))
path, key = cm.get_cached_file_by_source(
str(cache_env / "src1.txt"))
assert open(path, "r").read() == (
cache_env / "result1.txt").read()
assert key == '737b337e605199de28b3b64c674f9422_1_1'
assert my_id == key
开发者ID:sbywater,项目名称:ulif.openoffice,代码行数:13,代码来源:test_cachemanager.py
示例20: test_convert_to_pdf_cached_wo_cache_key
def test_convert_to_pdf_cached_wo_cache_key(self):
# We can get a cached doc also without a cache key (but
# it is extensive)
self.doc = Document('mytestdoc.doc', self.doc_simple1, self.workdir)
pdf1, cache_key1 = self.doc.convertToPDF() # store doc in cache
# modfiy result to distuingish it from freshly converted doc
from ulif.openoffice.cachemanager import CacheManager
cm = CacheManager(self.workdir)
cached_path = cm.get_cached_file(cache_key1)
open(cached_path, 'wb').write('My Fake Result')
# now re-get the document. We should get the cached copy
self.doc = Document('mytestdoc.doc', self.doc_simple1, self.workdir)
pdf2, cache_key2 = self.doc.convertToPDF()
self.assertEqual(pdf2, 'My Fake Result')
self.assertEqual(cache_key2, cache_key1)
开发者ID:ulif,项目名称:psj.policy,代码行数:15,代码来源:test_cmd_oooconv.py
注:本文中的ulif.openoffice.cachemanager.CacheManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论