Esempio n. 1
0
def test_table_field_set():
    context = {'default': 'default'}

    table = Table('default')
    table.name = Simple('name')('default')
    table.magnitude = FloatRange('magnitude')('default')
    table.target = FormattedString(
            'target', format_string='{color}_{series}',
            format_parameters={'color': ['RED', 'GREEN', 'BLUE'], 'series': ['00']})('default')

    table.name.put_value_data(context,
                              value='Foo')
    table.magnitude.put_value_data(context,
                                   minimum=0.3,
                                   maximum=0.4,
                                   precision=0.01,
                                   sign_start=-1,
                                   sign_end=-1)
    table.target.put_value_data(context,
                                color={'RED': 0, 'BLUE': 4, 'GREEN': 2},
                                series={'00': 1})

    assert table.name.compute(context) == 'Foo'
    assert -0.4 <= table.magnitude.compute(context) <= -0.3
    assert table.target.compute(context) in ['BLUE_00', 'GREEN_00']
Esempio n. 2
0
def _create_table(context_key):
    table = Table(context_key)
    table.name = Simple('name')(context_key)
    table.magnitude = FloatRange('magnitude')(context_key)
    table.target = FormattedString(
            'target', format_string='{color}_{series}',
            format_parameters={'color': ['RED', 'GREEN', 'BLUE'], 'series': ['00']})(context_key)

    return table
Esempio n. 3
0
def test_table_instantiation():
    table = Table()
    table.name = Simple('name')('default')
    table.magnitude = FloatRange('magnitude')('default')
    table.target = FormattedString(
            'target',
            format_string='{color}_{series}',
            format_parameters={'color': ['RED', 'GREEN', 'BLUE'], 'series': ['00']}
    )('default')

    assert isinstance(table, Table)
Esempio n. 4
0
def test_table_import_json():
    context = {'default': 'default'}

    table = Table('default')
    table.name = Simple('name')('default')
    table.magnitude = FloatRange('magnitude')('default')
    table.target = FormattedString(
            'target', format_string='{color}_{series}',
            format_parameters={'color': ['RED', 'GREEN', 'BLUE'], 'series': ['00']})('default')

    table.import_json(_table_json)

    assert table.name.compute(context) == 'Success'
    assert 6.0 <= table.magnitude.compute(context) <= 7.0
    assert table.target.compute(context) == 'RED_00'