예제 #1
0
def test_channels_exists_in_template_params_single(render):
    # Template params should have a channels attribute

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert 'channels' in render.call_args[1]
예제 #2
0
def test_opacity_exists_in_template_params(render):
    # Template params should have a opacity attribute

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert 'opacity' in render.call_args[1]
예제 #3
0
def test_colormap_is_a_collection_of_dictionaries():
    # If colormap values are not all dicts should throw an exception

    name = 'Some_Name'
    band = 1
    colormap = ["foo", "bar"]

    with pytest.raises(AssertionError):
        sld.get_single_band_raster_sld(name, band, colormap=colormap)
예제 #4
0
def test_colormap_is_a_list_or_tuple():
    # If colormap is not a list/tuple should throw an exception

    name = 'Some_Name'
    band = 1
    colormap = "Not a List or Tuple"

    with pytest.raises(AssertionError):
        sld.get_single_band_raster_sld(name, band, colormap=colormap)
예제 #5
0
def test_colormap_does_not_exist_in_template_params_by_default(render):
    # if colormap is None there should be no 'colormap'
    # attribute in template_params """

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert 'colormap' not in render.call_args[1]
예제 #6
0
def test_deafault_title(render):
    # If title is None template_params['title']
    # should still be a string

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert type(render.call_args[1]['title']) == str
예제 #7
0
def test_colormap_type_does_not_exist_in_template_params_by_default(render):
    # If no colormap_type is passed in no colormap_type
    # attr should be in template_params

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert 'colormap_type' not in render.call_args[1]
예제 #8
0
def test_default_channel_name_is_passed_correctly(render):
    # if no custom channel_name template_params['channels'][0]['name']
    # should be equal to GrayChannel

    name = 'Super Fancy Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert render.call_args[1]['channels'][0]['name'] == 'GrayChannel'
예제 #9
0
def test_given_band_value_is_set_correctly(render):
    # Given band must match with channel's band property

    name = 'Some_Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)
    out_band = render.call_args[1]['channels'][0]['band']

    assert band == out_band
예제 #10
0
def test_band_is_greater_than_zero():
    # If band is less than 1
    # should throw an exception

    name = 'Some_Name'
    band = 0

    with pytest.raises(AssertionError):
        sld.get_single_band_raster_sld(name, band=band)
예제 #11
0
def test_assigned_name_is_passed_correctly_single(render):
    # If name is given template_params['name'] should
    # be the same as the given name """

    name = 'Super Fancy Name'
    band = 1
    sld.get_single_band_raster_sld(name, band)

    assert render.call_args[1]['name'] == name
예제 #12
0
def test_assigned_channel_name_is_passed_correctly(render):
    # If custom channel_name template_params['channels'][0]['name']
    # should be equal to custom channel_name

    name = 'Super Fancy Name'
    band = 1
    channel_name = "Super Channel Name"
    sld.get_single_band_raster_sld(name, band,
                                   channel_name=channel_name)

    assert render.call_args[1]['channels'][0]['name'] == channel_name
예제 #13
0
def test_each_colormap_element_has_quantity():
    # If colormap values do not all contain 'quantity'
    # attribute should thrown an exception

    name = 'Some_Name'
    band = 1
    colormap = [{'foo': 'bar'},
                {'bar': 'foo'}]

    with pytest.raises(AssertionError):
        sld.get_single_band_raster_sld(name, band, colormap=colormap)
예제 #14
0
def test_colormap_type_assigned_correctly(render):
    # If custom colormap_type is passed in
    # template_params['colormap_type'] should be
    # equal to custom colormap_type

    name = 'Some_Name'
    band = 1
    colormap = [{"color": "#000000", "quantity": "0"},
                {"color": "#0000FF", "quantity": "1"}]
    colormap_type = "Different ramp"
    sld.get_single_band_raster_sld(name, band,
                                   colormap=colormap,
                                   colormap_type=colormap_type)

    assert colormap_type == render.call_args[1]['colormap_type']
예제 #15
0
def test_given_band_value_is_set_correctly_xml():
    # Band Value should be set correctly

    name = 'Some_Name'
    expected_band = 2
    singleband_xml = sld.get_single_band_raster_sld(name,
                                                    band=expected_band)
    namespace = "{http://www.opengis.net/sld}"
    root = ET.fromstring(singleband_xml.strip())
    for elem in root.iter("{}{}".format(namespace, 'SourceChannelName')):
        assert int(float(elem.text)) == expected_band
예제 #16
0
def test_by_default_dont_have_colormap():
    # Call with no colormap should produce no ColorMap XML

    name = 'Some_Name'
    band = 2
    singleband_xml = sld.get_single_band_raster_sld(name, band)
    root = ET.fromstring(singleband_xml.strip())
    for elem in root.iter():
        if 'ColorMap' in elem.tag:
            colormap = elem
        else:
            colormap = False

    assert not colormap
예제 #17
0
def test_number_of_color_entries_matches_xml():
    # Call with 4 colormap dicts should produce 4 ColorMap entries

    name = 'Some_Name'
    band = 2
    colormap = [
        {"color": "#000000", "quantity": "100"},
        {"color": "#0000FF", "quantity": "110"},
        {"color": "#00FF00", "quantity": "135"},
        {"color": "#FF00FF", "quantity": "185"}]

    singleband_xml = sld.get_single_band_raster_sld(name, band,
                                                    colormap=colormap)
    root = ET.fromstring(singleband_xml.strip())
    entries = []
    for elem in root.iter():
        if 'ColorMapEntry' in elem.tag:
            entries.append(elem)

    assert len(colormap) == len(entries)
예제 #18
0
def test_passed_colormap_exists_in_xml():
    # Call with colormap should produce ColorMap section

    name = 'Some_Name'
    band = 2
    colormap = [
        {"color": "#000000", "quantity": "100"},
        {"color": "#0000FF", "quantity": "110"},
        {"color": "#00FF00", "quantity": "135"},
        {"color": "#FF0000", "quantity": "160"},
        {"color": "#FF00FF", "quantity": "185"}]

    singleband_xml = sld.get_single_band_raster_sld(name, band,
                                                    colormap=colormap)
    root = ET.fromstring(singleband_xml.strip())
    for elem in root.iter():
        if 'ColorMap' in elem.tag:
            colormap = True
        else:
            colormap = False

    assert colormap
예제 #19
0
def test_xml_items_have_quantity_and_color_attributes():
    # Call with colormap dicts that have 'color' and 'quantity'
    # should produce ColorMapEntry XML with 'color' and 'quantity' attributes

    name = 'Some_Name'
    band = 2
    colormap = [
        {"color": "#000000", "quantity": "100"},
        {"color": "#0000FF", "quantity": "110"},
        {"color": "#00FF00", "quantity": "135"},
        {"color": "#FF00FF", "quantity": "185"}]

    singleband_xml = sld.get_single_band_raster_sld(name, band,
                                                    colormap=colormap)
    root = ET.fromstring(singleband_xml.strip())

    for elem in root.iter():
        if 'ColorMapEntry' in elem.tag:
            if 'color' in elem.attrib and 'quantity' in elem.attrib:
                attrib = True
            else:
                attrib = False
            assert attrib