Пример #1
0
    def testExtractImplicitStyles(self):
        """Tests that Extract extracts implicit lines and polygons."""
        kml = """<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
      <Document>
        <name>test</name>
        <Placemark>%s</Placemark>
      </Document>
    </kml>"""

        # No implied styles in empty Placemark
        self.assertEquals(([], [], [], set(), set()),
                          legend_item_extractor.Extract(kml % ''))

        # Implied polygon
        self.assertEquals(
            ([], [], [legend_item_extractor.ToPolygonStyleDict()], set(),
             set(
                 self.CssColors([
                     legend_item_extractor.LINE_DEFAULT_KML_COLOR,
                     legend_item_extractor.POLYGON_DEFAULT_KML_COLOR
                 ]))),
            legend_item_extractor.Extract(kml % '<Polygon></Polygon>'))

        # Implied lines
        line_tuple = ([], [legend_item_extractor.ToLineStyleDict()], [], set(),
                      set(
                          self.CssColors(
                              [legend_item_extractor.LINE_DEFAULT_KML_COLOR])))
        self.assertEquals(
            line_tuple,
            legend_item_extractor.Extract(kml % '<LineString></LineString>'))
        self.assertEquals(
            line_tuple,
            legend_item_extractor.Extract(kml % '<LinearRing></LinearRing>'))
Пример #2
0
 def testExtractLastPolygonStyle(self):
     """Tests that Extract only extracts the last of multiple PolyStyles."""
     kml_colors = ['FF123456', '12ABCDEF']
     polystyle = (
         '<PolyStyle><color>%s</color><width>3</width></PolyStyle>' %
         kml_colors[0])
     linestyle = (
         '<LineStyle><color>%s</color><width>4</width></LineStyle>' %
         kml_colors[1])
     kml = """<?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://earth.google.com/kml/2.2">
   <Document>
     <name>test</name>
     <Style>
       <LineStyle>Overridden</LineStyle>
       <PolyStyle>Overridden</PolyStyle>
       %s
       %s
     </Style>
   </Document>
 </kml>""" % (polystyle, linestyle)
     self.assertEquals(
         ([], [], [self.CreatePolygonFromString(polystyle, linestyle)
                   ], set(), set(self.CssColors(kml_colors))),
         legend_item_extractor.Extract(kml))
Пример #3
0
 def testExtractNoDuplicates(self):
     """Tests that Extract does not extract duplicates of items."""
     icon_href = 'icon_href'
     iconstyle = ('<IconStyle><Icon><href>%s</href></Icon></IconStyle>' %
                  icon_href)
     linestyle = '<LineStyle></LineStyle>'
     polystyle = '<PolyStyle></PolyStyle>'
     kml = """<?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://earth.google.com/kml/2.2">
   <Document>
     <name>test</name>
     <Style>%s</Style>
     <Style>%s</Style>
     <Style>%s</Style>
     <Style>%s</Style>
     <Style>%s</Style>
     <Style>%s</Style>
   </Document>
 </kml>""" % (iconstyle, iconstyle, linestyle, linestyle, polystyle,
              polystyle)
     self.assertEquals(
         ([self.CreateIconFromString(iconstyle)], [
             legend_item_extractor.ToLineStyleDict()
         ], [legend_item_extractor.ToPolygonStyleDict()], set([icon_href]),
          set(
              self.CssColors([
                  legend_item_extractor.LINE_DEFAULT_KML_COLOR,
                  legend_item_extractor.POLYGON_DEFAULT_KML_COLOR,
              ]))), legend_item_extractor.Extract(kml))
Пример #4
0
    def testExtract(self):
        """Tests legend_item_extractor's Extract method."""
        static_icons = ['icon_href']
        kml_colors = [
            'FF123456', '12ABCDEF', 'FF654321',
            legend_item_extractor.LINE_DEFAULT_KML_COLOR
        ]
        href_icon = ('<IconStyle><Icon><href>%s</href></Icon></IconStyle>' %
                     static_icons[0])
        colored_icon = """<IconStyle>
                     <Icon><href>colored_icon_href</href></Icon>
                     <color>%s</color>
                   </IconStyle>""" % kml_colors[0]
        no_href = '<IconStyle><color>%s</color></IconStyle>' % kml_colors[1]
        linestyle = '<LineStyle><color>%s</color></LineStyle>' % kml_colors[2]
        polystyle = '<PolyStyle><color>%s</color></PolyStyle>' % kml_colors[2]
        color_style = '<color>Ignored</color>'
        kml = """<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
      <Document>
        <name>test</name>
        <Style>%s</Style>
        <Style>%s</Style>
        <Style>%s</Style>
        <Style>%s</Style>
        <Style>%s</Style>
        <Style>%s</Style>
        <Style>%s</Style>
      </Document>
    </kml>""" % (href_icon, colored_icon, no_href, linestyle, polystyle,
                 linestyle + polystyle, color_style)

        self.assertEquals(
            # Icons
            # pylint: disable=g-long-lambda
            (
                mox.SameElementsAs(
                    map(self.CreateIconFromString,
                        [no_href, colored_icon, href_icon])),
                # Lines
                [self.CreateLineFromString(linestyle)],
                # Polygons
                mox.SameElementsAs([
                    self.CreatePolygonFromString(polystyle),
                    self.CreatePolygonFromString(polystyle, linestyle)
                ]),
                # Static icons; Colors
                set(static_icons),
                set(self.CssColors(kml_colors))),
            legend_item_extractor.Extract(kml))
Пример #5
0
    def testExtractLastIconStyle(self):
        """Tests that Extract only extracts the last of multiple IconStyles."""
        icon_href = 'icon_href'
        iconstyle = ('<IconStyle><Icon><href>%s</href></Icon></IconStyle>' %
                     icon_href)
        kml = """<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
      <Document>
        <name>test</name>
        <Style>
          <IconStyle>
            <Icon><href>Overridden</href></Icon>
            <color>Ignored</color>
          </IconStyle>
          %s
        </Style>
      </Document>
    </kml>""" % iconstyle

        self.assertEquals(([self.CreateIconFromString(iconstyle)
                            ], [], [], set([icon_href]), set()),
                          legend_item_extractor.Extract(kml))
Пример #6
0
    def testGetLegendItems(self):
        """Tests the GetLegendItems handler."""
        url = 'http://www.maps.com:123/?map=321'
        kml = 'the kml'
        items = ['icons'], ['lines'], ['polygons'], ['static icons'
                                                     ], ['colors']

        self.mox.StubOutWithMock(GetLegendItems, 'GetKmlFromUrl')
        GetLegendItems.GetKmlFromUrl(url).AndReturn(kml)
        self.mox.StubOutWithMock(legend_item_extractor, 'Extract')
        legend_item_extractor.Extract(kml).AndReturn(items)

        self.mox.ReplayAll()
        response = self.DoGet('/.legend?url=' + urllib.quote(url))
        self.assertEquals(
            {
                'icon_styles': items[0],
                'line_styles': items[1],
                'polygon_styles': items[2],
                'static_icon_urls': list(items[3]),
                'colors': list(items[4])
            }, json.loads(response.body))
        self.mox.VerifyAll()
Пример #7
0
    def testExtractLastLineStyle(self):
        """Tests that Extract only extracts the last of multiple LineStyles."""
        kml_color = 'FF123456'
        linestyle = (
            '<LineStyle><color>%s</color><width>3</width></LineStyle>' %
            kml_color)
        kml = """<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
      <Document>
        <name>test</name>
        <Style>
          <LineStyle>
            Overridden
            <color>Ignored</color>
          </LineStyle>
          %s
        </Style>
      </Document>
    </kml>""" % linestyle

        self.assertEquals(
            ([], [self.CreateLineFromString(linestyle)
                  ], [], set(), set(self.CssColors([kml_color]))),
            legend_item_extractor.Extract(kml))
Пример #8
0
    def testExtractSeparatedPolyAndLineStyles(self):
        """Tests that Extract combines separated PolyStyle and LineStyle styles."""
        kml_colors = [
            'AA123456', 'BB234567', 'CC345678', 'DD456789',
            legend_item_extractor.LINE_DEFAULT_KML_COLOR
        ]
        polystyle = '<PolyStyle><color>%s</color><width>%d</width></PolyStyle>'
        linestyle = '<LineStyle><color>%s</color><width>%d</width></LineStyle>'
        polystyles = [
            polystyle % (kml_colors[0], 3), polystyle % (kml_colors[1], 4)
        ]
        linestyles = [
            linestyle % (kml_colors[2], 5), linestyle % (kml_colors[3], 6)
        ]
        kml = """<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://earth.google.com/kml/2.2">
      <Document>
        <name>test</name>
        <Placemark>
          Separated PolyStyle and LineStyle should be composed into one polygon
          item. Should not exist as separate line and polygon items.
          Should be able to dig into normal StyleMap Styles.
          <Style>%s</Style>
          <StyleMap>
            <Pair>
              <key>normal</key>
              <Style>%s</Style>
            </Pair>
            <Pair>
              <key>highlight</key>
              <Style><PolyStyle>Should be ignored</PolyStyle></Style>
            </Pair>
          </StyleMap>
        </Placemark>
        <Placemark>
          <StyleMap>
            <Pair>
              <key>normal</key>
              <styleUrl>#a</styleUrl>
            </Pair>
            <Pair>
              Should be ignored
              <key>highlight</key>
              <styleUrl>#b</styleUrl>
            </Pair>
          </StyleMap>
          <styleUrl>#b</styleUrl>
        </Placemark>
        <Style id="a">%s</Style>
        <Style id="b">%s</Style>
      </Document>
    </kml>""" % (polystyles[0], linestyles[0], polystyles[1], linestyles[1])

        self.assertEquals(
            # Line from shared style
            (
                [],
                [self.CreateLineFromString(linestyles[1])],
                # Polygons
                mox.SameElementsAs([
                    self.CreatePolygonFromString(polystyles[0], linestyles[0]),
                    self.CreatePolygonFromString(polystyles[1], linestyles[1]),
                    self.CreatePolygonFromString(polystyles[1])
                ]),
                # Icons and colors
                set(),
                set(self.CssColors(kml_colors))),
            legend_item_extractor.Extract(kml))