Beispiel #1
0
def test_data_config_defaults():
    """Testing default settings of the DataConfig object."""
    data_config = DataConfig(identifier='Daylight-factor',
                             object_type='grid',
                             unit='Percentage',
                             path='tests/assets/df_results')

    assert not data_config.hide
    assert data_config.legend_parameters == LegendConfig()
Beispiel #2
0
def test_get_legend_range():
    """Test if the _get_legend_range supplies correct range."""
    path = r'tests/assets/gridbased.hbjson'
    model = Model.from_hbjson(path)
    # if neither min nor max is set
    lc = LegendConfig()
    dc = DataConfig(identifier='test',
                    object_type=DataSetNames.grid,
                    unit='sample',
                    path='.',
                    legend_parameters=lc)
    legend_range = model._get_legend_range(dc)
    assert legend_range == [None, None]

    # if both min and max are set
    lc = LegendConfig(min=0, max=0)
    dc = DataConfig(identifier='test',
                    object_type=DataSetNames.grid,
                    unit='sample',
                    path='.',
                    legend_parameters=lc)
    legend_range = model._get_legend_range(dc)
    assert legend_range == [0.0, 0.0]

    # if only min is set
    lc = LegendConfig(min=0)
    dc = DataConfig(identifier='test',
                    object_type=DataSetNames.grid,
                    unit='sample',
                    path='.',
                    legend_parameters=lc)
    legend_range = model._get_legend_range(dc)
    assert legend_range == [0.0, None]

    # if only max is set
    lc = LegendConfig(max=0)
    dc = DataConfig(identifier='test',
                    object_type=DataSetNames.grid,
                    unit='sample',
                    path='.',
                    legend_parameters=lc)
    legend_range = model._get_legend_range(dc)
    assert legend_range == [None, 0.0]
Beispiel #3
0
def test_legend_config_defaults():
    """Testting default settings of the LegendConfig object."""
    legend_config = LegendConfig()
    assert legend_config.color_set == ColorSets.ecotect
    assert legend_config.min == Autocalculate()
    assert legend_config.max == Autocalculate()
    assert not legend_config.hide_legend
    assert legend_config.orientation == Orientation.vertical
    assert legend_config.width == 0.05
    assert legend_config.height == 0.45
    assert legend_config.position == [0.9, 0.5]
    assert legend_config.color_count == Autocalculate()
    assert legend_config.label_count == Autocalculate()
    assert legend_config.decimal_count == DecimalCount.default
    assert legend_config.preceding_labels == False
    assert legend_config.label_parameters == TextConfig()
    assert legend_config.title_parameters == TextConfig(bold=True)
Beispiel #4
0
def test_data_config_legend_parameter_validator():
    """Testing the legend parameter validator in DataConfig object."""

    # width greater than position in X direction
    legend_params = LegendConfig()
    legend_params.position = [0.5, 0.5]
    legend_params.width = 0.6
    with pytest.raises(ValidationError):
        data_config = DataConfig(identifier='Daylight-factor',
                                 object_type='grid',
                                 unit='Percentage',
                                 path='tests/assets/df_results',
                                 legend_parameters=legend_params)

    # height greater than position in Y direction
    legend_params = LegendConfig()
    legend_params.position = [0.5, 0.5]
    legend_params.height = 0.6
    with pytest.raises(ValidationError):
        data_config = DataConfig(identifier='Daylight-factor',
                                 object_type='grid',
                                 unit='Percentage',
                                 path='tests/assets/df_results',
                                 legend_parameters=legend_params)
Beispiel #5
0
def text_legend_config_validators():
    """Testting validators of LegendConfig object."""
    legend_config = LegendConfig()

    with pytest.raises(ValidationError):
        legend_config.colors = "red"

    with pytest.raises(ValidationError):
        legend_config.colors = 255

    legend_config.min = -10
    assert legend_config.min == -10

    with pytest.raises(ValidationError):
        legend_config.max = -20

    with pytest.raises(ValidationError):
        legend_config.min = 'less'

    with pytest.raises(ValidationError):
        legend_config.max = 'more'

    with pytest.raises(ValidationError):
        legend_config.orientation = 'up'

    with pytest.raises(ValidationError):
        legend_config.width = 200

    with pytest.raises(ValidationError):
        legend_config.height == 500

    with pytest.raises(ValidationError):
        legend_config.position = (0, 5, 4)

    with pytest.raises(ValidationError):
        legend_config.color_count = 25

    with pytest.raises(ValidationError):
        legend_config.label_count = 26

    with pytest.raises(ValidationError):
        legend_config.decimal_count = 2

    with pytest.raises(ValidationError):
        legend_config.preceding_labels = 'no'

    with pytest.raises(ValidationError):
        legend_config.label_parameters = {'color': [0, 0, 0]}

    with pytest.raises(ValidationError):
        legend_config.title_parameters = {'color': [0, 0, 0]}