本文整理汇总了Python中IPython.utils.tempdir.TemporaryDirectory类的典型用法代码示例。如果您正苦于以下问题:Python TemporaryDirectory类的具体用法?Python TemporaryDirectory怎么用?Python TemporaryDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemporaryDirectory类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PickleShareDBTestCase
class PickleShareDBTestCase(TestCase):
def setUp(self):
self.tempdir = TemporaryDirectory()
def tearDown(self):
self.tempdir.cleanup()
def test_picklesharedb(self):
db = PickleShareDB(self.tempdir.name)
db.clear()
print("Should be empty:", db.items())
db['hello'] = 15
db['aku ankka'] = [1, 2, 313]
db['paths/nest/ok/keyname'] = [1, (5, 46)]
db.hset('hash', 'aku', 12)
db.hset('hash', 'ankka', 313)
self.assertEqual(db.hget('hash', 'aku'), 12)
self.assertEqual(db.hget('hash', 'ankka'), 313)
print("all hashed", db.hdict('hash'))
print(db.keys())
print(db.keys('paths/nest/ok/k*'))
print(dict(db)) # snapsot of whole db
db.uncache() # frees memory, causes re-reads later
# shorthand for accessing deeply nested files
lnk = db.getlink('myobjects/test')
lnk.foo = 2
lnk.bar = lnk.foo + 5
self.assertEqual(lnk.bar, 7)
@skip("Too slow for regular running.")
def test_stress(self):
db = PickleShareDB('~/fsdbtest')
import time
import sys
for i in range(1000):
for j in range(1000):
if i % 15 == 0 and i < 200:
if str(j) in db:
del db[str(j)]
continue
if j % 33 == 0:
time.sleep(0.02)
db[str(j)] = db.get(str(j), []) + \
[(i, j, "proc %d" % os.getpid())]
db.hset('hash', j, db.hget('hash', j, 15) + 1)
print(i, end=' ')
sys.stdout.flush()
if i % 10 == 0:
db.uncache()
示例2: setUp
def setUp(self):
self._temp_dir = TemporaryDirectory()
self.td = self._temp_dir.name
self.notebook_manager = FileNotebookManager(
notebook_dir=self.td,
log=logging.getLogger()
)
示例3: setUp
def setUp(self):
self._temp_dir = TemporaryDirectory()
self.td = self._temp_dir.name
self.contents_manager = FileContentsManager(
root_dir=self.td,
log=logging.getLogger()
)
示例4: setUp
def setUp(self):
self.package = package = "tmp{0}".format(repr(random.random())[2:])
"""Temporary valid python package name."""
self.value = int(random.random() * 10000)
self.tempdir = TemporaryDirectory()
self.__orig_cwd = os.getcwdu()
sys.path.insert(0, self.tempdir.name)
self.writefile(os.path.join(package, "__init__.py"), "")
self.writefile(
os.path.join(package, "sub.py"),
"""
x = {0!r}
""".format(
self.value
),
)
self.writefile(
os.path.join(package, "relative.py"),
"""
from .sub import x
""",
)
self.writefile(
os.path.join(package, "absolute.py"),
"""
from {0}.sub import x
""".format(
package
),
)
示例5: setUp
def setUp(self):
self._temp_dir = TemporaryDirectory()
self.td = self._temp_dir.name
self._file_manager = FileContentsManager(root_dir=self.td)
self.contents_manager = HybridContentsManager(
managers={'': self._file_manager}
)