本文整理汇总了Python中test.support.temp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python temp_dir函数的具体用法?Python temp_dir怎么用?Python temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了temp_dir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_consistent_sys_path_for_direct_execution
def test_consistent_sys_path_for_direct_execution(self):
# This test case ensures that the following all give the same
# sys.path configuration:
#
# ./python -s script_dir/__main__.py
# ./python -s script_dir
# ./python -I script_dir
script = textwrap.dedent("""\
import sys
for entry in sys.path:
print(entry)
""")
# Always show full path diffs on errors
self.maxDiff = None
with support.temp_dir() as work_dir, support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__', script)
# Reference output comes from directly executing __main__.py
# We omit PYTHONPATH and user site to align with isolated mode
p = spawn_python("-Es", script_name, cwd=work_dir)
out_by_name = kill_python(p).decode().splitlines()
self.assertEqual(out_by_name[0], script_dir)
self.assertNotIn(work_dir, out_by_name)
# Directory execution should give the same output
p = spawn_python("-Es", script_dir, cwd=work_dir)
out_by_dir = kill_python(p).decode().splitlines()
self.assertEqual(out_by_dir, out_by_name)
# As should directory execution in isolated mode
p = spawn_python("-I", script_dir, cwd=work_dir)
out_by_dir_isolated = kill_python(p).decode().splitlines()
self.assertEqual(out_by_dir_isolated, out_by_dir, out_by_name)
开发者ID:Daetalus,项目名称:cpython,代码行数:30,代码来源:test_cmd_line_script.py
示例2: test_main_recursion_error
def test_main_recursion_error(self):
with temp_dir() as script_dir, temp_dir() as dummy_dir:
mod_name = "__main__"
source = ("import runpy\n" "runpy.run_path(%r)\n") % dummy_dir
script_name = self._make_test_script(script_dir, mod_name, source)
zip_name, fname = make_zip_script(script_dir, "test_zip", script_name)
msg = "recursion depth exceeded"
self.assertRaisesRegex(RecursionError, msg, run_path, zip_name)
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:8,代码来源:test_runpy.py
示例3: test_script_compiled
def test_script_compiled(self):
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, "script")
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
pyc_file = support.make_legacy_pyc(script_name)
self._check_script(pyc_file, pyc_file, pyc_file, script_dir, None, importlib.machinery.SourcelessFileLoader)
开发者ID:wdv4758h,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例4: test_zipfile_compiled
def test_zipfile_compiled(self):
with temp_dir() as script_dir:
mod_name = "__main__"
script_name = self._make_test_script(script_dir, mod_name)
compiled_name = py_compile.compile(script_name, doraise=True)
zip_name, fname = make_zip_script(script_dir, "test_zip", compiled_name)
self._check_script(zip_name, "<run_path>", fname, zip_name, mod_name=mod_name, check_loader=False)
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:7,代码来源:test_runpy.py
示例5: test_package_error
def test_package_error(self):
with support.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, "test_pkg")
make_pkg(pkg_dir)
msg = "'test_pkg' is a package and cannot " "be directly executed"
launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
self._check_import_error(launch_name, msg)
开发者ID:wdv4758h,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例6: test_basic_script_no_suffix
def test_basic_script_no_suffix(self):
with temp_dir() as script_dir:
mod_name = 'script'
script_name = self._make_test_script(script_dir, mod_name,
omit_suffix=True)
self._check_script(script_name, "<run_path>", script_name,
script_name, expect_spec=False)
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:7,代码来源:test_runpy.py
示例7: test_script_compiled
def test_script_compiled(self):
with temp_dir() as script_dir:
mod_name = "script"
script_name = self._make_test_script(script_dir, mod_name)
compiled_name = py_compile.compile(script_name, doraise=True)
os.remove(script_name)
self._check_script(compiled_name, "<run_path>", compiled_name, compiled_name, expect_spec=False)
开发者ID:francois-wellenreiter,项目名称:cpython,代码行数:7,代码来源:test_runpy.py
示例8: test_zipfile
def test_zipfile(self):
with temp_dir() as script_dir:
mod_name = '__main__'
script_name = self._make_test_script(script_dir, mod_name)
zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
self._check_script(zip_name, "<run_path>", fname, zip_name,
mod_name=mod_name, check_loader=False)
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:7,代码来源:test_runpy.py
示例9: test_zipfile_error
def test_zipfile_error(self):
with temp_dir() as script_dir:
mod_name = 'not_main'
script_name = self._make_test_script(script_dir, mod_name)
zip_name, fname = make_zip_script(script_dir, 'test_zip', script_name)
msg = "can't find '__main__' module in %r" % zip_name
self._check_import_error(zip_name, msg)
开发者ID:DAWZayas-Projects,项目名称:TEJEDOR-RETUERTO-ALEJANDRO,代码行数:7,代码来源:test_runpy.py
示例10: test_module_in_subpackage_in_zipfile
def test_module_in_subpackage_in_zipfile(self):
with support.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name)
self._check_script(launch_name, run_name, run_name,
zip_name, 'test_pkg.test_pkg',
zipimport.zipimporter)
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例11: test_zipfile
def test_zipfile(self):
source = self.main_in_children_source
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
self._check_script(zip_name)
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:7,代码来源:test_multiprocessing_main_handling.py
示例12: test_module_in_subpackage_in_zipfile
def test_module_in_subpackage_in_zipfile(self):
with support.temp_dir() as script_dir:
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
self._check_script(["-m", "test_pkg.test_pkg.script"], run_name, run_name,
script_dir, 'test_pkg.test_pkg',
zipimport.zipimporter,
PYTHONPATH=zip_name, cwd=script_dir)
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例13: test_script_compiled
def test_script_compiled(self):
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
py_compile.compile(script_name, doraise=True)
os.remove(script_name)
pyc_file = support.make_legacy_pyc(script_name)
self._check_script(pyc_file)
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:7,代码来源:test_multiprocessing_main_handling.py
示例14: test_ismount
def test_ismount(self):
self.assertTrue(ntpath.ismount("c:\\"))
self.assertTrue(ntpath.ismount("C:\\"))
self.assertTrue(ntpath.ismount("c:/"))
self.assertTrue(ntpath.ismount("C:/"))
self.assertTrue(ntpath.ismount("\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount("\\\\.\\C:\\"))
self.assertTrue(ntpath.ismount(b"c:\\"))
self.assertTrue(ntpath.ismount(b"C:\\"))
self.assertTrue(ntpath.ismount(b"c:/"))
self.assertTrue(ntpath.ismount(b"C:/"))
self.assertTrue(ntpath.ismount(b"\\\\.\\c:\\"))
self.assertTrue(ntpath.ismount(b"\\\\.\\C:\\"))
with support.temp_dir() as d:
self.assertFalse(ntpath.ismount(d))
if sys.platform == "win32":
#
# Make sure the current folder isn't the root folder
# (or any other volume root). The drive-relative
# locations below cannot then refer to mount points
#
drive, path = ntpath.splitdrive(sys.executable)
with support.change_cwd(os.path.dirname(sys.executable)):
self.assertFalse(ntpath.ismount(drive.lower()))
self.assertFalse(ntpath.ismount(drive.upper()))
self.assertTrue(ntpath.ismount("\\\\localhost\\c$"))
self.assertTrue(ntpath.ismount("\\\\localhost\\c$\\"))
self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$"))
self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$\\"))
开发者ID:venkatanagineni,项目名称:cpython,代码行数:34,代码来源:test_ntpath.py
示例15: test_package_error
def test_package_error(self):
with support.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
msg = ("'test_pkg' is a package and cannot "
"be directly executed")
self._check_import_error(["-m", "test_pkg"], msg, cwd=script_dir)
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例16: test_zipfile_compiled
def test_zipfile_compiled(self):
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__')
compiled_name = py_compile.compile(script_name, doraise=True)
zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name)
self._check_script(zip_name, run_name, zip_name, zip_name, '',
zipimport.zipimporter)
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:7,代码来源:test_cmd_line_script.py
示例17: test_history_size
def test_history_size(self):
history_size = 10
with temp_dir() as test_dir:
inputrc = os.path.join(test_dir, "inputrc")
with open(inputrc, "wb") as f:
f.write(b"set history-size %d\n" % history_size)
history_file = os.path.join(test_dir, "history")
with open(history_file, "wb") as f:
# history_size * 2 items crashes readline
data = b"".join(b"item %d\n" % i
for i in range(history_size * 2))
f.write(data)
script = """
import os
import readline
history_file = os.environ["HISTORY_FILE"]
readline.read_history_file(history_file)
input()
readline.write_history_file(history_file)
"""
env = dict(os.environ)
env["INPUTRC"] = inputrc
env["HISTORY_FILE"] = history_file
run_pty(script, input=b"last input\r", env=env)
with open(history_file, "rb") as f:
lines = f.readlines()
self.assertEqual(len(lines), history_size)
self.assertEqual(lines[-1].strip(), b"last input")
开发者ID:1st1,项目名称:cpython,代码行数:34,代码来源:test_readline.py
示例18: test_module_in_package
def test_module_in_package(self):
with support.temp_dir() as script_dir:
pkg_dir = os.path.join(script_dir, 'test_pkg')
make_pkg(pkg_dir)
script_name = _make_test_script(pkg_dir, 'check_sibling')
launch_name = _make_launch_script(script_dir, 'launch',
'test_pkg.check_sibling')
self._check_script(launch_name)
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:8,代码来源:test_multiprocessing_main_handling.py
示例19: test_syntaxerror_unindented_caret_position
def test_syntaxerror_unindented_caret_position(self):
script = "1 + 1 = 2\n"
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
# Confirm that the caret is located under the first 1 character
self.assertIn("\n 1 + 1 = 2\n ^", text)
开发者ID:Daetalus,项目名称:cpython,代码行数:8,代码来源:test_cmd_line_script.py
示例20: test_zipfile_compiled
def test_zipfile_compiled(self):
source = self.main_in_children_source
with support.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, '__main__',
source=source)
compiled_name = py_compile.compile(script_name, doraise=True)
zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name)
self._check_script(zip_name)
开发者ID:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:8,代码来源:test_multiprocessing_main_handling.py
注:本文中的test.support.temp_dir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论