Changeset e62a134 in sasmodels


Ignore:
Timestamp:
Apr 8, 2016 6:48:35 PM (9 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
49d2308
Parents:
0d99a6a
Message:

add type hinting to model_test

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernelpy.py

    r4bfd277 re62a134  
    1212from . import details 
    1313from .generate import F64 
     14 
     15try: 
     16    from typing import Union 
     17except: 
     18    pass 
     19else: 
     20    DType = Union[None, str, np.dtype] 
    1421 
    1522class PyModel(object): 
  • sasmodels/model_test.py

    r4bfd277 re62a134  
    5858from .modelinfo import expand_pars 
    5959 
     60try: 
     61    from typing import List, Iterator, Callable 
     62except ImportError: 
     63    pass 
     64else: 
     65    from .modelinfo import ParameterTable, ParameterSet, TestCondition, ModelInfo 
     66    from .kernelpy import PyModel, PyInput, PyKernel, DType 
     67 
    6068def call_ER(model_info, pars): 
     69    # type: (ModelInfo, ParameterSet) -> float 
    6170    """ 
    6271    Call the model ER function using *values*. *model_info* is either 
     
    7281 
    7382def call_VR(model_info, pars): 
     83    # type: (ModelInfo, ParameterSet) -> float 
    7484    """ 
    7585    Call the model VR function using *pars*. 
     
    8595 
    8696def _vol_pars(model_info, pars): 
     97    # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray] 
    8798    vol_pars = [get_weights(p, pars) 
    8899                for p in model_info.parameters.call_parameters 
     
    93104 
    94105def make_suite(loaders, models): 
     106    # type: (List[str], List[str]) -> unittest.TestSuite 
    95107    """ 
    96108    Construct the pyunit test suite. 
     
    102114    *models* is the list of models to test, or *["all"]* to test all models. 
    103115    """ 
    104  
    105     ModelTestCase = _hide_model_case_from_nosetests() 
     116    ModelTestCase = _hide_model_case_from_nose() 
    106117    suite = unittest.TestSuite() 
    107118 
     
    160171 
    161172 
    162 def _hide_model_case_from_nosetests(): 
     173def _hide_model_case_from_nose(): 
     174    # type: () -> type 
    163175    class ModelTestCase(unittest.TestCase): 
    164176        """ 
     
    171183        def __init__(self, test_name, model_info, test_method_name, 
    172184                     platform, dtype): 
     185            # type: (str, ModelInfo, str, str, DType) -> None 
    173186            self.test_name = test_name 
    174187            self.info = model_info 
     
    180193 
    181194        def run_all(self): 
     195            # type: () -> None 
    182196            smoke_tests = [ 
    183                 [{}, 0.1, None], 
    184                 [{}, (0.1, 0.1), None], 
    185                 [{}, 'ER', None], 
    186                 [{}, 'VR', None], 
     197                ({}, 0.1, None), 
     198                ({}, (0.1, 0.1), None), 
     199                ({}, 'ER', None), 
     200                ({}, 'VR', None), 
    187201                ] 
    188202 
     
    207221 
    208222        def run_one(self, model, test): 
    209             pars, x, y = test 
    210             pars = expand_pars(self.info.parameters, pars) 
     223            # type: (PyModel, TestCondition) -> None 
     224            user_pars, x, y = test 
     225            pars = expand_pars(self.info.parameters, user_pars) 
    211226 
    212227            if not isinstance(y, list): 
     
    222237                actual = [call_VR(model.info, pars)] 
    223238            elif isinstance(x[0], tuple): 
    224                 Qx, Qy = zip(*x) 
    225                 q_vectors = [np.array(Qx), np.array(Qy)] 
     239                qx, qy = zip(*x) 
     240                q_vectors = [np.array(qx), np.array(qy)] 
    226241                kernel = model.make_kernel(q_vectors) 
    227242                actual = call_kernel(kernel, pars) 
     
    247262 
    248263def is_near(target, actual, digits=5): 
     264    # type: (float, float, int) -> bool 
    249265    """ 
    250266    Returns true if *actual* is within *digits* significant digits of *target*. 
     
    255271 
    256272def main(): 
     273    # type: () -> int 
    257274    """ 
    258275    Run tests given is sys.argv. 
     
    288305  python -m sasmodels.model_test [-v] [opencl|dll] model1 model2 ... 
    289306 
    290 If -v is included on the command line, then use verboe output. 
     307If -v is included on the command line, then use verbose output. 
    291308 
    292309If neither opencl nor dll is specified, then models will be tested with 
    293 both opencl and dll; the compute target is ignored for pure python models. 
     310both OpenCL and dll; the compute target is ignored for pure python models. 
    294311 
    295312If model1 is 'all', then all except the remaining models will be tested. 
     
    306323 
    307324def model_tests(): 
     325    # type: () -> Iterator[Callable[[], None] 
    308326    """ 
    309327    Test runner visible to nosetests. 
  • sasmodels/modelinfo.py

    r0d99a6a re62a134  
    640640    info.variant_info = getattr(kernel_module, 'variant_info', None) 
    641641    info.source = getattr(kernel_module, 'source', []) 
     642    # TODO: check the structure of the tests 
    642643    info.tests = getattr(kernel_module, 'tests', []) 
    643644    info.ER = getattr(kernel_module, 'ER', None) 
     
    712713    source = None           # type: List[str] 
    713714    tests = None            # type: List[TestCondition] 
    714     ER = None               # type: Optional[Callable[[np.ndarray, ...], float]] 
    715     VR = None               # type: Optional[Callable[[np.ndarray, ...], float]] 
     715    ER = None               # type: Optional[Callable[[np.ndarray, ...], np.ndarray]] 
     716    VR = None               # type: Optional[Callable[[np.ndarray, ...], Tuple[np.ndarray, np.ndarray]]] 
    716717    form_volume = None      # type: Optional[Callable[[np.ndarray, ...], float]] 
    717718    Iq = None               # type: Optional[Callable[[np.ndarray, ...], np.ndarray]] 
Note: See TracChangeset for help on using the changeset viewer.