コード例 #1
0
ファイル: test_import.py プロジェクト: bq/witbox-updater
 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")
コード例 #2
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 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
0
ファイル: test_build_ext.py プロジェクト: GeezerGeek/PyVHDL
 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()
コード例 #4
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 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]
コード例 #5
0
ファイル: regrtest.py プロジェクト: certik/jython
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
0
 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()
コード例 #7
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 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)
コード例 #8
0
 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
0
    def tearDown(self):
        # Get everything back to normal
        test_support.unload('xx')
        sys.path = self.sys_path
        if sys.version > "2.6":
            import site
            site.USER_BASE = self.old_user_base
            from distutils.command import build_ext
            build_ext.USER_BASE = self.old_user_base

        super(BuildExtTestCase, self).tearDown()
コード例 #10
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 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")
コード例 #11
0
ファイル: regrtest.py プロジェクト: thepian/themaestro
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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
ファイル: test_import.py プロジェクト: Alkalit/pypyjs
 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")
コード例 #15
0
ファイル: regrtest.py プロジェクト: Birdbird/StartPage
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
コード例 #16
0
ファイル: test_import.py プロジェクト: zpeach68/ironpython2
 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
         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]
コード例 #17
0
ファイル: test_import.py プロジェクト: Alkalit/pypyjs
 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]
コード例 #18
0
ファイル: test_import.py プロジェクト: zpeach68/ironpython2
    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)
コード例 #19
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
    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)
コード例 #20
0
ファイル: test_import.py プロジェクト: dearman/iron-python
 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")
コード例 #21
0
ファイル: regrtest.py プロジェクト: harry159821/sl4a
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
コード例 #22
0
                skipped.append(test)
                if ok == -2:
                    resource_denieds.append(test)
        if findleaks:
            gc.collect()
            if gc.garbage:
                print "Warning: test created", len(gc.garbage),
                print "uncollectable object(s)."
                # move the uncollectable objects somewhere so we don't see
                # them again
                found_garbage.extend(gc.garbage)
                del gc.garbage[:]
        # Unload the newly imported modules (best effort finalization)
        for module in sys.modules.keys():
            if module not in save_modules and module.startswith("test."):
                test_support.unload(module)
                module = module[5:]
                if hasattr(_test, module):
                    delattr(_test, module)

    if good and not quiet:
        if not bad and not skipped and len(good) > 1:
            print "All",
        print count(len(good), "test"), "OK."
    if print_slow:
        test_times.sort(reverse=True)
        print "10 slowest tests:"
        for time, test in test_times[:10]:
            print "%s: %.1fs" % (test, time)
    surprises = 0
    if skipped and not quiet:
コード例 #23
0
 def tearDown(self):
     if self.xx_created:
         test_support.unload('xx')
     super(BuildExtTestCase, self).tearDown()
コード例 #24
0
ファイル: regrtest.py プロジェクト: lucchouina/Rim
                skipped.append(test)
                if ok == -2:
                    resource_denieds.append(test)
        if findleaks:
            gc.collect()
            if gc.garbage:
                print "Warning: test created", len(gc.garbage),
                print "uncollectable object(s)."
                # move the uncollectable objects somewhere so we don't see
                # them again
                found_garbage.extend(gc.garbage)
                del gc.garbage[:]
        # Unload the newly imported modules (best effort finalization)
        for module in sys.modules.keys():
            if module not in save_modules and module.startswith("test."):
                test_support.unload(module)

    # The lists won't be sorted if running with -r
    good.sort()
    bad.sort()
    skipped.sort()

    if good and not quiet:
        if not bad and not skipped and len(good) > 1:
            print "All",
        print count(len(good), "test"), "OK."
    if print_slow:
        test_times.sort(reverse=True)
        print "10 slowest tests:"
        for time, test in test_times[:10]:
            print "%s: %.1fs" % (test, time)
コード例 #25
0
 def test_future3(self):
     test_support.unload('test_future3')
     from test import test_future3
コード例 #26
0
def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
    """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()
    if huntrleaks:
        refrep = open(huntrleaks[2], "a")
    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:
                # This code *is* hackish and inelegant, yes.
                # But it seems to do the job.
                import copy_reg
                fs = warnings.filters[:]
                ps = copy_reg.dispatch_table.copy()
                pic = sys.path_importer_cache.copy()
                import gc
                def cleanup():
                    import _strptime, urlparse, warnings, dircache
                    from distutils.dir_util import _path_created
                    _path_created.clear()
                    warnings.filters[:] = fs
                    gc.collect()
                    sre.purge()
                    _strptime._regex_cache.clear()
                    urlparse.clear_cache()
                    copy_reg.dispatch_table.clear()
                    copy_reg.dispatch_table.update(ps)
                    sys.path_importer_cache.clear()
                    sys.path_importer_cache.update(pic)
                    dircache.reset()
                if indirect_test:
                    def run_the_test():
                        indirect_test()
                else:
                    def run_the_test():
                        reload(the_module)
                deltas = []
                repcount = huntrleaks[0] + huntrleaks[1]
                print >> sys.stderr, "beginning", repcount, "repetitions"
                print >> sys.stderr, \
                      ("1234567890"*(repcount//10 + 1))[:repcount]
                for i in range(repcount):
                    rc = sys.gettotalrefcount()
                    run_the_test()
                    sys.stderr.write('.')
                    cleanup()
                    deltas.append(sys.gettotalrefcount() - rc - 2)
                print >>sys.stderr
                if max(map(abs, deltas[-huntrleaks[1]:])) > 0:
                    print >>sys.stderr, test, 'leaked', \
                          deltas[-huntrleaks[1]:], 'references'
                    print >>refrep, test, 'leaked', \
                          deltas[-huntrleaks[1]:], 'references'
                # The end of the huntrleaks hackishness.
        finally:
            sys.stdout = save_stdout
    except test_support.ResourceDenied, msg:
        if not quiet:
            print test, "skipped --", msg
            sys.stdout.flush()
        return -2
コード例 #27
0
 def tearDown(self):
     unload("test.relimport")
コード例 #28
0
 def testBlocker(self):
     mname = "exceptions"  # an arbitrary harmless builtin module
     test_support.unload(mname)
     sys.meta_path.append(ImportBlocker(mname))
     self.assertRaises(ImportError, __import__, mname)
コード例 #29
0
ファイル: test_future.py プロジェクト: AojiaoZero/CrossApp
 def test_future2(self):
     test_support.unload('test_future2')
     from test import test_future2
     self.assertEqual(test_future2.result, 6)
コード例 #30
0
 def tearDown(self):
     if self.xx_created:
         test_support.unload('xx')
         # XXX on Windows the test leaves a directory
         # with xx module in TEMP
     super(BuildExtTestCase, self).tearDown()
コード例 #31
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
                self.assertEqual(mod.a, a,
                    "module loaded (%s) but contents invalid" % mod)
                self.assertEqual(mod.b, b,
                    "module loaded (%s) but contents invalid" % mod)
            finally:
                if check_impl_detail(pypy=False):
                    unlink(source)

            try:
                imp.reload(mod)
            except ImportError, err:
                self.fail("import from .pyc/.pyo failed: %s" % err)
            finally:
                unlink(pyc)
                unlink(pyo)
                unload(TESTFN)

        sys.path.insert(0, os.curdir)
        try:
            test_with_extension(os.extsep + "py")
            if sys.platform.startswith("win"):
                for ext in [".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw"]:
                    test_with_extension(ext)
        finally:
            del sys.path[0]

    @unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems")
    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)
コード例 #32
0
 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.pyd in TEMP
     shutil.rmtree(self.tmp_dir, False if os.name != "nt" else True)
コード例 #33
0
 def tearDown(self):
     if self.xx_created:
         test_support.unload('xx')
     super(BuildExtTestCase, self).tearDown()
コード例 #34
0
# Test various flavors of legal and illegal future statements

from test.test_support import unload
import re

rx = re.compile('\((\S+).py, line (\d+)')


def check_error_location(msg):
    mo = rx.search(msg)
    print "SyntaxError %s %s" % mo.group(1, 2)


# The first two tests should work

unload('test_future1')
from test import test_future1

unload('test_future2')
from test import test_future2

unload('test_future3')
from test import test_future3

# The remaining tests should fail
try:
    from test import badsyntax_future3
except SyntaxError, msg:
    check_error_location(str(msg))

try:
コード例 #35
0
def runtest_inner(test,
                  verbose,
                  quiet,
                  test_times,
                  testdir=None,
                  huntrleaks=False,
                  junit_xml_dir=None):
    test_support.unload(test)
    if not testdir:
        testdir = findtestdir()
    if verbose:
        capture_stdout = None
    else:
        capture_stdout = cStringIO.StringIO()

    from test.junit_xml import Tee, write_direct_test
    try:
        save_stdout = sys.stdout

        indirect_test = None
        if junit_xml_dir:
            save_stderr = sys.stderr
            sys.stdout = stdout = Tee(sys.stdout)
            sys.stderr = stderr = Tee(sys.stderr)
        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)
            test_time = None
            if indirect_test is not None:
                indirect_test()
            elif junit_xml_dir:
                test_time = time.time() - start_time
                write_direct_test(junit_xml_dir,
                                  abstest,
                                  test_time,
                                  stdout=stdout.getvalue(),
                                  stderr=stderr.getvalue())
            if huntrleaks:
                dash_R(the_module, test, indirect_test, huntrleaks)
            if test_time is None:
                test_time = time.time() - start_time
            test_times.append((test_time, test))
        finally:
            sys.stdout = save_stdout
            if junit_xml_dir:
                sys.stderr = save_stderr
                test_time = time.time() - start_time
    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,
                              test_time,
                              'skipped',
                              sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return -2
コード例 #36
0
            else:
                self.assertEqual(
                    mod.a, a, "module loaded (%s) but contents invalid" % mod)
                self.assertEqual(
                    mod.b, b, "module loaded (%s) but contents invalid" % mod)
            finally:
                unlink(source)

            try:
                imp.reload(mod)
            except ImportError, err:
                self.fail("import from .pyc/.pyo failed: %s" % err)
            finally:
                unlink(pyc)
                unlink(pyo)
                unload(TESTFN)

        sys.path.insert(0, os.curdir)
        try:
            test_with_extension(os.extsep + "py")
            if sys.platform.startswith("win"):
                for ext in [".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw"]:
                    test_with_extension(ext)
        finally:
            del sys.path[0]

    @unittest.skipUnless(os.name == 'posix',
                         "test meaningful only on posix systems")
    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.
コード例 #37
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 def tearDown(self):
     unload(TESTFN)
コード例 #38
0
 def test_multiple_features(self):
     test_support.unload("test.test_future5")
     from test import test_future5
コード例 #39
0
ファイル: test_future.py プロジェクト: AojiaoZero/CrossApp
 def test_multiple_features(self):
     test_support.unload("test.test_future5")
     from test import test_future5
コード例 #40
0
 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')
コード例 #41
0
ファイル: test_future.py プロジェクト: AojiaoZero/CrossApp
 def test_future3(self):
     test_support.unload('test_future3')
     from test import test_future3
コード例 #42
0
ファイル: regrtest.py プロジェクト: varialus/jython-legacy
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()

    #XXX: seems to need setting outside of the try block.
    indirect_test = None
    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
コード例 #43
0
 def tearDown(self):
     unload(TESTFN)
コード例 #44
0
ファイル: test_future.py プロジェクト: FloMom/pypy
 def test_future3(self):
     test_support.unload('test_future3')
コード例 #45
0
ファイル: regrtest.py プロジェクト: pekkaklarck/jython
def runtest_inner(test, verbose, quiet, test_times,
                  testdir=None, huntrleaks=False, junit_xml_dir=None):
    test_support.unload(test)
    if not testdir:
        testdir = findtestdir()
    if verbose:
        capture_stdout = None
    else:
        capture_stdout = cStringIO.StringIO()

    from test.junit_xml import Tee, write_direct_test
    try:
        save_stdout = sys.stdout

        indirect_test = None
        if junit_xml_dir:
            save_stderr = sys.stderr
            sys.stdout = stdout = Tee(sys.stdout)
            sys.stderr = stderr = Tee(sys.stderr)
        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)
            test_time = None
            if indirect_test is not None:
                indirect_test()
            elif junit_xml_dir:
                test_time = time.time() - start_time
                write_direct_test(junit_xml_dir, abstest, test_time,
                                  stdout=stdout.getvalue(),
                                  stderr=stderr.getvalue())
            if huntrleaks:
                dash_R(the_module, test, indirect_test, huntrleaks)
            if test_time is None:
                test_time = time.time() - start_time
            test_times.append((test_time, test))
        finally:
            sys.stdout = save_stdout
            if junit_xml_dir:
                sys.stderr = save_stderr
                test_time = time.time() - start_time
    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, test_time,
                              'skipped', sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return -2
コード例 #46
0
ファイル: test_import.py プロジェクト: MichaelBlume/pypy
 def tearDown(self):
     unload("test.relimport")
コード例 #47
0
 def tearDown(self):
     if self.xx_created:
         test_support.unload('xx')
         # XXX on Windows the test leaves a directory
         # with xx module in TEMP
     super(BuildExtTestCase, self).tearDown()
コード例 #48
0
 def test_future2(self):
     test_support.unload('test_future2')
     from test import test_future2
     self.assertEqual(test_future2.result, 6)