|
2 | 2 |
|
3 | 3 | from argparse import ArgumentParser |
4 | 4 | import array |
5 | | -import average |
6 | 5 |
|
7 | | - |
8 | | -size = 10 |
| 6 | +DEFAULT_SIZE = 10 |
9 | 7 |
|
10 | 8 | arg_parser = ArgumentParser(description='test Cython errors') |
11 | 9 | arg_parser.add_argument('--m', type=int, default=0, help='lower bound') |
12 | | -arg_parser.add_argument('--n', type=int, default=size, help='upper bound') |
| 10 | +arg_parser.add_argument('--n', type=int, default=DEFAULT_SIZE, |
| 11 | + help='upper bound') |
| 12 | +arg_parser.add_argument('--size', type=int, default=DEFAULT_SIZE, |
| 13 | + help='array size') |
| 14 | +arg_parser.add_argument('--implementation', choices=['pure', 'cython'], |
| 15 | + default='cython', help='implementation to use') |
13 | 16 | options = arg_parser.parse_args() |
14 | | -data = array.array('d', list(range(size))) |
| 17 | +if options.implementation == 'cython': |
| 18 | + from average import average, average_no_except |
| 19 | +elif options.implementation == 'pure': |
| 20 | + from average_pure import average, average_no_except |
| 21 | +data = array.array('d', list(range(options.size))) |
15 | 22 | print('with except:') |
16 | 23 | try: |
17 | | - print(average.average(data, options.m, options.n)) |
| 24 | + print(average(data, options.m, options.n)) |
18 | 25 | except Exception as e: |
19 | 26 | print('caught exception {0}: {1}'.format(str(e.__class__), str(e))) |
20 | 27 | print('without except:') |
21 | 28 | try: |
22 | | - print(average.average_no_except(data, options.m, options.n)) |
| 29 | + print(average_no_except(data, options.m, options.n)) |
23 | 30 | print('no exception caught') |
24 | 31 | except Exception as e: |
25 | 32 | print('caught exception {0}: {1}'.format(e.__class__, str(e))) |
0 commit comments