Opened 10 months ago

Last modified 10 months ago

#1154 new defect

Refactor tests so that gui doesn't reload module each time

Reported by: butler Owned by: pkienzle
Priority: major Milestone: SasView 4.3.0
Component: sasmodels Keywords:
Cc: Work Package: SasView Framework Enhancements


The fundamental problem of not being able to use the model editors in SasView without throwing errors was fixed by SasView PR 161 for release 4.2. The problem was that when the sasmodels unit tests were loading the models twice. When they loaded the model the second time, the math globals were being overwritten so that rather than functions they become "None" objects for the first instance of that model. The error that was being thrown is

File "sas\sascalc\data_util\calcthread.pyc", line 274, in _run
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

However, in that PR, Paul Kienzle suggests that this can be done more cleanly and points to his notes in the code itself documenting his ideas (reproduced below). Due to the increased complexity (and the fact that it touches both sasmodels and SasView) it was agreed to wait for 4.3 to implement. Note however that the sasmodels part has already been done and is sitting in the queue as a sasmodels PR 75 and includes notes on what to do in SasView to make the changes accessible to the SasView GUI.

    # TODO: fix model caching
    # model_test.run_one() is directly forcing a reload of the module, but
    # sasview_model is caching models that have already been loaded.
    # If the sasview load happens before the test, then the module is
    # reloaded out from under it, which causes the global variables in
    # the model function definitions to be cleared (at least in python 2.7).
    # To fix the proximal problem of models failing on test, perform the
    # run_one() tests first.  To fix the deeper problem we should either
    # remove caching from sasmodels.sasview_model.load_custom_model() or
    # add caching to sasmodels.custom.load_custom_kernel_module().  Another
    # option is to add a runTests method to SasviewModel which runs the
    # test suite directly from the model info structure.  Probably some
    # combination of options:
    #    (1) have this function (check_model) operate on a loaded model
    #    so that caching isn't needed in sasview_models.load_custom_model
    #    (2) add the runTests method to SasviewModel so that tests can
    #    be run on a loaded module.
    # Also, note that the model test suite runs the equivalent of the
    # "try running the model" block below, and doesn't need to be run
    # twice.  The reason for duplicating the block here is to generate
    # an exception that show_model_output can catch.  Need to write the
    # runTests method so that it returns success flag as well as output
    # string so that the extra test is not necessary.

Change History (1)

comment:1 Changed 10 months ago by butler

  • Work Package changed from SasView Bug Fixing to SasView Framework Enhancements
Note: See TracTickets for help on using tickets.