#!/usr/bin/env python import unittest from geopy import format, Location, Point from geopy.parsers.html import GeoMicroformat class GeoMicroformatFound(object): def setUp(self): self.parser = GeoMicroformat() def test_one_str(self): locations = self.parser.find_all(self.MARKUP) self.failUnless(len(locations) == 1) self._location_test(locations[0]) def test_multi_str(self): locations = self.parser.find_all(self.MARKUP * 3) self.failUnless(len(locations) == 3) for i in range(3): self._location_test(locations[i]) def test_one_soup(self): from BeautifulSoup import BeautifulSoup locations = self.parser.find_all(BeautifulSoup(self.MARKUP)) self.failUnless(len(locations) == 1) self._location_test(locations[0]) def test_multi_soup(self): from BeautifulSoup import BeautifulSoup locations = self.parser.find_all(BeautifulSoup(self.MARKUP * 3)) self.failUnless(len(locations) == 3) for i in range(3): self._location_test(locations[i]) def _location_test(self, location): self.failUnless(location.name == self.NAME) self.failUnless(location.point == self.POINT) class GeoMicroformatNotFound(object): def setUp(self): self.parser = GeoMicroformat() def test_none_str(self): locations = self.parser.find_all(self.MARKUP) self.failUnless(len(locations) == 0) def test_none_soup(self): from BeautifulSoup import BeautifulSoup locations = self.parser.find_all(BeautifulSoup(self.MARKUP)) self.failUnless(len(locations) == 0) class GeoMicroformatFoundTest(GeoMicroformatFound, unittest.TestCase): MARKUP = """ 41.4924; -81.7239 """ NAME = "41.4924; -81.7239" POINT = Point(41.4924, -81.7239) class GeoMicroformatNotFoundTest(GeoMicroformatNotFound, unittest.TestCase): MARKUP = """ 41.4924; -81.7239 """ class FindAbbrLatLongTest(GeoMicroformatFoundTest): MARKUP = """ N 41.5, W 81.7 """ NAME = "N 41.5, W 81.7" class FindAbbrShorthandTest(GeoMicroformatFoundTest): MARKUP = """ N 41.5, W 81.7 """ NAME = "N 41.5, W 81.7" class NoShorthandNotFoundTest(GeoMicroformatNotFoundTest): def setUp(self): self.parser = GeoMicroformat(shorthand=False) MARKUP = """41.4924;-81.7239""" class NoShorthandFoundTest(GeoMicroformatFoundTest): def setUp(self): self.parser = GeoMicroformat(shorthand=False) MARKUP = """ 41.4924;-81.7239 41.4924; -81.7239 N 41.5, W 81.7 """ class FindNestedDefListTest(GeoMicroformatFoundTest): MARKUP = """