class ArcGISTestCases(unittest.TestCase): def setUp(self): self.address = "Sunnersta" #static address to be found self.userlocation = (59.8585107, 17.6368508) self.addrNone = "abcdefghijklmnopqrstuvwxyz zyxwvutsrqponmlkjihgfedcba" #non-existing address self.scheme = "https" self.plainscheme = "http" self.geolocators = [] #set up for ArcGIS self.geolocator2auth = ArcGIS("asailona", "uppsala00", "asailona.maps.arcgis.com") self.geolocator2 = ArcGIS() self.arcgisurl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find" self.arcgisurlmulti = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates" self.arcgisgenerate = "https://www.arcgis.com/sharing/generateToken?username=asailona&password=uppsala00&expiration=3600&f=json&referer=asailona.maps.arcgis.com" self.geolocators.append(self.geolocator2auth) self.geolocators.append(self.geolocator2) def testArcGIS(self): #assert if the object's structure is the same as class ArcGIS self.assertIsInstance(self.geolocator2, ArcGIS, "The object is not an instance of class ArcGIS") #assert the url built self.assertEqual(self.geolocator2.scheme, self.scheme) self.assertEqual(self.geolocator2.api, self.arcgisurl) self.assertEqual(self.geolocator2.api_multi, self.arcgisurlmulti) #assert if the authenticated mode is used var = self.geolocator2auth._refresh_authentication_token() var2 = self.geolocator2auth._base_call_geocoder(self.arcgisgenerate) self.geolocator2auth.token = var2['token'] self.assertIsNotNone(self.geolocator2auth.token, "The token is None") def testDataTypeNone(self): for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' #without userlocation location = self.geolocators[gl].geocode(self.addrNone) self.assertIsNone( location, "location found! " + web_serv + " " + str(self.geolocators[gl])) #with userlocation location = self.geolocators[gl].geocode(self.addrNone, self.userlocation) self.assertIsNone( location, "location found! " + web_serv + " " + str(self.geolocators[gl])) def testDataTypeSingle(self): for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' location = self.geolocators[gl].geocode(self.address) self.assertIsNotNone(location, "location not found! " + web_serv) self.assertIsInstance( location, Location, "location is not an instance of class Location! " + web_serv) self.assertIsNot(type(location), list, "location is multiple! " + web_serv) self.assertIs(type(location), Location, "location is not of type Location! " + web_serv) self.assertIs( type(location.address), unicode, "address is not of type unicode! " + web_serv + " " + str(self.geolocators[gl])) self.assertIs(type(location.latitude), float, "latitude is not of type float! " + web_serv) self.assertIs(type(location.longitude), float, "longitude is not of type float! " + web_serv) self.assertIs(type(location.altitude), float, "altitude is not of type float! " + web_serv) self.assertIs(type(location.raw), dict, "raw is not of type dict! " + web_serv) def testDataTypeMultiple(self): #before changes, the web service always return 1 address. Making the request without userlocation will result in single result for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' location = self.geolocators[gl].geocode(self.address, self.userlocation, False) self.assertIsNotNone(location, "location not found! " + web_serv) self.assertIs(type(location), list, "location is single! " + web_serv) for l in range(len(location)): self.assertIsInstance( location[l], Location, "location is not an instance of class Location! " + web_serv) self.assertIs(type(location[l]), Location, "location is not of type Location! " + web_serv) self.assertIs( type(location[l].address), unicode, "address is not of type unicode! " + web_serv + " " + str(self.geolocators[gl])) self.assertIs(type(location[l].latitude), float, "latitude is not of type float! " + web_serv) self.assertIs(type(location[l].longitude), float, "longitude is not of type float! " + web_serv) self.assertIs(type(location[l].altitude), float, "altitude is not of type float! " + web_serv) self.assertIs(type(location[l].raw), dict, "raw is not of type dict! " + web_serv) def testAddressBeforeChanges(self): #before changes, the web service always return 1 address. Making the testAddressMultiple invalid for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' #request for single location = self.geolocators[gl].geocode(self.address) self.assertIn( self.address, location.raw['name'], "address is not the same for " + web_serv + "," + self.address + " != " + location.raw['name']) #request for multiple location = self.geolocators[gl].geocode(self.address, exactly_one=False) for gl1 in range(len(location)): self.assertIn( self.address, location[gl1].raw['name'], "address is not the same for " + web_serv + "," + self.address + " != " + location[gl1].raw['name']) def testAddressSingleChanges(self): for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' location = self.geolocators[gl].geocode( self.address, exactly_one=True, userlocation=self.userlocation) self.assertIn(self.address, location.raw['address'], "address not found " + web_serv) def testAddressMultipleChanges(self): for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' location = self.geolocators[gl].geocode( self.address, exactly_one=False, userlocation=self.userlocation) for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['address'], "address not found " + web_serv) def testOrderedData(self): for gl in range(len(self.geolocators)): time.sleep(2) #flag for differentiate between authenticated and unauthenticated request web_serv = 'not_auth' if gl == 0: web_serv = 'auth' location = self.geolocators[gl].geocode( self.address, exactly_one=False, userlocation=self.userlocation) #put all distance in array distance = [] for l in range(len(location)): distance.append( vincenty(self.userlocation, (location[l].latitude, location[l].longitude))) #compare all distance with the first distance, the first one should be the smallest min_distance = distance[0] for l in range(len(distance)): self.assertLessEqual(min_distance, distance[l], "The order of data is wrong " + web_serv) def testLenData(self): for gl in range(len(self.geolocators)): time.sleep(2) location = self.geolocators[gl].geocode( self.address, userlocation=self.userlocation, exactly_one=False) print len(location) print len(self.geolocators[gl].geocoded) self.assertEqual(len(self.geolocators[gl].geocoded), len(location), "The length is not the same")
class GeopyTestCases(unittest.TestCase): def setUp(self): self.address = "Sunnersta" #static address to be found self.address2 = "Mackenzie" #static address for DataBC only self.userlocation = (59.8585107, 17.6368508) self.addrNone = "abcdefghijklmnopqrstuvwxyz zyxwvutsrqponmlkjihgfedcba" #non-existing address self.scheme = "https" self.plainscheme = "http" self.geolocators = [] #set up for Google self.geolocator1 = GoogleV3() self.googleurl = "https://maps.googleapis.com/maps/api/geocode/json" self.googledomain = "maps.googleapis.com" self.geolocators.append(self.geolocator1) #set up for ArcGIS self.geolocator2auth = ArcGIS("asailona", "uppsala00", "asailona.maps.arcgis.com") self.geolocator2 = ArcGIS() self.arcgisurl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find" self.arcgisgenerate = "https://www.arcgis.com/sharing/generateToken?username=asailona&password=uppsala00&expiration=3600&f=json&referer=asailona.maps.arcgis.com" self.geolocators.append(self.geolocator2auth) self.geolocators.append(self.geolocator2) #set up for Bing self.geolocator3auth = Bing( "AjIo4Ums4724tF5U5V7t91SHwwvjm8GP8wf0b3HZmVJWVQLlGJtSwv04IlwJ6971") self.bingapikey = "AjIo4Ums4724tF5U5V7t91SHwwvjm8GP8wf0b3HZmVJWVQLlGJtSwv04IlwJ6971" self.bingurlapi = "https://dev.virtualearth.net/REST/v1/Locations" self.geolocators.append(self.geolocator3auth) #set up for Data BC self.geolocator4 = DataBC() self.databcurlapi = "https://apps.gov.bc.ca/pub/geocoder/addresses.geojson" self.geolocators.append(self.geolocator4) #set up for geocodeFarm self.geolocator5 = GeocodeFarm() self.geourlapi = "https://www.geocode.farm/v3/json/forward/" self.geolocators.append(self.geolocator5) #set up for GeoNames self.geolocator6 = GeoNames(None, "asailona") self.gnameapi = "http://api.geonames.org/searchJSON" self.geolocators.append(self.geolocator6) #set up for MapZen self.geolocator7 = Mapzen("mapzen-yJXCFyc") self.mapzenapikey = "mapzen-yJXCFyc" self.mapzenapi = "https://search.mapzen.com/v1/search" self.geolocators.append(self.geolocator7) #set up for OpenCage self.geolocator8 = OpenCage("1aea82c9f55149dc1acc6ae04be7747c") self.openapikey = "1aea82c9f55149dc1acc6ae04be7747c" self.opendomain = "api.opencagedata.com" self.openapi = "https://api.opencagedata.com/geocode/v1/json" self.geolocators.append(self.geolocator8) #set up for Open Street Map self.geolocator9 = Nominatim() self.osmdomain = "nominatim.openstreetmap.org" self.osmapi = "https://nominatim.openstreetmap.org/search" self.geolocators.append(self.geolocator9) #set up for Photon self.geolocator10 = Photon() self.photondomain = "photon.komoot.de" self.photonapi = "https://photon.komoot.de/api" self.geolocators.append(self.geolocator10) #set up for vincenty distance test cases self.myLocation = Point(59.849904, 17.621000) self.northPole = Point(90.0, 0.0) self.southPole = Point(-90.0, 0.0) self.antiPodal1 = Point(0.0, 0.0) self.antiPodal2 = Point(0.5, 179.7) self.earthCircunference = Distance(2 * math.pi * EARTH_RADIUS) def testGoogle(self): #assert if the object's structure is the same as class GoogleV3 self.assertIsInstance( self.geolocator1, GoogleV3, "The object is not an instance of class GoogleV3") #assert the url built self.assertEqual(self.geolocator1.scheme, self.scheme) self.assertEqual(self.geolocator1.domain, self.googledomain) self.assertEqual(self.geolocator1.api, self.googleurl) def testArcGIS(self): #assert if the object's structure is the same as class ArcGIS self.assertIsInstance(self.geolocator2, ArcGIS, "The object is not an instance of class ArcGIS") #assert the url built self.assertEqual(self.geolocator2.scheme, self.scheme) self.assertEqual(self.geolocator2.api, self.arcgisurl) #assert if the authenticated mode is used var = self.geolocator2auth._refresh_authentication_token() var2 = self.geolocator2auth._base_call_geocoder(self.arcgisgenerate) self.geolocator2auth.token = var2['token'] self.assertIsNotNone(self.geolocator2auth.token, "The token is None") def testBing(self): #assert if the object's structure is the same as class Bing self.assertIsInstance(self.geolocator3auth, Bing, "The object is not an instance of class Bing") #assert the url built self.assertEqual(self.geolocator3auth.scheme, self.scheme) self.assertEqual(self.geolocator3auth.api, self.bingurlapi) self.assertEqual(self.geolocator3auth.api_key, self.bingapikey) def testDataBC(self): #assert if the object's structure is the same as class Data BC self.assertIsInstance( self.geolocator4, DataBC, "The object is not an instance of class Data BC") #assert the url built self.assertEqual(self.geolocator4.scheme, self.scheme) self.assertEqual(self.geolocator4.api, self.databcurlapi) def testGeocodeFarm(self): #assert if the object's structure is the same as class Geocode Farm self.assertIsInstance( self.geolocator5, GeocodeFarm, "The object is not an instance of class Geocode Farm") #assert the url built self.assertEqual(self.geolocator5.scheme, self.scheme) self.assertEqual(self.geolocator5.api, self.geourlapi) def testGeoNames(self): #assert if the object's structure is the same as class GeoNames self.assertIsInstance( self.geolocator6, GeoNames, "The object is not an instance of class GeoNames") #assert the url built self.assertEqual(self.geolocator6.scheme, self.plainscheme) self.assertEqual(self.geolocator6.api, self.gnameapi) def testMapzen(self): #assert if the object's structure is the same as class Mapzen self.assertIsInstance(self.geolocator7, Mapzen, "The object is not an instance of class Mapzen") #assert the url built self.assertEqual(self.geolocator7.geocode_api, self.mapzenapi) self.assertEqual(self.geolocator7.api_key, self.mapzenapikey) def testOpenCage(self): #assert if the object's structure is the same as class OpenCage self.assertIsInstance( self.geolocator8, OpenCage, "The object is not an instance of class OpenCage") #assert the url built self.assertEqual(self.geolocator8.scheme, self.scheme) self.assertEqual(self.geolocator8.api, self.openapi) self.assertEqual(self.geolocator8.api_key, self.openapikey) self.assertEqual(self.geolocator8.domain, self.opendomain) def testNominatim(self): #assert if the object's structure is the same as class Open Street Map self.assertIsInstance( self.geolocator9, Nominatim, "The object is not an instance of class Open Street Map") #assert the url built self.assertEqual(self.geolocator9.scheme, self.scheme) self.assertEqual(self.geolocator9.api, self.osmapi) self.assertEqual(self.geolocator9.domain, self.osmdomain) def testPhoton(self): #assert if the object's structure is the same as class Photon self.assertIsInstance(self.geolocator10, Photon, "The object is not an instance of class Photon") #assert the url built self.assertEqual(self.geolocator10.scheme, self.scheme) self.assertEqual(self.geolocator10.api, self.photonapi) self.assertEqual(self.geolocator10.domain, self.photondomain) def testDataTypeNone(self): for gl in range(len(self.geolocators)): #time.sleep(2) location = self.geolocators[gl].geocode(query=self.addrNone, timeout=2) self.assertIsNone(location, "location found! " + str(self.geolocators[gl])) def testDataTypeSingle(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2) #, timeout=2) else: location = self.geolocators[gl].geocode(query=self.address, timeout=2) self.assertIsNotNone(location, "location not found! " + str(gl)) self.assertIsInstance( location, Location, "location is not an instance of class Location! " + str(gl)) self.assertIsNot(type(location), list, "location is multiple! " + str(gl)) self.assertIs(type(location), Location, "location is not of type Location! " + str(gl)) self.assertIs( type(location.address), unicode, "address is not of type unicode! " + str(gl) + " " + str(self.geolocators[gl])) self.assertIs(type(location.latitude), float, "latitude is not of type float! " + str(gl)) self.assertIs(type(location.longitude), float, "longitude is not of type float! " + str(gl)) self.assertIs(type(location.altitude), float, "altitude is not of type float! " + str(gl)) self.assertIs(type(location.raw), dict, "raw is not of type dict! " + str(gl)) def testDataTypeMultiple(self): for gl in range(len(self.geolocators)): #time.sleep(2) if (type(self.geolocators[gl]) == DataBC): location = self.geolocators[gl].geocode( query=self.address2, exactly_one=False) #, timeout=2) else: location = self.geolocators[gl].geocode(query=self.address, exactly_one=False, timeout=2) self.assertIsNotNone(location, "location not found! " + str(gl)) # Multiple results stored as a list self.assertIs(type(location), list, "location is single! " + str(gl)) for l in range(len(location)): self.assertIsInstance( location[l], Location, "location is not an instance of class Location! " + str(gl)) self.assertIs(type(location[l]), Location, "location is not of type Location! " + str(gl)) self.assertIs( type(location[l].address), unicode, "address is not of type unicode! " + str(gl) + " " + str(self.geolocators[gl])) self.assertIs(type(location[l].latitude), float, "latitude is not of type float! " + str(gl)) self.assertIs(type(location[l].longitude), float, "longitude is not of type float! " + str(gl)) self.assertIs(type(location[l].altitude), float, "altitude is not of type float! " + str(gl)) self.assertIs(type(location[l].raw), dict, "raw is not of type dict! " + str(gl)) def testDataTypeNoneChanges(self): for gl in range(len(self.geolocators)): #time.sleep(2) #with userlocation location = self.geolocators[gl].geocode( query=self.addrNone, userlocation=self.userlocation, exactly_one=False, timeout=2) self.assertIsNone(location, "location found! " + str(self.geolocators[gl])) def testDataTypeSingleChanges(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation) #, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, timeout=2) self.assertIsNotNone(location, "location not found! " + str(gl)) self.assertIsInstance( location, Location, "location is not an instance of class Location! " + str(gl)) self.assertIsNot(type(location), list, "location is multiple! " + str(gl)) self.assertIs(type(location), Location, "location is not of type Location! " + str(gl)) self.assertIs( type(location.address), unicode, "address is not of type unicode! " + str(gl) + " " + str(self.geolocators[gl])) self.assertIs(type(location.latitude), float, "latitude is not of type float! " + str(gl)) self.assertIs(type(location.longitude), float, "longitude is not of type float! " + str(gl)) self.assertIs(type(location.altitude), float, "altitude is not of type float! " + str(gl)) self.assertIs(type(location.raw), dict, "raw is not of type dict! " + str(gl)) def testDataTypeMultipleChanges(self): for gl in range(len(self.geolocators)): #time.sleep(2) if (type(self.geolocators[gl]) == DataBC): location = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation, exactly_one=False) #, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, exactly_one=False, timeout=2) self.assertIsNotNone(location, "location not found! " + str(gl)) # Multiple results stored as a list self.assertIs(type(location), list, "location is single! " + str(gl)) for l in range(len(location)): self.assertIsInstance( location[l], Location, "location is not an instance of class Location! " + str(gl)) self.assertIs(type(location[l]), Location, "location is not of type Location! " + str(gl)) self.assertIs( type(location[l].address), unicode, "address is not of type unicode! " + str(gl) + " " + str(self.geolocators[gl])) self.assertIs(type(location[l].latitude), float, "latitude is not of type float! " + str(gl)) self.assertIs(type(location[l].longitude), float, "longitude is not of type float! " + str(gl)) self.assertIs(type(location[l].altitude), float, "altitude is not of type float! " + str(gl)) self.assertIs(type(location[l].raw), dict, "raw is not of type dict! " + str(gl)) def testAddressSingle(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2) #, timeout=2) else: location = self.geolocators[gl].geocode(query=self.address, timeout=2) if gl in (0, 5): self.assertIn(self.address, location.raw['formatted_address']) elif gl == 3: self.assertIn(self.address, location.raw['address']['formattedAddress']) elif gl == 4: self.assertIn(self.address2, location.raw['fullAddress']) elif gl in (1, 2, 6): self.assertIn(self.address, location.raw['name']) elif gl == 7: self.assertIn(self.address, location.raw['properties']['label']) elif gl == 8: self.assertIn(self.address, location.raw['formatted']) elif gl == 9: self.assertIn(self.address, location.raw['display_name']) elif gl == 10: self.assertIn(self.address, location.raw['properties']['name']) def testAddressMultiple(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, exactly_one=False) #, timeout=2) else: location = self.geolocators[gl].geocode(query=self.address, exactly_one=False, timeout=2) if gl in (0, 5): for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['formatted_address']) elif gl == 3: for gl1 in range(len(location)): self.assertIn( self.address, location[gl1].raw['address']['formattedAddress']) elif gl == 4: for gl1 in range(len(location)): if self.address2 in location[gl1].raw['fullAddress']: self.assertIn(self.address2, location[gl1].raw['fullAddress']) elif gl in (1, 2): for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['address']) elif gl == 6: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['name']) elif gl == 7: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['properties']['label']) elif gl == 8: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['formatted']) elif gl == 9: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['display_name']) elif gl == 10: for gl1 in range(len(location)): if self.address in location[gl1].raw['properties']['name']: self.assertIn(self.address, location[gl1].raw['properties']['name']) def testAddressSingleChanges(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation) #, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, timeout=2) if gl in (0, 5): self.assertIn(self.address, location.raw['formatted_address']) elif gl == 3: self.assertIn(self.address, location.raw['address']['formattedAddress']) elif gl == 4: self.assertIn(self.address2, location.raw['fullAddress']) elif gl == (1, 2, 6): self.assertIn(self.address, location.raw['name']) elif gl == 7: self.assertIn(self.address, location.raw['properties']['label']) elif gl == 8: self.assertIn(self.address, location.raw['formatted']) elif gl == 9: self.assertIn(self.address, location.raw['display_name']) elif gl == 10: self.assertIn(self.address, location.raw['properties']['name']) def testAddressMultipleChanges(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation, exactly_one=False) #, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, exactly_one=False, timeout=2) if gl in (0, 5): for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['formatted_address']) elif gl == 3: for gl1 in range(len(location)): self.assertIn( self.address, location[gl1].raw['address']['formattedAddress']) elif gl == 4: for gl1 in range(len(location)): if self.address2 in location[gl1].raw['fullAddress']: self.assertIn(self.address2, location[gl1].raw['fullAddress']) elif gl in (1, 2): for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['address']) elif gl == 6: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['name']) elif gl == 7: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['properties']['label']) elif gl == 8: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['formatted']) elif gl == 9: for gl1 in range(len(location)): self.assertIn(self.address, location[gl1].raw['display_name']) elif gl == 10: for gl1 in range(len(location)): if self.address in location[gl1].raw['properties']['name']: self.assertIn(self.address, location[gl1].raw['properties']['name']) #Test for Distance module: Vincenty method #Test if the result is of type Distance def testDistanceType(self): self.assertIsNot(type(vincenty(1)), Distance, "Distance does not have the right object type") #Test the distance when both given points are the same def testZeroDistance(self): self.assertEqual(vincenty(self.myLocation, self.myLocation), 0.0, "Distance is not zero!") #Test the distance when the given points are not same def testNonZeroDistance(self): self.assertGreater( vincenty(self.myLocation, Point(0 - self.myLocation[0], self.myLocation[1])), 0, "Distance is not greater than zero!") #Test that the distance between poles is half of the Earth perimeter def testHalfEarthPerimeterBtwPoles(self): self.assertAlmostEquals( first=vincenty(self.northPole, self.southPole), second=self.earthCircunference / 2, msg="Distance between Earth poles are not correct!", delta=20.0) #Test the not converging issue for anti-podal points def testAntiPodalException(self): self.assertRaises(ValueError, vincenty, self.antiPodal1, self.antiPodal2) #Test the module handles positive and negative coordinates def testPosNegSupport(self): self.assertEqual( vincenty((180, 0), (-180, 0)), 0, "Distance does not support positive and negative coordinates") #Tests for Calculation class #Testing right ordering def testOrderedData(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation, exactly_one=False) #, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, exactly_one=False, timeout=2) #put all distance in array distance = [] for l in range(len(location)): distance.append( vincenty(self.userlocation, (location[l].latitude, location[l].longitude))) #compare all distance with the previous distance, the previous one should be smaller for l in range(len(distance)): if (l != 0): self.assertLessEqual(distance[l - 1], distance[l], "The order of data is wrong") #Testing data consistency and integrity def testDataIntegrity(self): for gl in range(len(self.geolocators)): #time.sleep(2) if gl == 4: location = self.geolocators[gl].geocode( query=self.address2, exactly_one=False) #, timeout=2) ordLocation = self.geolocators[gl].geocode( query=self.address2, userlocation=self.userlocation, exactly_one=False, timeout=2) else: location = self.geolocators[gl].geocode( query=self.address, exactly_one=False) #, timeout=2) ordLocation = self.geolocators[gl].geocode( query=self.address, userlocation=self.userlocation, exactly_one=False, timeout=2) #Test if original and ordered array have the same size self.assertEqual(len(location), len(ordLocation), "The size of location arrays are not the same!") #Test if all locations in original array are also in ordered array for l in range(len(location)): self.assertIn(location[l], ordLocation, "Location is missing in ordered array!") #Testing right handling of convergence error def testAntiPodalOrdering(self): resultplace = Calculation.calculations(self.antiPodal1, [self.antiPodal2]) self.assertEqual(resultplace, [self.antiPodal2], "Antipodal location is not the same!")