本文整理汇总了Python中test.test_support.unload函数的典型用法代码示例。如果您正苦于以下问题:Python unload函数的具体用法?Python unload怎么用?Python unload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unload函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
def tearDown(self):
# Get everything back to normal
test_support.unload('xx')
sys.path = self.sys_path
# XXX on Windows the test leaves a directory with xx module in TEMP
shutil.rmtree(self.tmp_dir, os.name == 'nt' or sys.platform == 'cygwin')
super(BuildExtTestCase, self).tearDown()
示例2: test_trailing_slash
def test_trailing_slash(self):
with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
f.write("testdata = 'test_trailing_slash'")
sys.path.append(self.path+'/')
mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, 'test_trailing_slash')
unload("test_trailing_slash")
示例3: test_execute_bit_not_copied
def test_execute_bit_not_copied(self):
# Issue 6070: under posix .pyc files got their execute bit set if
# the .py file had the execute bit set, but they aren't executable.
oldmask = os.umask(022)
sys.path.insert(0, os.curdir)
try:
fname = TESTFN + os.extsep + "py"
f = open(fname, 'w').close()
os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
__import__(TESTFN)
fn = fname + 'c'
if not os.path.exists(fn):
fn = fname + 'o'
if not os.path.exists(fn):
self.fail("__import__ did not result in creation of "
"either a .pyc or .pyo file")
s = os.stat(fn)
self.assertEqual(stat.S_IMODE(s.st_mode),
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
finally:
os.umask(oldmask)
remove_files(TESTFN)
unload(TESTFN)
del sys.path[0]
示例4: test_trailing_slash
def test_trailing_slash(self):
with open(os.path.join(self.path, "test_trailing_slash.py"), "w") as f:
f.write("testdata = 'test_trailing_slash'")
sys.path.append(self.path + "/")
mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, "test_trailing_slash")
unload("test_trailing_slash")
示例5: runtest_inner
def runtest_inner(test, generate, verbose, quiet,
testdir=None, huntrleaks=False, junit_xml_dir=None):
test_support.unload(test)
if not testdir:
testdir = findtestdir()
outputdir = os.path.join(testdir, "output")
outputfile = os.path.join(outputdir, test)
if verbose:
cfp = None
else:
cfp = cStringIO.StringIO()
try:
save_stdout = sys.stdout
if junit_xml_dir:
from test.junit_xml import Tee, write_direct_test
indirect_test = None
save_stderr = sys.stderr
sys.stdout = stdout = Tee(sys.stdout)
sys.stderr = stderr = Tee(sys.stderr)
try:
if cfp:
sys.stdout = cfp
print test # Output file starts with test name
if test.startswith('test.'):
abstest = test
else:
# Always import it from the test package
abstest = 'test.' + test
start = time.time()
the_package = __import__(abstest, globals(), locals(), [])
the_module = getattr(the_package, test)
# Most tests run to completion simply as a side-effect of
# being imported. For the benefit of tests that can't run
# that way (like test_threaded_import), explicitly invoke
# their test_main() function (if it exists).
indirect_test = getattr(the_module, "test_main", None)
if indirect_test is not None:
indirect_test()
elif junit_xml_dir:
write_direct_test(junit_xml_dir, abstest, time.time() - start,
stdout=stdout.getvalue(),
stderr=stderr.getvalue())
if huntrleaks:
dash_R(the_module, test, indirect_test, huntrleaks)
finally:
sys.stdout = save_stdout
if junit_xml_dir:
sys.stderr = save_stderr
except test_support.ResourceDenied, msg:
if not quiet:
print test, "skipped --", msg
sys.stdout.flush()
if junit_xml_dir:
write_direct_test(junit_xml_dir, abstest, time.time() - start,
'skipped', sys.exc_info(),
stdout=stdout.getvalue(),
stderr=stderr.getvalue())
return -2
示例6: tearDown
def tearDown(self):
sys.path[:] = self.sys_path
if self.orig_module is not None:
sys.modules[self.module_name] = self.orig_module
else:
unload(self.module_name)
unlink(self.file_name)
unlink(self.compiled_name)
rmtree(self.dir_name)
示例7: tearDown
def tearDown(self):
# Get everything back to normal
if os.path.exists(_XX_MODULE_PATH):
test_support.unload("xx")
sys.path[:] = self.sys_path
# XXX on Windows the test leaves a directory
# with xx module in TEMP
shutil.rmtree(self.tmp_dir, os.name == "nt" or sys.platform == "cygwin")
super(BuildExtTestCase, self).tearDown()
示例8: test_trailing_slash
def test_trailing_slash(self):
# Regression test for http://bugs.python.org/issue1293.
f = open(os.path.join(self.path, 'test_trailing_slash.py'), 'w')
try:
f.write("testdata = 'test_trailing_slash'")
finally:
f.close()
sys.path.append(self.path+'/')
mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, 'test_trailing_slash')
test_support.unload("test_trailing_slash")
示例9: _test_UNC_path
def _test_UNC_path(self):
with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
f.write("testdata = 'test_trailing_slash'")
# Create the UNC path, like \\myhost\c$\foo\bar.
path = os.path.abspath(self.path)
import socket
hn = socket.gethostname()
drive = path[0]
unc = "\\\\%s\\%s$"%(hn, drive)
unc += path[2:]
sys.path.append(path)
mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, 'test_trailing_slash')
unload("test_trailing_slash")
示例10: runtest_inner
def runtest_inner(test, generate, verbose, quiet,
testdir=None, huntrleaks=False):
test_support.unload(test)
if testdir:
testdirs = [testdir]
else:
testdirs = findtestdirs()
outputfiles = []
for testdir in testdirs:
outputdir = os.path.join(testdir, "output")
outputfile = os.path.join(outputdir, test)
if os.path.exists(outputfile):
outputfiles.append(outputfile)
if outputfiles:
outputfile = outputfiles[-1]
if verbose:
cfp = None
else:
cfp = cStringIO.StringIO()
try:
save_stdout = sys.stdout
try:
if cfp:
sys.stdout = cfp
print test # Output file starts with test name
if test.startswith('test.'):
abstest = test
else:
# Always import it from the test package
abstest = 'test.' + test
the_package = __import__(abstest, globals(), locals(), [])
the_module = getattr(the_package, test)
# Most tests run to completion simply as a side-effect of
# being imported. For the benefit of tests that can't run
# that way (like test_threaded_import), explicitly invoke
# their test_main() function (if it exists).
indirect_test = getattr(the_module, "test_main", None)
if indirect_test is not None:
indirect_test()
if huntrleaks:
dash_R(the_module, test, indirect_test, huntrleaks)
finally:
sys.stdout = save_stdout
except test_support.ResourceDenied, msg:
if not quiet:
print test, "skipped --", msg
sys.stdout.flush()
return -2
示例11: runtest
def runtest(test, generate, verbose, quiet, testdir = None):
"""Run a single test.
test -- the name of the test
generate -- if true, generate output, instead of running the test
and comparing it to a previously created output file
verbose -- if true, print more messages
quiet -- if true, don't print 'skipped' messages (probably redundant)
testdir -- test directory
"""
test_support.unload(test)
if not testdir: testdir = findtestdir()
outputdir = os.path.join(testdir, "output")
outputfile = os.path.join(outputdir, test)
if verbose:
cfp = None
else:
cfp = cStringIO.StringIO()
try:
save_stdout = sys.stdout
try:
if cfp:
sys.stdout = cfp
print test # Output file starts with test name
if test.startswith('test.'):
abstest = test
else:
# Always import it from the test package
abstest = 'test.' + test
the_package = __import__(abstest, globals(), locals(), [])
the_module = getattr(the_package, test)
# Most tests run to completion simply as a side-effect of
# being imported. For the benefit of tests that can't run
# that way (like test_threaded_import), explicitly invoke
# their test_main() function (if it exists).
indirect_test = getattr(the_module, "test_main", None)
if indirect_test is not None:
indirect_test()
finally:
sys.stdout = save_stdout
except test_support.ResourceDenied, msg:
if not quiet:
print test, "skipped --", msg
sys.stdout.flush()
return -2
示例12: runtest_inner
def runtest_inner(test, verbose, quiet,
testdir=None, huntrleaks=False):
test_support.unload(test)
testdir = findtestdir(testdir)
if verbose:
capture_stdout = None
else:
capture_stdout = StringIO.StringIO()
test_time = 0.0
refleak = False # True if the test leaked references.
try:
save_stdout = sys.stdout
try:
if capture_stdout:
sys.stdout = capture_stdout
if test.startswith('test.'):
abstest = test
else:
# Always import it from the test package
abstest = 'test.' + test
with saved_test_environment(test, verbose, quiet) as environment:
start_time = time.time()
the_package = __import__(abstest, globals(), locals(), [])
the_module = getattr(the_package, test)
# Old tests run to completion simply as a side-effect of
# being imported. For tests based on unittest or doctest,
# explicitly invoke their test_main() function (if it exists).
indirect_test = getattr(the_module, "test_main", None)
if indirect_test is not None:
indirect_test()
if huntrleaks:
refleak = dash_R(the_module, test, indirect_test,
huntrleaks)
test_time = time.time() - start_time
finally:
sys.stdout = save_stdout
except test_support.ResourceDenied, msg:
if not quiet:
print test, "skipped --", msg
sys.stdout.flush()
return RESOURCE_DENIED, test_time
示例13: _test_UNC_path
def _test_UNC_path(self):
with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
f.write("testdata = 'test_trailing_slash'")
# Create the UNC path, like \\myhost\c$\foo\bar.
path = os.path.abspath(self.path)
import socket
hn = socket.gethostname()
drive = path[0]
unc = "\\\\%s\\%s$"%(hn, drive)
unc += path[2:]
try:
os.listdir(unc)
except OSError as e:
if e.errno in (errno.EPERM, errno.EACCES):
# See issue #15338
self.skipTest("cannot access administrative share %r" % (unc,))
raise
sys.path.append(path)
mod = __import__("test_trailing_slash")
self.assertEqual(mod.testdata, 'test_trailing_slash')
unload("test_trailing_slash")
示例14: runtest
def runtest(test, generate, verbose, testdir = None):
"""Run a single test.
test -- the name of the test
generate -- if true, generate output, instead of running the test
and comparing it to a previously created output file
verbose -- if true, print more messages
testdir -- test directory
"""
test_support.unload(test)
if not testdir: testdir = findtestdir()
outputdir = os.path.join(testdir, "output")
outputfile = os.path.join(outputdir, test)
try:
if generate:
cfp = open(outputfile, "w")
elif verbose:
cfp = sys.stdout
else:
cfp = Compare(outputfile)
except IOError:
cfp = None
print "Warning: can't open", outputfile
try:
save_stdout = sys.stdout
try:
if cfp:
sys.stdout = cfp
print test # Output file starts with test name
the_module = __import__(test, globals(), locals(), [])
# Most tests run to completion simply as a side-effect of
# being imported. For the benefit of tests that can't run
# that way (like test_threaded_import), explicitly invoke
# their test_main() function (if it exists).
indirect_test = getattr(the_module, "test_main", None)
if indirect_test is not None:
indirect_test()
finally:
sys.stdout = save_stdout
except ImportError, msg:
return -1
示例15: test_rewrite_pyc_with_read_only_source
def test_rewrite_pyc_with_read_only_source(self):
# Issue 6074: a long time ago on posix, and more recently on Windows,
# a read only source file resulted in a read only pyc file, which
# led to problems with updating it later
sys.path.insert(0, os.curdir)
fname = TESTFN + os.extsep + "py"
try:
# Write a Python file, make it read-only and import it
with open(fname, 'w') as f:
f.write("x = 'original'\n")
# Tweak the mtime of the source to ensure pyc gets updated later
s = os.stat(fname)
os.utime(fname, (s.st_atime, s.st_mtime-100000000))
os.chmod(fname, 0400)
m1 = __import__(TESTFN)
self.assertEqual(m1.x, 'original')
# Change the file and then reimport it
os.chmod(fname, 0600)
with open(fname, 'w') as f:
f.write("x = 'rewritten'\n")
unload(TESTFN)
m2 = __import__(TESTFN)
self.assertEqual(m2.x, 'rewritten')
# Now delete the source file and check the pyc was rewritten
if check_impl_detail(pypy=False):
unlink(fname)
unload(TESTFN)
m3 = __import__(TESTFN)
self.assertEqual(m3.x, 'rewritten')
finally:
chmod_files(TESTFN)
remove_files(TESTFN)
unload(TESTFN)
del sys.path[0]