当前位置: 首页>>代码示例>>Python>>正文


Python tempdir.TemporaryDirectory类代码示例

本文整理汇总了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()
开发者ID:mattvonrocketstein,项目名称:smash,代码行数:54,代码来源:test_pickleshare.py

示例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()
     )
开发者ID:BhuvanRamK,项目名称:ipython,代码行数:7,代码来源:test_nbmanager.py

示例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()
     )
开发者ID:DoWhatILove,项目名称:ipython,代码行数:7,代码来源:test_manager.py

示例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
            ),
        )
开发者ID:aereinha,项目名称:ipython,代码行数:33,代码来源:test_run.py

示例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}
     )
开发者ID:baldur,项目名称:pgcontents,代码行数:7,代码来源:test_hybrid_manager.py


注:本文中的IPython.utils.tempdir.TemporaryDirectory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。