本文整理汇总了Python中pitz.project.Project.to_pickle方法的典型用法代码示例。如果您正苦于以下问题:Python Project.to_pickle方法的具体用法?Python Project.to_pickle怎么用?Python Project.to_pickle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pitz.project.Project
的用法示例。
在下文中一共展示了Project.to_pickle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFromPitzdir
# 需要导入模块: from pitz.project import Project [as 别名]
# 或者: from pitz.project.Project import to_pickle [as 别名]
class TestFromPitzdir(unittest.TestCase):
def setUp(self):
self.p = Project(pathname='/tmp')
self.p.to_yaml_file()
self.p.to_pickle()
def tearDown(self):
for f in glob.glob('/tmp/*.yaml'):
os.unlink(f)
if os.path.isfile('/tmp/project.pickle'):
os.unlink('/tmp/project.pickle')
def test_fresh_pickle(self):
"""
Verify we use the pickle when we can.
"""
p = Project.from_pitzdir('/tmp')
assert p.loaded_from == 'pickle', p.loaded_from
def test_stale_pickle(self):
"""
Verify we use the yaml files when the pickle is too old.
"""
stat = os.stat('/tmp/project.pickle')
os.utime('/tmp/project.pickle',
(stat.st_atime-1, stat.st_mtime-1))
print("pickle file: %s"
% os.stat('/tmp/project.pickle').st_mtime)
print("newest yaml file: %s"
% max([os.stat(f).st_mtime for f in glob.glob('/tmp/*.yaml')]))
p = Project.from_pitzdir('/tmp')
assert p.loaded_from == 'yaml', p.loaded_from
def test_from_yaml_files(self):
"""
Verify we can use the yaml files when no pickle exists.
"""
os.unlink('/tmp/project.pickle')
p = Project.from_pitzdir('/tmp')
assert p.loaded_from == 'yaml', p.loaded_from
示例2: TestPicklingProject
# 需要导入模块: from pitz.project import Project [as 别名]
# 或者: from pitz.project.Project import to_pickle [as 别名]
class TestPicklingProject(unittest.TestCase):
def setUp(self):
self.p = Project()
self.c = Entity(self.p, title="c")
self.e = Entity(self.p, title="t", c=self.c)
def tearDown(self):
self.c.self_destruct(self.p)
self.e.self_destruct(self.p)
if os.path.exists('/tmp/project.pickle'):
os.remove('/tmp/project.pickle')
def test_to_pickle1(self):
self.assertRaises(
ValueError,
self.p.to_pickle)
def test_to_pickle2(self):
self.p.to_pickle('/tmp')
assert os.path.exists('/tmp/project.pickle')
def test_unpickle(self):
assert not os.path.exists('/tmp/project.pickle')
self.p.to_pickle('/tmp')
assert os.path.exists('/tmp/project.pickle')
new_p = Project.from_pickle('/tmp/project.pickle')
assert self.p.length == new_p.length
assert new_p.length
for e in new_p:
assert e.project