14 | | Tests are to be included directly in the GSAS-II module by defining test functions. The test functions should be named to start with the string "test" and should not require any arguments. The should use assert or raise to report an unexpected result and should not print anything if the test succeeds. If the test requires more input than can comfortably be included in the module itself, the input should be placed in directory {{{testinp\}}}. If routines are used to generate this input, the generating routines can also be placed here. |
| 14 | Tests are to be included directly in the GSAS-II module by defining test functions. The test functions should be named to start with the string "test" and should not require any arguments. The test could should use assert or raise to report an unexpected result and should not print anything if the test succeeds. If the test requires more input than can comfortably be included in the module itself, the input should be placed in directory {{{testinp\}}}. If routines are used to generate this input, the generating routines can also be placed there. The code to implement the test can then look like this: |
| 15 | {{{ |
| 16 | def test1(): |
| 17 | ''' test #1: SpcGroup and SGPrint against previous results''' |
| 18 | testdir = ospath.join(mypath,'testinp') |
| 19 | if ospath.exists(testdir): |
| 20 | if testdir not in sys.path: sys.path.insert(0,testdir) |
| 21 | import spctestinp |
| 22 | def CompareSpcGroup(spc, referr, refdict, reflist): |
| 23 | 'Compare output from GSASIIspc.SpcGroup with results from a previous run' |
| 24 | #... |
| 25 | for spc in spctestinp.SGdat: |
| 26 | CompareSpcGroup(spc, 0, spctestinp.SGdat[spc], spctestinp.SGlist[spc] ) |
| 27 | }}} |
| 28 | This allows the python nosetests to perform tests on the module using command {{{nosetests <file.py>}}} to run the test on the file ({{{file.py}}}). It is also convenient if the tests are implemented in a code section that is run if the file is run directly, rather than imported, |
| 29 | {{{ |
| 30 | if __name__ == '__main__': |
| 31 | test0() |
| 32 | test1() |
| 33 | test2() |
| 34 | test3() |
| 35 | print "OK" |
| 36 | }}} |
| 37 | this allows command {{{python <file.py>}}} to run the test without the nosetests package. |