• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python test_support.unload函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.test_support.unload函数的典型用法代码示例。如果您正苦于以下问题:Python unload函数的具体用法?Python unload怎么用?Python unload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unload函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:GeezerGeek,项目名称:PyVHDL,代码行数:7,代码来源:test_build_ext.py


示例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")
开发者ID:MichaelBlume,项目名称:pypy,代码行数:7,代码来源:test_import.py


示例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]
开发者ID:MichaelBlume,项目名称:pypy,代码行数:25,代码来源:test_import.py


示例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")
开发者ID:bq,项目名称:witbox-updater,代码行数:7,代码来源:test_import.py


示例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
开发者ID:certik,项目名称:jython,代码行数:59,代码来源:regrtest.py


示例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)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:9,代码来源:test_import.py


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


示例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")
开发者ID:andrcmdr,项目名称:unladen-swallow,代码行数:11,代码来源:test_import.py


示例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")
开发者ID:MichaelBlume,项目名称:pypy,代码行数:14,代码来源:test_import.py


示例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
开发者ID:thepian,项目名称:themaestro,代码行数:49,代码来源:regrtest.py


示例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
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:44,代码来源:regrtest.py


示例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
开发者ID:carlosrcjunior,项目名称:BCC-2s13-PI4-WebCrawler,代码行数:42,代码来源:regrtest.py


示例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")
开发者ID:Alkalit,项目名称:pypyjs,代码行数:21,代码来源:test_import.py


示例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
开发者ID:Birdbird,项目名称:StartPage,代码行数:40,代码来源:regrtest.py


示例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]
开发者ID:Alkalit,项目名称:pypyjs,代码行数:34,代码来源:test_import.py


示例16: test_failing_reload

    def test_failing_reload(self):
        # A failing reload should leave the module object in sys.modules.
        source = TESTFN + os.extsep + "py"
        with open(source, "w") as f:
            print >> f, "a = 1"
            print >> f, "b = 2"

        sys.path.insert(0, os.curdir)
        try:
            mod = __import__(TESTFN)
            self.assertIn(TESTFN, sys.modules)
            self.assertEqual(mod.a, 1, "module has wrong attribute values")
            self.assertEqual(mod.b, 2, "module has wrong attribute values")

            # On WinXP, just replacing the .py file wasn't enough to
            # convince reload() to reparse it.  Maybe the timestamp didn't
            # move enough.  We force it to get reparsed by removing the
            # compiled file too.
            remove_files(TESTFN)

            # Now damage the module.
            with open(source, "w") as f:
                print >> f, "a = 10"
                print >> f, "b = 20//0"

            self.assertRaises(ZeroDivisionError, imp.reload, mod)

            # But we still expect the module to be in sys.modules.
            mod = sys.modules.get(TESTFN)
            self.assertIsNot(mod, None, "expected module to be in sys.modules")

            # We should have replaced a w/ 10, but the old b value should
            # stick.
            self.assertEqual(mod.a, 10, "module has wrong attribute values")
            self.assertEqual(mod.b, 2, "module has wrong attribute values")

        finally:
            del sys.path[0]
            remove_files(TESTFN)
            unload(TESTFN)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:40,代码来源:test_import.py


示例17: runtest_inner

def runtest_inner(test, verbose, quiet, test_times, testdir=None, huntrleaks=False):
    test_support.unload(test)
    if not testdir:
        testdir = findtestdir()
    if verbose:
        capture_stdout = None
    else:
        capture_stdout = cStringIO.StringIO()

    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
            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:
                dash_R(the_module, test, indirect_test, huntrleaks)
            test_time = time.time() - start_time
            test_times.append((test_time, test))
        finally:
            sys.stdout = save_stdout
    except test_support.ResourceDenied, msg:
        if not quiet:
            print test, "skipped --", msg
            sys.stdout.flush()
        return -2
开发者ID:harry159821,项目名称:sl4a,代码行数:39,代码来源:regrtest.py


示例18: test_future3

 def test_future3(self):
     test_support.unload('test_future3')
     from test import test_future3
开发者ID:AojiaoZero,项目名称:CrossApp,代码行数:3,代码来源:test_future.py


示例19: test_future2

 def test_future2(self):
     test_support.unload('test_future2')
     from test import test_future2
     self.assertEqual(test_future2.result, 6)
开发者ID:AojiaoZero,项目名称:CrossApp,代码行数:4,代码来源:test_future.py


示例20: test_multiple_features

 def test_multiple_features(self):
     test_support.unload("test.test_future5")
     from test import test_future5
开发者ID:AojiaoZero,项目名称:CrossApp,代码行数:3,代码来源:test_future.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_support.vereq函数代码示例发布时间:2022-05-27
下一篇:
Python test_support.unlink函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap