本文整理汇总了Python中test.script_helper.temp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python temp_dir函数的具体用法?Python temp_dir怎么用?Python temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了temp_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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.assertRaisesRegexp(RuntimeError, msg, run_path, zip_name)
示例2: test_directory_compiled
def test_directory_compiled(self):
with temp_dir() as script_dir:
mod_name = "__main__"
script_name = self._make_test_script(script_dir, mod_name)
compiled_name = compile_script(script_name)
os.remove(script_name)
self._check_script(script_dir, "<run_path>", compiled_name, script_dir, "")
示例3: test_basic_script
def test_basic_script(self):
with temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script')
package = '' if support.check_impl_detail(pypy=True) else None
self._check_script(script_name, script_name, script_name,
script_dir, package,
importlib.machinery.SourceFileLoader)
示例4: 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 = compile_script(script_name)
os.remove(script_name)
self._check_script(compiled_name, "<run_path>", compiled_name, compiled_name, None)
示例5: 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)
示例6: test_doctest_main_issue4197
def test_doctest_main_issue4197(self):
test_src = textwrap.dedent("""\
class Test:
">>> 'line 2'"
pass
import doctest
doctest.testmod()
""")
pattern = 'File "%s", line 2, in %s'
with temp_dir() as d:
script_name = make_script(d, 'script', test_src)
exit_code, data = run_python(script_name)
expected = pattern % (script_name, "__main__.Test")
if verbose:
print "Expected line", expected
print "Got stdout:"
print data
self.assertIn(expected, data)
zip_name, run_name = make_zip_script(d, "test_zip",
script_name, '__main__.py')
exit_code, data = run_python(zip_name)
expected = pattern % (run_name, "__main__.Test")
if verbose:
print "Expected line", expected
print "Got stdout:"
print data
self.assertIn(expected, data)
示例7: test_zipfile_compiled
def test_zipfile_compiled(self):
with 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)
示例8: test_module_in_subpackage_in_zipfile
def test_module_in_subpackage_in_zipfile(self):
with 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)
示例9: 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, "")
示例10: test_module_in_package
def test_module_in_package(self):
with 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, 'script')
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script')
self._check_script(launch_name, script_name, script_name, 'test_pkg')
示例11: test_package_error
def test_package_error(self):
with 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)
示例12: test_zipfile
def test_zipfile(self):
source = self.main_in_children_source
with 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)
示例13: test_package
def test_package(self):
with 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, "__main__")
launch_name = _make_launch_script(script_dir, "launch", "test_pkg")
self._check_script(launch_name, script_name, script_name, "test_pkg")
示例14: test_script_compiled
def test_script_compiled(self):
with 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)
示例15: 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 = compile_script(script_name)
zip_name, fname = make_zip_script(script_dir, 'test_zip', compiled_name)
self._check_script(zip_name, "<run_path>", fname, zip_name, '')