Example #1
0
def test_iteritems():
    a = [1, 2, 3]
    b = ["a", "b", "c"]
    d = dict(pyzip(a, b))
    for k, v in iteritems(d):
        assert k in a
        assert v in b
        assert d[k] == v
Example #2
0
def test_iteritems():
    a = [1, 2, 3]
    b = ['a', 'b', 'c']
    d = dict(pyzip(a, b))
    for k, v in iteritems(d):
        assert k in a
        assert v in b
        assert d[k] == v
Example #3
0
def test_iteritems_ordered_dict():
    a = [1, 2, 3]
    b = ["a", "b", "c"]
    d = OrderedDict(pyzip(a, b))
    for i, (k, v) in enumerate(iteritems(d)):
        assert k in a
        assert v in b
        assert d[k] == v
        assert b[i] == v
Example #4
0
def test_iteritems_ordered_dict():
    a = [1, 2, 3]
    b = ['a', 'b', 'c']
    d = OrderedDict(pyzip(a, b))
    for i, (k, v) in enumerate(iteritems(d)):
        assert k in a
        assert v in b
        assert d[k] == v
        assert b[i] == v
Example #5
0
def run_examples(config_file):
    ''' Run examples from config file '''
    # ---------------------------------------------------------------- #
    # Read Configuration files
    config_dict = read_config(config_file)
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # run tests
    num_tests = len(list(config_dict.keys()))

    test_outcomes = OrderedDict()

    for i, (test, test_dict) in enumerate(iteritems(config_dict)):
        print(''.center(100, '-'))
        print('Starting Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                      test).center(100))
        desc = textwrap.fill(', '.join(test_dict['description']), 100)
        print('Description: {0}'.format(desc))
        print(''.center(100, '-'))

        if 'processors' in test_dict:
            numofproc = test_dict['processors']
        else:
            numofproc = 1

        pr = cProfile.Profile()
        pr.enable()

        if test_dict['function'] == 'convert':
            try:
                convert.convert(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in conversion example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'convolution':
            try:
                convolution.convolution(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in convolution example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'parameters':
            try:
                parameters.parameters(test_dict['config_file'],
                                      numofproc=numofproc)
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in parameters example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        else:
            raise ValueError('Unknown function variable: '
                             '{0}'.format(test_dict['function']))

        pr.disable()
        if py3:
            s = io.StringIO()
        else:
            s = io.BytesIO()
        sortby = 'cumulative'
        ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
        ps.print_stats()

        print(''.center(100, '-'))
        print('Done With Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                       test).center(100))
        print('.....Printing Profile Information.....'.center(100))
        print(''.center(100, '-'))
        print(s.getvalue())
        print(''.center(100, '-'))

    print('Done with examples...printing summary')
    for test, outcome in iteritems(test_outcomes):
        print('\t{0}: {1}'.format(test, outcome))

    return 0
Example #6
0
def run_examples(config_file):
    ''' Run examples from config file '''
    # ---------------------------------------------------------------- #
    # Read Configuration files
    config_dict = read_config(config_file)
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # run tests
    num_tests = len(list(config_dict.keys()))

    test_outcomes = OrderedDict()

    for i, (test, test_dict) in enumerate(iteritems(config_dict)):
        print(''.center(100, '-'))
        print('Starting Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                      test).center(100))
        desc = textwrap.fill(', '.join(test_dict['description']), 100)
        print('Description: {0}'.format(desc))
        print(''.center(100, '-'))

        if 'processors' in test_dict:
            numofproc = test_dict['processors']
        else:
            numofproc = 1

        pr = cProfile.Profile()
        pr.enable()

        if test_dict['function'] == 'convert':
            try:
                convert.convert(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in conversion example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'convolution':
            try:
                convolution.convolution(test_dict['config_file'])
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in convolution example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        elif test_dict['function'] == 'parameters':
            try:
                parameters.parameters(test_dict['config_file'],
                                      numofproc=numofproc)
                test_outcomes[test] = 'Passed'
            except Exception as e:
                print('Error in parameters example: {0}'.format(test))
                test_outcomes[test] = 'Failed: {0}'.format(e)
        else:
            raise ValueError('Unknown function variable: '
                             '{0}'.format(test_dict['function']))

        pr.disable()
        if py3:
            s = io.StringIO()
        else:
            s = io.BytesIO()
        sortby = 'cumulative'
        ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
        ps.print_stats()

        print(''.center(100, '-'))
        print('Done With Test #{0} of {1}: {2}'.format(i + 1, num_tests,
                                                       test).center(100))
        print('.....Printing Profile Information.....'.center(100))
        print(''.center(100, '-'))
        print(s.getvalue())
        print(''.center(100, '-'))

    print('Done with examples...printing summary')
    for test, outcome in iteritems(test_outcomes):
        print('\t{0}: {1}'.format(test, outcome))

    return 0