Example #1
0
def test_validate_params_list():
    """Test the behaviour of validate_params on parameters which are of list
    type. Each entry in the list should satisfy the constraints described by
    references[parameter_name]['of']."""
    references = {
        'par1': {
            'type': list,
            'of': {
                'type': float,
                'in': [1., 2.]
            }
        }
    }
    parameters = {'par1': [1.]}

    validate_params(parameters, references)
Example #2
0
def test_validate_params():
    """These tests should fail because either the type of parameters[
    parameter_name] is incorrect, or because parameter not in references[
    parameter_name]['in']."""
    references = {'par1': {'type': int, 'in': [0, 1]}}
    parameters = {'par1': 0.5}

    with pytest.raises(TypeError):
        validate_params(parameters, references)

    parameters = {'par1': 2}
    with pytest.raises(ValueError):
        validate_params(parameters, references)

    parameters = {'par0': 1}
    with pytest.raises(KeyError):
        validate_params(parameters, references)
Example #3
0
def test_validate_params_tuple_of_types():
    references = {
        'n_coefficients': {
            'type': (type(None), list, int),
            'in': Interval(1, np.inf, closed='left'),
            'of': {
                'type': Integral,
                'in': Interval(1, np.inf, closed='left')
            }
        }
    }
    parameters = {'n_coefficients': None}

    validate_params(parameters, references)

    parameters['n_coefficients'] = 1
    validate_params(parameters, references)

    parameters['n_coefficients'] = 1.
    with pytest.raises(TypeError):
        validate_params(parameters, references)

    parameters['n_coefficients'] = 0
    with pytest.raises(ValueError):
        validate_params(parameters, references)

    parameters['n_coefficients'] = [1, 2]
    validate_params(parameters, references)

    parameters['n_coefficients'] = [1., 2.]
    with pytest.raises(TypeError):
        validate_params(parameters, references)

    parameters['n_coefficients'] = [0, 2]
    with pytest.raises(ValueError):
        validate_params(parameters, references)