Ejemplo n.º 1
0
def test_add_unknown_enum_variable_value(persons, enum_variable):
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    with pytest.raises(SituationParsingError):
        simulation_builder.add_variable_value(persons, enum_variable,
                                              instance_index, 'Alicia',
                                              '2018-11', 'baz')
Ejemplo n.º 2
0
def test_add_variable_value_as_expression(persons):
    salary = persons.get_variable('salary')
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    simulation_builder.add_variable_value(persons, salary, instance_index,
                                          'Alicia', '2018-11', '3 * 1000')
    input_array = simulation_builder.get_input('salary', '2018-11')
    assert input_array[instance_index] == pytest.approx(3000)
Ejemplo n.º 3
0
def test_fail_on_date_parsing(persons, date_variable):
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    with pytest.raises(SituationParsingError) as excinfo:
        simulation_builder.add_variable_value(persons, date_variable,
                                              instance_index, 'Alicia',
                                              '2018-11', '2019-02-30')
    assert excinfo.value.error == {
        'persons': {
            'Alicia': {
                'datevar': {
                    '2018-11': "Can't deal with date: '2019-02-30'."
                }
            }
        }
    }
Ejemplo n.º 4
0
def test_fail_on_integer_overflow(persons, int_variable):
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    with pytest.raises(SituationParsingError) as excinfo:
        simulation_builder.add_variable_value(persons, int_variable,
                                              instance_index, 'Alicia',
                                              '2018-11', 9223372036854775808)
    assert excinfo.value.error == {
        'persons': {
            'Alicia': {
                'intvar': {
                    '2018-11':
                    "Can't deal with value: '9223372036854775808', it's too large for type 'integer'."
                }
            }
        }
    }
Ejemplo n.º 5
0
def test_fail_on_wrong_data(persons):
    salary = persons.get_variable('salary')
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    with pytest.raises(SituationParsingError) as excinfo:
        simulation_builder.add_variable_value(persons, salary, instance_index,
                                              'Alicia', '2018-11', 'alicia')
    assert excinfo.value.error == {
        'persons': {
            'Alicia': {
                'salary': {
                    '2018-11':
                    "Can't deal with value: expected type number, received 'alicia'."
                }
            }
        }
    }
Ejemplo n.º 6
0
def test_fail_on_ill_formed_expression(persons):
    salary = persons.get_variable('salary')
    instance_index = 0
    simulation_builder = SimulationBuilder()
    simulation_builder.entity_counts['persons'] = 1
    with pytest.raises(SituationParsingError) as excinfo:
        simulation_builder.add_variable_value(persons, salary, instance_index,
                                              'Alicia', '2018-11',
                                              '2 * / 1000')
    assert excinfo.value.error == {
        'persons': {
            'Alicia': {
                'salary': {
                    '2018-11':
                    "I couldn't understand '2 * / 1000' as a value for 'salary'"
                }
            }
        }
    }