Beispiel #1
0
 def test_targets(self):
     "The targets passed in make it through mergeConfig"
     "The specified target gets parsed"
     config.sys.argv = ['', 'target1', 'target2']
     args = config.parseArguments()
     args = config.mergeConfig(args)
     self.assertEqual(args.targets, ['target1', 'target2'])
Beispiel #2
0
 def test_target(self):
     """
     The specified target gets parsed
     """
     config.sys.argv = ['', 'target1', 'target2']
     args = config.parseArguments()
     self.assertEqual(args.targets, ['target1', 'target2'])
Beispiel #3
0
 def test_target(self):
     """
     The specified target gets parsed
     """
     config.sys.argv = ["", "target1", "target2"]
     args = config.parseArguments()
     self.assertEqual(args.targets, ["target1", "target2"])
Beispiel #4
0
 def test_absent(self):
     """
     Arguments not specified on the command-line are not present in the args
     object.
     """
     config.sys.argv = ['', '--debug']
     args = config.parseArguments()
     self.assertEqual(getattr(args, 'debug', 'not there'), True)
     self.assertEqual(getattr(args, 'verbose', 'not there'), 'not there')
     self.assertEqual(getattr(args, 'targets', 'not there'), 'not there')
     self.assertEqual(getattr(args, 'file_pattern', 'not there'), 'not there')
Beispiel #5
0
 def test_absent(self):
     """
     Arguments not specified on the command-line are not present in the args
     object.
     """
     config.sys.argv = ["", "--debug"]
     args = config.parseArguments()
     self.assertEqual(getattr(args, "debug", "not there"), True)
     self.assertEqual(getattr(args, "verbose", "not there"), "not there")
     self.assertEqual(getattr(args, "targets", "not there"), "not there")
     self.assertEqual(getattr(args, "file_pattern", "not there"),
                      "not there")
Beispiel #6
0
def run_test(path):
    args = config.parseArguments()
    args = config.mergeConfig(args)
    args.verbose = 3

    args.targets = path

    stream = GreenStream(sys.stdout)

    loader = GreenTestLoader()
    test_suite = loader.loadTargets(args.targets)
    result = run(test_suite, stream, args)

    return result
Beispiel #7
0
def get_user_options():

    # When running "python setup.py --help-commands", setup.py will call this
    # function -- but green isn't actually being called.
    if "--help-commands" in sys.argv:
        return []

    r = parseArguments()
    options = []

    for action in r.store_opt.actions:
        names = [str(name.lstrip('-')) for name in action.option_strings]
        if len(names) == 1: names.insert(0, None)
        if not action.const: names[1] += str("=")
        options.append((names[1], names[0], action.help))

    return options
Beispiel #8
0
def get_user_options():

    # When running "python setup.py --help-commands", setup.py will call this
    # function -- but green isn't actually being called.
    if "--help-commands" in sys.argv:
        return []

    r = parseArguments()
    options = []

    for action in r.store_opt.actions:
        names = [str(name.lstrip('-')) for name in action.option_strings]
        if len(names) == 1: names.insert(0, None)
        if not action.const: names[1] += str("=")
        options.append((names[1], names[0], action.help))

    return options
Beispiel #9
0
def main(testing=False, coverage_testing=False):
    args = config.parseArguments()
    args = config.mergeConfig(args, testing, coverage_testing)
    if getattr(args, 'html', False): # pragma: no cover
        print("""
The --html flag is scheduled to be removed in version 2.0 due to it being a pain
to maintain and no one using it.  If you actually use it, please open an issue
stating so!  https://github.com/CleanCut/green/issues/new  Unless some people
request it, it will be removed in 2.0
""")
        import time
        time.sleep(2)
    if args.shouldExit:
        return args.exitCode

    # Clear out all the passed-in-options just in case someone tries to run a
    # test that assumes sys.argv is clean.  I can't guess at the script name
    # that they want, though, so we'll just leave ours.
    sys.argv = sys.argv[:1]

    # Set up our various main objects
    from green.loader import loadTargets
    from green.runner import run
    from green.output import GreenStream, debug
    import green.output
    from green.suite import GreenTestSuite
    GreenTestSuite.args = args

    if args.debug:
        green.output.debug_level = args.debug

    stream = GreenStream(sys.stdout, html = args.html)

    # Location of shell completion file
    if args.completion_file:
        print(os.path.join(os.path.dirname(__file__), 'shell_completion.sh'))
        return 0

    # Argument-completion for bash and zsh (for test-target completion)
    if args.completions:
        from green.loader import getCompletions
        print(getCompletions(args.targets))
        return 0

    # Option-completion for bash and zsh
    if args.options:
        print('\n'.join(sorted(args.store_opt.options)))
        return 0

    # Add debug logging for stuff that happened before this point here
    if config.files_loaded:
        debug("Loaded config file(s): {}".format(
            ', '.join(config.files_loaded)))

    # Discover/Load the test suite
    if testing:
        test_suite = None
    else:
        test_suite = loadTargets(args.targets, file_pattern = args.file_pattern)

    # We didn't even load 0 tests...
    if not test_suite:
        debug(
            "No test loading attempts succeeded.  Created an empty test suite.")
        test_suite = GreenTestSuite()

    # Actually run the test_suite
    if testing:
        result = lambda: None
        result.wasSuccessful = lambda: 0
    else:
        result = run(test_suite, stream, args) # pragma: no cover

    if args.run_coverage and ((not testing) or coverage_testing):
        stream.writeln()
        args.cov.stop()
        args.cov.save()
        args.cov.combine()
        args.cov.save()
        args.cov.report(file=stream, omit=args.omit_patterns)
    return(int(not result.wasSuccessful()))
Beispiel #10
0
def main(testing=False):
    args = config.parseArguments()
    args = config.mergeConfig(args, testing)

    if args.shouldExit:
        return args.exitCode

    # Clear out all the passed-in-options just in case someone tries to run a
    # test that assumes sys.argv is clean.  I can't guess at the script name
    # that they want, though, so we'll just leave ours.
    sys.argv = sys.argv[:1]

    # Set up our various main objects
    from green.loader import loadTargets
    from green.runner import run
    from green.output import GreenStream, debug
    import green.output
    from green.suite import GreenTestSuite
    GreenTestSuite.args = args

    if args.debug:
        green.output.debug_level = args.debug

    stream = GreenStream(sys.stdout, disable_windows=args.disable_windows)

    # Location of shell completion file
    if args.completion_file:
        print(os.path.join(os.path.dirname(__file__), 'shell_completion.sh'))
        return 0

    # Argument-completion for bash and zsh (for test-target completion)
    if args.completions:
        from green.loader import getCompletions
        print(getCompletions(args.targets))
        return 0

    # Option-completion for bash and zsh
    if args.options:
        print('\n'.join(sorted(args.store_opt.options)))
        return 0

    # Add debug logging for stuff that happened before this point here
    if config.files_loaded:
        debug("Loaded config file(s): {}".format(
            ', '.join(config.files_loaded)))

    # Discover/Load the test suite
    if testing:
        test_suite = None
    else:  # pragma: no cover
        test_suite = loadTargets(args.targets, file_pattern=args.file_pattern)

    # We didn't even load 0 tests...
    if not test_suite:
        debug(
            "No test loading attempts succeeded.  Created an empty test suite.")
        test_suite = GreenTestSuite()

    # Actually run the test_suite
    result = run(test_suite, stream, args, testing)

    return(int(not result.wasSuccessful()))
Beispiel #11
0
def main(testing=False, coverage_testing=False):
    args = config.parseArguments()
    args = config.mergeConfig(args, testing, coverage_testing)
    if args.shouldExit:
        return args.exitCode

    # Clear out all the passed-in-options just in case someone tries to run a
    # test that assumes sys.argv is clean.  I can't guess at the script name
    # that they want, though, so we'll just leave ours.
    sys.argv = sys.argv[:1]

    # Set up our various main objects
    from green.loader import loadTargets
    from green.runner import GreenTestRunner
    from green.output import GreenStream, debug
    import green.output
    if args.debug:
        green.output.debug_level = args.debug

    stream = GreenStream(sys.stdout, html = args.html)
    runner = GreenTestRunner(verbosity = args.verbose, stream = stream,
            termcolor=args.termcolor, subprocesses=args.subprocesses,
            run_coverage=args.run_coverage, omit=args.omit)

    # Location of shell completion file
    if args.completion_file:
        print(os.path.join(os.path.dirname(__file__), 'shell_completion.sh'))
        return 0

    # Argument-completion for bash and zsh (for test-target completion)
    if args.completions:
        from green.loader import getCompletions
        print(getCompletions(args.targets))
        return 0

    # Option-completion for bash and zsh
    if args.options:
        print('\n'.join(sorted(args.store_opt.options)))
        return 0

    # Add debug logging for stuff that happened before this point here
    if config.files_loaded:
        debug("Loaded config file(s): {}".format(
            ', '.join(config.files_loaded)))

    # Discover/Load the TestSuite
    if testing:
        test_suite = None
    else:
        test_suite = loadTargets(args.targets)

    # We didn't even load 0 tests...
    if not test_suite:
        debug(
            "No test loading attempts succeeded.  Created an empty test suite.")
        test_suite = unittest.suite.TestSuite()

    # Actually run the test_suite
    if testing:
        result = lambda: None
        result.wasSuccessful = lambda: 0
    else:
        result = runner.run(test_suite) # pragma: no cover

    if args.run_coverage and ((not testing) or coverage_testing):
        stream.writeln()
        args.cov.stop()
        args.cov.save()
        args.cov.combine()
        args.cov.save()
        args.cov.report(file=stream, omit=args.omit)
    return(int(not result.wasSuccessful()))