def test_extract_all(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() e = ExtractAll(self._read_data()) for key in ('contacts', 'links', 'keywords', 'locations', 'map', 'rating', 'role'): nt.ok_(key in e, "No key %s in dictionary" % key) nt.eq_(e['role'], None, "Role should be none")
def test_extract_location(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) cities = ('Dallas', 'New York', 'Paris') for location in l._locations: nt.ok_(location['location']['city'] in cities, "City doesn't exist in test set")
def test_geocode_location_with_no_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) loc = l._geocode(self.city) nt.ok_('as_string' in loc and 'location' in loc and 'options' in loc, 'Wrong keys') nt.ok_(len(loc['options']) == 2, 'Coordinate list not available')
def test_to_map(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) map = l._to_map_all(l._locations[0]) # should be 4 for Dallas, Paris, New York # 6 for test geolocation, returns 2 locations for 3 cities nt.ok_(len(map) == 2, "Wrong length of the map")
def test_geocode_location_with_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() with patch('hniextract.cache.Cache') as MockCache: instance = MockCache.return_value instance.put.return_value = mocks.cache_put() instance.get.return_value = mocks.cache_get() with instance: l = Location(self._read_data(), instance) loc = l._geocode(self.city) nt.ok_(len(loc['location']) == 3, "Location doesn't have necesary components") nt.ok_(len(loc['options']) == 2, "Length of coordinate list not correct")
def test_geocode_all_cache(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() with patch('hniextract.cache.Cache') as MockCache: instance = MockCache.return_value instance.put.return_value = mocks.cache_put() instance.get.return_value = mocks.cache_get() with instance: l = Location(self._read_data(), instance) locs = l._geocode_all(['Dallas', 'Paris', 'Las Vegas']) nt.ok_(len(locs) == 3, "Not enough locations found") nt.ok_(len(locs[1]['location']) == 3, "Location doesn't have necessary componenets") nt.ok_(len(locs[2]['options']) == 2, "Not enough guessed locations")
def test_extract_links(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Links(self._read_data()) nt.ok_(len(l) > 0, "No links found in text")
def test_rate_post(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() e = ExtractAll(self._read_data()) nt.ok_(e['rating'] > 6, "Rating should be more than 6")
def test_generate_final_location(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) nt.ok_(len(l['locations']) == 3, "Not a correct number of locations") nt.ok_(len(l['map']) == 6, "Not a correct number of locations in map")
def test_location_extract_empty(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location("no location here") nt.ok_(len(l._locations) == 0, "Something found when shouldn't have been") nt.ok_(l._locations == [], "Locations list should be an empty list")
def test_indexing(self, mock_geocode): mock_geocode.return_value = mocks.geocoder_multiple() l = Location(self._read_data()) nt.ok_(isinstance(l._locations[0], dict), 'Not an instance of dict or other error, no indexing')