コード例 #1
0
ファイル: test.py プロジェクト: s-fiebig/mechanize
def main(argv):
    # test-tools/ dir includes a bundled Python 2.5 doctest / linecache, and a
    # bundled & modified Python trunk (2.7 vintage) unittest.  This is only for
    # testing purposes, and these don't get installed.

    # unittest revision 77209, modified (probably I should have used PyPI
    # project discover, which is already backported to 2.4, but since I've
    # already done that and made changes, I won't bother for now)

    # doctest.py revision 45701 and linecache.py revision 45940.  Since
    # linecache is used by Python itself, linecache.py is renamed
    # linecache_copy.py, and this copy of doctest is modified (only) to use
    # that renamed module.

    mutate_sys_path()
    assert "doctest" not in sys.modules
    import testprogram

    # *.py to catch doctests in docstrings
    this_dir = os.path.dirname(__file__)
    prog = testprogram.TestProgram(argv=argv,
                                   default_discovery_args=(this_dir, "*.py",
                                                           None),
                                   module=None)
    result = prog.runTests()
    success = result.wasSuccessful()
    sys.exit(int(not success))
コード例 #2
0
        self._testcase.assertEqual(block_nr, self._count)
        self._count = self._count + 1


if __name__ == "__main__":
    import sys
    sys.path.insert(0, "test-tools")
    import testprogram
    USAGE_EXAMPLES = """
Examples:
  %(progName)s
                 - run all tests
  %(progName)s functional_tests.SimpleTests
                 - run all 'test*' test methods in class SimpleTests
  %(progName)s functional_tests.SimpleTests.test_redirect
                 - run SimpleTests.test_redirect

  %(progName)s -l
                 - start a local Twisted HTTP server and run the functional
                   tests against that, rather than against SourceForge
                   (quicker!)
                   If this option doesn't work on Windows/Mac, somebody please
                   tell me about it, or I'll never find out...
"""
    prog = testprogram.TestProgram(
        ["functional_tests"],
        localServerProcess=testprogram.TwistedServerProcess(),
        usageExamples=USAGE_EXAMPLES,
    )
    result = prog.runTests()
コード例 #3
0
        doctest.testmod(_clientcookie)
        doctest.testmod(_pullparser)
        doctest.testmod(_http)
        doctest.testmod(_useragent)

    if run_unittests:
        # run vanilla unittest tests
        import unittest
        test_path = os.path.join(os.path.dirname(sys.argv[0]), "test")
        sys.path.insert(0, test_path)
        test_runner = None
        if use_cgitb:
            test_runner = testprogram.CgitbTextTestRunner()
        prog = testprogram.TestProgram(
            MODULE_NAMES,
            testRunner=test_runner,
            localServerProcess=testprogram.TwistedServerProcess(),
        )
        result = prog.runTests()

    if run_coverage:
        # HTML coverage report
        import colorize
        try:
            os.mkdir("coverage")
        except OSError:
            pass
        private_modules = glob.glob("mechanize/_*.py")
        private_modules.remove("mechanize/__init__.py")
        for module_filename in private_modules:
            module_name = module_filename.replace("/", ".")[:-3]