Exemplo n.º 1
0
def run_tests(tests):
    import eventhandler

    failed = 0
    for test in tests:
        eventhandler.reset_test_state()

        try:
            payload = get_payload(test['filename'])['payload']
            initial = test['initial']
            api = TestAPIProvider(payload, 'highfive',
                                  initial['new_contributor'],
                                  initial['labels'], initial['assignee'],
                                  initial['diff'])
            handle_payload(api, payload)
            expected = test['expected']
            if 'comments' in expected:
                assert len(api.comments_posted
                           ) == expected['comments'], "%d == %d" % (len(
                               api.comments_posted), expected['comments'])
            if 'labels' in expected:
                assert api.labels == expected['labels'], "%s == %s" % (
                    api.labels, expected['labels'])
            if 'assignee' in expected:
                assert api.assignee == expected['assignee'], "%s == %s" % (
                    api.assignee, expected['assignee'])
        except AssertionError, error:
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)  # Fixed format
            tb_info = traceback.extract_tb(tb)
            filename, line, func, text = tb_info[-1]
            print('{}: An error occurred on line {} in statement {}'.format(
                test['filename'], line, text))
            print(error)
            failed += 1
Exemplo n.º 2
0
Arquivo: test.py Projeto: zwn/highfive
def run_tests(tests):
    import eventhandler

    failed = 0
    for test in tests:
        eventhandler.reset_test_state()

        try:
            payload = get_payload(test['filename'])['payload']
            initial = test['initial']
            api = TestAPIProvider(payload, 'highfive', initial['new_contributor'], initial['labels'],
                                  initial['assignee'], initial['diff'], initial['pull_request'])
            handle_payload(api, payload)
            expected = test['expected']
            if 'comments' in expected:
                assert len(api.comments_posted) == expected['comments'], "%d == %d" % (len(api.comments_posted), expected['comments'])
            if 'labels' in expected:
                assert api.labels == expected['labels'], "%s == %s" % (api.labels, expected['labels'])
            if 'assignee' in expected:
                assert api.assignee == expected['assignee'], "%s == %s" % (api.assignee, expected['assignee'])
        except AssertionError, error:
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb) # Fixed format
            tb_info = traceback.extract_tb(tb)
            filename, line, func, text = tb_info[-1]
            print('{}: An error occurred on line {} in statement {}'.format(test['filename'], line, text))
            print(error)
            failed += 1
Exemplo n.º 3
0
def run_tests(tests, warn=True, overwrite=False):
    failed, dirty = 0, 0
    for handler, test in tests:
        eventhandler.reset_test_state()

        try:
            initial, expected, = test['initial'], test['expected']
            wrapper = test['wrapper']
            payload = wrapper.json['payload']
            api = TestAPIProvider(payload,
                                  'highfive',
                                  initial['new_contributor'],
                                  initial['labels'],
                                  initial['assignee'],
                                  initial['diff'],
                                  initial['pull_request'])
            handle_payload(api, payload, [handler])

            if 'comments' in expected:
                assert len(api.comments_posted) == expected['comments'], \
                    "%d == %d" % (len(api.comments_posted),
                                  expected['comments'])
            if 'labels' in expected:
                assert api.labels == expected['labels'], \
                    "%s == %s" % (api.labels, expected['labels'])
            if 'assignee' in expected:
                assert api.assignee == expected['assignee'], \
                    "%s == %s" % (api.assignee, expected['assignee'])

            # If this is the last test in the file, then it's time for cleanup
            if test['clean']:
                cleaned = wrapper.clean(warn)

                if wrapper.unused and not overwrite:
                    error = '\033[91m%s\033[0m: The file has %s unused nodes'
                    print(error % (test['filename'], wrapper.unused))
                    dirty += 1

                if overwrite:   # useful for cleaning up the tests locally
                    clean_dict = test['dict']
                    clean_dict['payload'] = cleaned['payload']
                    with open(test['filename'], 'w') as fd:
                        json.dump(clean_dict, fd, indent=2)
                    error = '\033[91m%s\033[0m: Rewrote the JSON file'
                    print(error % test['filename'])

        except AssertionError as error:
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)      # Fixed format
            tb_info = traceback.extract_tb(tb)
            filename, line, func, text = tb_info[-1]
            error_template = '\033[91m{}\033[0m: An error occurred on ' + \
                             'line {} in statement {}'
            print(error_template.format(test['filename'], line, text))
            print(error)
            failed += 1

    return failed, dirty