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')))
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