Esempio n. 1
0
def test_parameters_get_parameter_value():
    allParams = parameters.Parameters()
    allParams.update_parameter('INPUT_CATEGORIES', 'value1')
    assert allParams.get_parameter_value('INPUT_CATEGORIES') == 'value1'
    with pytest.raises(KeyError) as excinfo:
        allParams.get_parameter_value('Param2')
    assert str(excinfo.value) == "'Param2'"
Esempio n. 2
0
def test_change_category_name():
    p = parameters.Parameters()
    p.update_parameter('INPUT_CATEGORIES', 'i1; i2; i3')
    p.change_category_name('i1', 'newInput')
    assert 'newInput' in p.get_set_of_parameters('INPUT_CATEGORIES')
    assert 'i1' not in p.get_set_of_parameters('INPUT_CATEGORIES')

    p.update_parameter('INPUT_CATEGORIES', 'i1; i2; i3')
    p.update_parameter('ABS_WEIGHT_RESTRICTIONS', 'i1 <= 9; i2 >= 7; 0 <= i3')
    p.change_category_name('i1', 'newInput')
    assert 'newInput' in p.get_set_of_parameters('INPUT_CATEGORIES')
    assert 'i1' not in p.get_set_of_parameters('INPUT_CATEGORIES')
    assert 'newInput <= 9' in p.get_set_of_parameters(
        'ABS_WEIGHT_RESTRICTIONS')
    assert 'i1 <= 9' not in p.get_set_of_parameters('ABS_WEIGHT_RESTRICTIONS')

    p.update_parameter('INPUT_CATEGORIES', 'i1; i2; i3')
    p.update_parameter('ABS_WEIGHT_RESTRICTIONS', 'i1 <= 9; i2 >= 7; 0 <= i3')
    p.update_parameter('PRICE_RATIO_RESTRICTIONS', 'i1/i2 >= 2; r/  i1 <= 7')
    p.update_parameter('CATEGORICAL_CATEGORY', 'category')
    p.change_category_name('i1', 'newInput')
    assert 'newInput' in p.get_set_of_parameters('INPUT_CATEGORIES')
    assert 'i1' not in p.get_set_of_parameters('INPUT_CATEGORIES')
    assert 'newInput <= 9' in p.get_set_of_parameters(
        'ABS_WEIGHT_RESTRICTIONS')
    assert 'i1 <= 9' not in p.get_set_of_parameters('ABS_WEIGHT_RESTRICTIONS')
    assert 'newInput/i2 >= 2' in p.get_set_of_parameters(
        'PRICE_RATIO_RESTRICTIONS')
    assert 'i1/i2 >= 2' not in p.get_set_of_parameters(
        'PRICE_RATIO_RESTRICTIONS')
    assert 'r/newInput <= 7' in p.get_set_of_parameters(
        'PRICE_RATIO_RESTRICTIONS')
    assert 'r/  i1 <= 7' not in p.get_set_of_parameters(
        'PRICE_RATIO_RESTRICTIONS')
    assert p.get_parameter_value('CATEGORICAL_CATEGORY') == 'category'
Esempio n. 3
0
def test_file_write_and_read_valid_parameters():
    p = parameters.Parameters()
    p.update_parameter('DEA_FORM', 'value1')
    p.update_parameter('INPUT_CATEGORIES', 'some long value')
    p.update_parameter('OUTPUT_CATEGORIES', 'some/linux/type/path/file.txt')
    p.update_parameter('DATA_FILE', '\some\Windows\like\path\p.txt')
    filename = 'test_valid_params.params'
    parameters.write_parameters_to_file(p, filename)
    paramsFromFile = parameters.parse_parameters_from_file(filename)
    for key, value in p.params.items():
        assert key in paramsFromFile.params
        assert paramsFromFile.params[key] == value
    os.remove(filename)
Esempio n. 4
0
 def __init__(self,
              return_to_scale='VRS',
              form='env',
              orientation='output'):
     self.__return_to_scale = return_to_scale
     self.__form = form
     self.__orientation = orientation
     self.__dea_params = param.Parameters()
     self.__dea_params.update_parameter('RETURN_TO_SCALE', return_to_scale)
     self.__dea_params.update_parameter('DEA_FORM', form)
     self.__dea_params.update_parameter('ORIENTATION', orientation)
     self.__dea_params.update_parameter('INPUT_CATEGORIES', 'i1')
     self.__dea_params.update_parameter('OUTPUT_CATEGORIES', 'o1')
Esempio n. 5
0
def test_parameters_update_parameter():
    p = parameters.Parameters()
    p.update_parameter('DEA_FORM', 'value1')
    assert p.get_parameter_value('DEA_FORM') == 'value1'
    p.update_parameter('INPUT_CATEGORIES', 'new value')
    assert p.get_parameter_value('INPUT_CATEGORIES') == 'new value'
    p.update_parameter('INPUT_CATEGORIES', '')
    assert p.get_parameter_value('INPUT_CATEGORIES') == ''
    with pytest.raises(KeyError) as excinfo:
        p.update_parameter('param2', 'value2')
    assert str(excinfo.value) == ("'Parameter param2 does not exists in"
                                  " the dictionary'")
    with pytest.raises(ValueError) as excinfo:
        p.update_parameter('INPUT_CATEGORIES', '   ')
    assert str(excinfo.value) == ('Trying to update parameter '
                                  '<INPUT_CATEGORIES> with not valid '
                                  'value <   >')
Esempio n. 6
0
def test_get_set_of_parameters():
    p = parameters.Parameters()
    p.update_parameter('INPUT_CATEGORIES', 'i1; i2; i3')
    s = p.get_set_of_parameters('INPUT_CATEGORIES')
    assert len(s) == 3
    assert 'i1' in s
    assert 'i2' in s
    assert 'i3' in s
    p.update_parameter('OUTPUT_CATEGORIES',
                       'i1;   i  2  ; ;  i3;    ;;;;;;;;;;')
    s = p.get_set_of_parameters('OUTPUT_CATEGORIES')
    assert len(s) == 3
    assert 'i1' in s
    assert 'i  2' in s
    assert 'i3' in s
    p.update_parameter('INPUT_CATEGORIES', 'i1')
    s = p.get_set_of_parameters('INPUT_CATEGORIES')
    assert len(s) == 1
    assert 'i1' in s
    p.update_parameter('OUTPUT_CATEGORIES', '')
    s = p.get_set_of_parameters('OUTPUT_CATEGORIES')
    assert len(s) == 0