Exemplo n.º 1
0
def test_default_opacity_is_applied_correctly(render):
    # If opacity is not provided it should default to 1.0

    name = 'Some_Name'
    sld.get_multiband_raster_sld(name)
    opacity = render.call_args[1]['opacity']

    assert opacity == 1.0
Exemplo n.º 2
0
def test_band_numbers_must_be_three():
    # Given number of bands must be equal to 3

    name = 'Some_Name'
    bands = [4, 5, 6, 9, 12]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, bands=bands)
Exemplo n.º 3
0
def test_title_exists_in_template_params(render):
    # if title not passed in template_params
    # should have a title attr

    name = 'Some_Name'
    sld.get_multiband_raster_sld(name)

    assert 'title' in render.call_args[1]
Exemplo n.º 4
0
def test_default_title(render):
    # If title is None template_params['title']
    # should still be a string

    name = 'Some_Name'
    sld.get_multiband_raster_sld(name)

    assert type(render.call_args[1]['title']) == str
Exemplo n.º 5
0
def test_assigned_name_is_passed_correctly(render):
    # If name is given template_params['name'] should
    # be the same as the given name

    name = 'Super Fancy Name'
    sld.get_multiband_raster_sld(name)

    assert render.call_args[1]['name'] == name
Exemplo n.º 6
0
def test_title_is_passed_correctly(render):
    # If title is passed in template_params['title']
    # should equal that string

    name = 'Some_Name'
    title = 'Tiff_Title'
    sld.get_multiband_raster_sld(name, title=title)

    assert render.call_args[1]['title'] == title
Exemplo n.º 7
0
def test_opacity_is_a_number():
    # If opacity is not a number, should
    # throw an exception

    name = 'Some_Name'
    opacity = 'opacity'

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, opacity=opacity)
Exemplo n.º 8
0
def test_default_gamma_is_applied_to_all_bands(render):
    # If gamma is not passed in and bands=(1,2,3)
    # template_params['gamma'] should equal [(1.0), (1.0), (1.0)]

    name = 'Some_Name'
    sld.get_multiband_raster_sld(name)
    gamma = [i['options']['gamma'] for i in render.call_args[1]['channels']]

    assert gamma == [(1.0), (1.0), (1.0)]
Exemplo n.º 9
0
def test_number_of_gamma_is_equal_to_number_of_bands():
    # If gamma is passed in as list [0.1, 0.2] and bands (1,2,3)
    # should throw an exception

    name = 'Some_Name'
    gamma = [0.1, 0.2]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, gamma=gamma)
Exemplo n.º 10
0
def test_band_is_a_list_or_tuple():
    # If bands is not a list/tuple should
    # throw an exception

    name = 'Some_Name'
    bands = 'Wrong Band Type'

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, bands=bands)
Exemplo n.º 11
0
def test_number_of_intervals_is_equal_to_number_of_bands():
    # If interval is passed in as a list [(0,1),(0,1)] and
    # bands (1,2,3) should throw an exception """

    name = 'Some_Name'
    interval = [(0, 1), (1, 2)]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, interval=interval)
Exemplo n.º 12
0
def test_band_values_are_greater_than_zero():
    # If any value of bands is less than 1
    # should throw an exception

    name = 'Some_Name'
    bands = [1, 2, -1]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, bands=bands)
Exemplo n.º 13
0
def test_band_values_are_integers():
    # If any value of bands is not an
    # integer, should throw an exception

    name = 'Some_Name'
    bands = [1, 1.3, 2.0]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, bands=bands)
Exemplo n.º 14
0
def test_gamma_is_a_number():
    # If gamma is not passed as a number thrown an
    # exception

    name = 'Some_Name'
    # Give a string with length of 3
    expected_gamma = 'Gam'

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, gamma=expected_gamma)
Exemplo n.º 15
0
def test_given_band_values_are_set_correctly(render):
    # Given band order must match with channel's band properties

    name = 'Some_Name'
    bands = [9, 5, 2]
    sld.get_multiband_raster_sld(name,
                                 bands=bands)
    out_bands = [i['band'] for i in render.call_args[1]['channels']]

    assert bands == out_bands
Exemplo n.º 16
0
def test_opacity_is_applied_correctly(render):
    # If opacity is provided as 0.7 it should be equal to 0.7

    name = 'Some_Name'
    opacity = 0.7
    sld.get_multiband_raster_sld(name,
                                 opacity=opacity)
    opacity_out = render.call_args[1]['opacity']

    assert opacity_out == opacity
Exemplo n.º 17
0
def test_default_single_interval_is_applied_to_all_bands(render):
    # If interval is not passed in and bands=(1,2,3)
    # template_params['interval'] should equal [(0,1), (0,1), (0,1)]

    name = 'Some_Name'
    sld.get_multiband_raster_sld(name)
    intervals = [(i['options']['minValue'], i['options']['maxValue'])
                 for i in render.call_args[1]['channels']]

    assert intervals == [(0, 1), (0, 1), (0, 1)]
Exemplo n.º 18
0
def test_number_of_bands_are_correct(render):
    # If 3 bands are passed there must be 3 channels

    name = 'Some_Name'
    bands = (1, 2, 3)
    sld.get_multiband_raster_sld(name,
                                 bands=bands)
    num_of_bands = render.call_args[1]['channels']

    assert len(num_of_bands) == 3
Exemplo n.º 19
0
def test_given_gamma_is_applied_to_all_bands(render):
    # If gamma is given 1.5 in and bands=(1,2,3)
    # template_params['gamma'] should equal [(1.5), (1.5), (1.5)]

    name = 'Some_Name'
    gamma = 1.5
    sld.get_multiband_raster_sld(name,
                                 gamma=gamma)
    gamma = [i['options']['gamma'] for i in render.call_args[1]['channels']]

    assert gamma == [(1.5), (1.5), (1.5)]
Exemplo n.º 20
0
def test_given_multi_gamma_is_applied_correctly(render):
    # If gamma is given as list [1.0, 1.5, 2.0]
    # template_params['gamma'] should be equal to [1.0, 1.5, 2.0]

    name = 'Some_Name'
    gammas = [1.0, 1.5, 2.0]
    sld.get_multiband_raster_sld(name,
                                 gamma=gammas)
    gammas_out = [i['options']['gamma']
                  for i in render.call_args[1]['channels']]

    assert gammas_out == gammas
Exemplo n.º 21
0
def test_given_single_interval_is_applied_to_all_bands(render):
    # If interval is passed in as tuple (10, 20) and bands=(1,2,3)
    # template_params['interval'] should equal [(10,20), (10,20), (10,20)]

    name = 'Some_Name'
    interval = (10, 20)
    sld.get_multiband_raster_sld(name,
                                 interval=interval)
    intervals = [(i['options']['minValue'], i['options']['maxValue'])
                 for i in render.call_args[1]['channels']]

    assert intervals == [(10, 20), (10, 20), (10, 20)]
Exemplo n.º 22
0
def test_opacity_is_between_0_and_1():
    # Opacity must be between 0 and 1

    name = 'Some_Name'
    opacity_1 = 1.5
    opacity_2 = -0.5

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, opacity=opacity_1)

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, opacity=opacity_2)
Exemplo n.º 23
0
def test_intervals_must_have_two_values():
    # If intervals has more or less then two
    # elements, should throw an exception

    name = 'Some_Name'
    intervals_1 = (0, 1, 2)
    intervals_2 = [(0, 1, 2), (0, 3, 4), (0)]

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, interval=intervals_1)

    with pytest.raises(AssertionError):
        sld.get_multiband_raster_sld(name, interval=intervals_2)
Exemplo n.º 24
0
def test_given_multi_interval_is_applied_correctly(render):
    # If interval is passed in as a list of tuples
    # [(10,20), (40,50), (90,100)] and bands=(1,2,3)
    # template_params['interval'] should equal
    # to [(10,20), (40,50), (90,100)]

    name = 'Some_Name'
    intervals = [(10, 20), (40, 50), (90, 100)]
    sld.get_multiband_raster_sld(name,
                                 interval=intervals)
    out_intervals = [(i['options']['minValue'], i['options']['maxValue'])
                     for i in render.call_args[1]['channels']]

    assert intervals == out_intervals
Exemplo n.º 25
0
def test_given_band_values_are_set_correctly_xml():
    # Band Values should be set correctly

    name = 'Some_Name'
    expected_bands = [4, 3, 9]
    multiband_xml = sld.get_multiband_raster_sld(name,
                                                 bands=expected_bands)
    namespace = "{http://www.opengis.net/sld}"
    xml_bands = []
    root = ET.fromstring(multiband_xml.strip())
    for elem in root.iter("{}{}".format(namespace, 'SourceChannelName')):
        xml_bands.append(int(float(elem.text)))

    assert expected_bands == xml_bands