| 1 | """ |
|---|
| 2 | Option parser for all tests |
|---|
| 3 | |
|---|
| 4 | Needs to be a separate module to avoid circular imports |
|---|
| 5 | """ |
|---|
| 6 | |
|---|
| 7 | import sys, optparse |
|---|
| 8 | |
|---|
| 9 | def option_parser(): |
|---|
| 10 | """ |
|---|
| 11 | Returns the option parser for tests. |
|---|
| 12 | |
|---|
| 13 | This parser needs to be able to handle all flags that may be passed |
|---|
| 14 | to any test |
|---|
| 15 | |
|---|
| 16 | Due to the optparse desing we cannot create a 'partial' option parser |
|---|
| 17 | that would ignore extra parameters while allowing it to be later be |
|---|
| 18 | extended. So it is either every flag goes the main option parser, |
|---|
| 19 | or each module will have to implement almost identical parsers. |
|---|
| 20 | |
|---|
| 21 | Having one large option parser seemed the lesser of two bad choices. |
|---|
| 22 | """ |
|---|
| 23 | |
|---|
| 24 | parser = optparse.OptionParser() |
|---|
| 25 | |
|---|
| 26 | # passing -n will disable the pathfix, use it to test global pygr distributions |
|---|
| 27 | parser.add_option( |
|---|
| 28 | '-n', '--nopath', action="store_true", dest="no_pathfix", default=False, |
|---|
| 29 | help="do not alter the python import path" |
|---|
| 30 | ) |
|---|
| 31 | |
|---|
| 32 | # add the regular build directory rather than the in place directory |
|---|
| 33 | parser.add_option( |
|---|
| 34 | '-b', '--buildpath', action="store_true", dest="builddir", default=False, |
|---|
| 35 | help="use the platform specific build directory", |
|---|
| 36 | ) |
|---|
| 37 | |
|---|
| 38 | # stops testing immediately after a test suite fails |
|---|
| 39 | parser.add_option( |
|---|
| 40 | '-s', '--strict', action="store_true", |
|---|
| 41 | dest="strict", default=False, |
|---|
| 42 | help="stops testing after a test suite fails" |
|---|
| 43 | ) |
|---|
| 44 | |
|---|
| 45 | # exclude the modules listed in arguments from all the tests |
|---|
| 46 | parser.add_option( |
|---|
| 47 | '-x', '--exclude', action="store_true", |
|---|
| 48 | dest="exclude", default=False, |
|---|
| 49 | help="excludes the files that are listed" |
|---|
| 50 | ) |
|---|
| 51 | |
|---|
| 52 | # verbosity can be 0,1 and 2 (increasing verbosity) |
|---|
| 53 | parser.add_option( |
|---|
| 54 | '-v', '--verbosity', action="store", |
|---|
| 55 | dest="verbosity", type="int", default=1, |
|---|
| 56 | help="sets the verbosity (0, 1, or 2)", |
|---|
| 57 | ) |
|---|
| 58 | |
|---|
| 59 | # reset the test directory |
|---|
| 60 | parser.add_option( |
|---|
| 61 | '-r', '--reset', action="store_true", |
|---|
| 62 | dest="reset", default=False, |
|---|
| 63 | help="resets the test directory" |
|---|
| 64 | ) |
|---|
| 65 | |
|---|
| 66 | # long options are typically used only within individual tests |
|---|
| 67 | |
|---|
| 68 | # executes figleaf to collect the coverage data |
|---|
| 69 | parser.add_option( |
|---|
| 70 | '--coverage', action="store_true", dest="coverage", default=False, |
|---|
| 71 | help="runs figleaf and collects the coverage information into the html directory" |
|---|
| 72 | ) |
|---|
| 73 | |
|---|
| 74 | # runs the performance tests |
|---|
| 75 | parser.add_option( |
|---|
| 76 | '--performance', action="store_true", dest="performance", default=False, |
|---|
| 77 | help="runs the performance tests (not implemented)" |
|---|
| 78 | ) |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | return parser |
|---|
| 82 | |
|---|
| 83 | if __name__ == '__main__': |
|---|
| 84 | # list flags here |
|---|
| 85 | flags = " --coverage" |
|---|
| 86 | |
|---|
| 87 | sys.argv.extend( flags.split() ) |
|---|
| 88 | parser = option_parser() |
|---|
| 89 | options, args = parser.parse_args() |
|---|
| 90 | |
|---|
| 91 | print options |
|---|
| 92 | |
|---|
| 93 | |
|---|