Exemplo n.º 1
0
    def test_Markup(self):

        markup = Markup()
        self.assertIs(markup, Markup)
        markup = Markup(title='NewYorkCity', filename=self.tmpfile.name)
        self.assertIs(markup, Markup)

        # add_spot
        self.assertRaises(ValueError, lambda: markup.add_spot(
            Search('New York City')))
        # generate_kml
        markup.add_spot(Spot.from_search(
            Search('New York City')))
        markup.generate_kml()  # latitude, longitude, elevation
        markup.add_spot(
            Spot.from_search(Search('New York City', language='en')))
        markup.generate_kml()  # latitude, longitude
        # save_kml_file
        markup.save_kml_file()

        # title
        self.assertIs(markup.title, str)
        self.failUnlessRaises(
            AttributeError, setattr, markup, "title", "set not allowed")
        # spots
        self.assertIs(markup.spots, list)
        self.failUnlessRaises(
            AttributeError, setattr, markup, "spots", "set not allowed")
        # filename
        self.assertIs(markup.filename, str)
        markup.filename = 'filename'
        self.assertStrEqual(markup.filename, 'filename')
Exemplo n.º 2
0
    def test_Spot(self):

        spot = Spot()
        self.assertIs(spot, Spot)
        spot = Spot(
            title='New York', latitude=-74.0058333333,
            longitude=40.7127777778, elevation=10.0,
            url='https://de.wikipedia.org/wiki/New_York_City')
        self.assertIs(spot, Spot)

        # url
        self.assertIs(spot.url, str)
        self.failUnlessRaises(
            AttributeError, setattr, spot, "url", "set not allowed")
        # title
        self.assertIs(spot.title, str)
        self.failUnlessRaises(
            AttributeError, setattr, spot, "title", "set not allowed")
        # latitude
        self.assertIs(spot.latitude, float)
        self.failUnlessRaises(
            AttributeError, setattr, spot, "latitude", "set not allowed")
        # longitude
        self.assertIs(spot.longitude, float)
        self.failUnlessRaises(
            AttributeError, setattr, spot, "longitude", "set not allowed")
        # elevation
        self.assertIs(spot.elevation, float)
        self.failUnlessRaises(
            AttributeError, setattr, spot, "elevation", "set not allowed")

        # search
        spot = Spot.from_search(Search('New York City'))
        self.assertIs(spot, Spot)
        self.assertRaises(
            ValueError, lambda: Spot.from_search(
                Scrape('https://de.wikipedia.org/wiki/New_York_City')))
        # scrape
        spot = Spot.from_scrape(
            Scrape('https://de.wikipedia.org/wiki/New_York_City'))
        self.assertIs(spot, Spot)
        self.assertRaises(
            ValueError, lambda: Spot.from_scrape(Search('New York City')))
Exemplo n.º 3
0
def get_spots(wikiobj, language):
    wiki_url_pattern = re.compile(
        r'^https://(de|en|fr).wikipedia.org/wiki/.+'
    )
    spots = []
    for obj in wikiobj:
        if wiki_url_pattern.match(obj):
            # scrape url
            spot = Spot.from_scrape(Scrape(obj))
        else:
            # search term
            try:
                spot = Spot.from_search(Search(obj, language=language))
            except IndexError:
                raise UserWarning("'%s' no search results" % obj)
        spots.append(spot)
    return spots
Exemplo n.º 4
0
    def test_Map(self):

        map = Map()
        self.assertIs(map, Map)
        map = Map(filename=self.tmpfile.name)
        self.assertIs(map, Map)

        # add_marker
        self.assertRaises(ValueError, lambda: map.add_marker(Search(
            'New York City')))
        map.add_marker(Spot.from_search(Search('New York City')))
        map.save_map_file()

        # spots
        self.assertIs(map.spots, list)
        self.failUnlessRaises(
            AttributeError, setattr, map, "spots", "set not allowed")
        # filename
        self.assertIs(map.filename, str)
        map.filename = 'filename'
        self.assertStrEqual(map.filename, 'filename')