當前位置: 首頁>>代碼示例>>Python>>正文


Python script_helper.temp_dir方法代碼示例

本文整理匯總了Python中test.script_helper.temp_dir方法的典型用法代碼示例。如果您正苦於以下問題:Python script_helper.temp_dir方法的具體用法?Python script_helper.temp_dir怎麽用?Python script_helper.temp_dir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在test.script_helper的用法示例。


在下文中一共展示了script_helper.temp_dir方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _ready_to_import

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def _ready_to_import(name=None, source=""):
    # sets up a temporary directory and removes it
    # creates the module file
    # temporarily clears the module from sys.modules (if any)
    # reverts or removes the module when cleaning up
    name = name or "spam"
    with script_helper.temp_dir() as tempdir:
        path = script_helper.make_script(tempdir, name, source)
        old_module = sys.modules.pop(name, None)
        try:
            sys.path.insert(0, tempdir)
            yield name, path
            sys.path.remove(tempdir)
        finally:
            if old_module is not None:
                sys.modules[name] = old_module
            elif name in sys.modules:
                del sys.modules[name] 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:20,代碼來源:test_import.py

示例2: test_gc_ordinary_module_at_shutdown

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def test_gc_ordinary_module_at_shutdown(self):
        # Same as above, but with a non-__main__ module.
        with temp_dir() as script_dir:
            module = """if 1:
                import weakref
                class C:
                    def __del__(self):
                        print('__del__ called')
                l = [C()]
                l.append(l)
                """
            code = """if 1:
                import sys
                sys.path.insert(0, %r)
                import gctest
                """ % (script_dir,)
            make_script(script_dir, 'gctest', module)
            rc, out, err = assert_python_ok('-c', code)
            self.assertEqual(out.strip(), b'__del__ called') 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:21,代碼來源:test_gc.py

示例3: test_cwd

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def test_cwd(self):
        # Check that cwd changes the cwd for the child process.
        temp_dir = tempfile.gettempdir()
        temp_dir = self._normalize_cwd(temp_dir)
        self._assert_cwd(temp_dir, sys.executable, cwd=temp_dir) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:7,代碼來源:test_subprocess.py

示例4: test_cwd_with_absolute_arg

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def test_cwd_with_absolute_arg(self):
        # Check that Popen can find the executable when the cwd is wrong
        # if args[0] is an absolute path.
        python_dir, python_base = self._split_python_path()
        abs_python = os.path.join(python_dir, python_base)
        rel_python = os.path.join(os.curdir, python_base)
        with script_helper.temp_dir() as wrong_dir:
            # Before calling with an absolute path, confirm that using a
            # relative path fails.
            self.assertRaises(FileNotFoundError, subprocess.Popen,
                              [rel_python], cwd=wrong_dir)
            wrong_dir = self._normalize_cwd(wrong_dir)
            self._assert_cwd(wrong_dir, abs_python, cwd=wrong_dir) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:15,代碼來源:test_subprocess.py

示例5: test_syshook_no_logdir_default_format

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def test_syshook_no_logdir_default_format(self):
        with temp_dir() as tracedir:
            rc, out, err = assert_python_failure(
                  '-c',
                  ('import cgitb; cgitb.enable(logdir=%s); '
                   'raise ValueError("Hello World")') % repr(tracedir))
        out = out.decode(sys.getfilesystemencoding())
        self.assertIn("ValueError", out)
        self.assertIn("Hello World", out)
        # By default we emit HTML markup.
        self.assertIn('<p>', out)
        self.assertIn('</p>', out) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:14,代碼來源:test_cgitb.py

示例6: test_selftest

# 需要導入模塊: from test import script_helper [as 別名]
# 或者: from test.script_helper import temp_dir [as 別名]
def test_selftest(self):
        self.maxDiff = None
        with temp_dir() as directory:
            data_path = os.path.join(directory, '_test.py')
            with open(self.script) as f:
                closed = f.read()
            with open(data_path, 'w') as f:
                f.write(closed)

            rc, out, err = assert_python_ok(self.script, '-d', data_path)
            self.assertEqual(out, b'')
            self.assertEqual(err, b'')
            backup = data_path + '~'
            self.assertTrue(os.path.exists(backup))
            with open(backup) as f:
                self.assertEqual(f.read(), closed)
            with open(data_path) as f:
                clean = f.read()
            compile(clean, '_test.py', 'exec')
            self.assertEqual(self.pindent(clean, '-c'), closed)
            self.assertEqual(self.pindent(closed, '-d'), clean)

            rc, out, err = assert_python_ok(self.script, '-c', data_path)
            self.assertEqual(out, b'')
            self.assertEqual(err, b'')
            with open(backup) as f:
                self.assertEqual(f.read(), clean)
            with open(data_path) as f:
                self.assertEqual(f.read(), closed)

            broken = self.lstriplines(closed)
            with open(data_path, 'w') as f:
                f.write(broken)
            rc, out, err = assert_python_ok(self.script, '-r', data_path)
            self.assertEqual(out, b'')
            self.assertEqual(err, b'')
            with open(backup) as f:
                self.assertEqual(f.read(), broken)
            with open(data_path) as f:
                indented = f.read()
            compile(indented, '_test.py', 'exec')
            self.assertEqual(self.pindent(broken, '-r'), indented) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:44,代碼來源:test_tools.py


注:本文中的test.script_helper.temp_dir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。