<s> import os <EOL> import json <EOL> import unittest <EOL> from collections import defaultdict <EOL> from geopy import exc <EOL> try : <EOL> env = defaultdict ( lambda : None ) <EOL> with open ( "<STR_LIT>" ) as fp : <EOL> env . update ( json . loads ( fp . read ( ) ) ) <EOL> except IOError : <EOL> keys = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> env = { key : os . environ . get ( key , None ) for key in keys } <EOL> class Empty ( object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> EMPTY = Empty ( ) <EOL> class GeocoderTestBase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> geocoder = None <EOL> delta = <NUM_LIT:0.5> <EOL> def geocode_run ( self , payload , expected , expect_failure = False ) : <EOL> """<STR_LIT>""" <EOL> result = self . _make_request ( self . geocoder . geocode , ** payload ) <EOL> if result is None : <EOL> if not expect_failure : <EOL> self . fail ( '<STR_LIT>' ) <EOL> else : <EOL> return <EOL> self . _verify_request ( result , ** expected ) <EOL> def reverse_run ( self , payload , expected , expect_failure = False ) : <EOL> """<STR_LIT>""" <EOL> result = self . _make_request ( self . geocoder . reverse , ** payload ) <EOL> if result is None : <EOL> if not expect_failure : <EOL> self . fail ( '<STR_LIT>' ) <EOL> else : <EOL> return <EOL> self . _verify_request ( result , ** expected ) <EOL> @ staticmethod <EOL> def _make_request ( call , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> result = call ( * args , ** kwargs ) <EOL> except exc . GeocoderQuotaExceeded : <EOL> raise unittest . SkipTest ( "<STR_LIT>" ) <EOL> except exc . GeocoderTimedOut : <EOL> raise unittest . SkipTest ( "<STR_LIT>" ) <EOL> except exc . GeocoderUnavailable : <EOL> raise unittest . SkipTest ( "<STR_LIT>" ) <EOL> return result <EOL> def _verify_request ( <EOL> self , <EOL> result , <EOL> raw = EMPTY , <EOL> latitude = EMPTY , <EOL> longitude = EMPTY , <EOL> address = EMPTY <EOL> ) : <EOL> """<STR_LIT>""" <EOL> item = result [ <NUM_LIT:0> ] if isinstance ( result , ( tuple , list ) ) else result <EOL> if raw != EMPTY : <EOL> self . assertEqual ( item . raw , raw ) <EOL> if latitude != EMPTY : <EOL> self . assertAlmostEqual ( <EOL> item . latitude , latitude , delta = self . delta <EOL> ) <EOL> if longitude != EMPTY : <EOL> self . assertAlmostEqual ( <EOL> item . longitude , longitude , delta = self . delta <EOL> ) <EOL> if address != EMPTY : <EOL> self . assertEqual ( <EOL> item . address , address <EOL> ) </s>
