Changes between Version 3 and Version 4 of UnitTests


Ignore:
Timestamp:
Apr 30, 2010 2:05:27 PM (13 years ago)
Author:
toby
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UnitTests

    v3 v4  
    1 The hope is that all sections of GSAS-II "model" code (as opposed to controller or view code in the MVC paradigm) will eventually have unit tests, as described below.
     1The hope is that all sections of GSAS-II computation aka "model" code (as opposed to controller or view code in the [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC paradigm]) will eventually have unit tests, as described below.
    22
    33=== Design philosophy ===
     
    1212=== Implementation ===
    1313
    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.
     14Tests 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{{{
     16def 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}}}
     28This 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{{{
     30if __name__ == '__main__':
     31    test0()
     32    test1()
     33    test2()
     34    test3()
     35    print "OK"
     36}}}
     37this allows command {{{python <file.py>}}} to run the test without the nosetests package.
    1538
     39Finally, file {{{unit_tests.py}}} is intended to have a comprehensive list of all unit tests in GSAS-II, so that the entire suite of tests can be run in one pass. This file should contain a set of routines, each named beginning with the string "test" to exercise the self-tests from each module. Where this code:
     40{{{
     41import GSASIIspc
     42def test_GSASIIspc():
     43    GSASIIspc.test0()
     44def test_GSASIIspc1():
     45    GSASIIspc.test1()
     46def test_GSASIIspc2():
     47    GSASIIspc.test2()
     48def test_GSASIIspc3():
     49    GSASIIspc.test3()
     50}}}
     51duplicates that in the previous section.