Skip to content

Commit

Permalink
Cleanup (2)
Browse files Browse the repository at this point in the history
- Deleting createfakeplace.py and setup_integrationtests.sh

- Reverting to setup_tests.sh in start_integration_tests.sh

- Moving creation of fake place to TestNominatim.py setup  function

- Adding logging for query URL and modifying a print in nominatim.py
  • Loading branch information
nataliejschultz committed Oct 11, 2023
1 parent 80519bb commit d31df8c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
10 changes: 0 additions & 10 deletions bin/createfakeplace.py

This file was deleted.

16 changes: 11 additions & 5 deletions emission/individual_tests/TestNominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
from emission.core.wrapper.trip_old import Coordinate
import requests
import bin.createfakeplace as bc
import emission.core.wrapper.entry as ecwe
import emission.analysis.intake.cleaning.clean_and_resample as clean
import emission.net.ext_service.geocoder.nominatim as eco

Expand All @@ -22,8 +22,14 @@
class NominatimTest(unittest.TestCase):
maxDiff = None

def setUp(self) -> None:
return super().setUp()
def setUp(self):
#Creates a fake, cleaned place in Rhode Island
fake_id = "place_in_rhodeisland"
key = "segmentation/raw_place"
write_ts = 1694344333
data = {'source': 'FakeTripGenerator','location': {'type': 'Point', 'coordinates': [-71.4128343, 41.8239891]}}
fake_place = ecwe.Entry.create_fake_entry(fake_id, key, data, write_ts)
return fake_place

#When a nominatim service is called, we set the value of the NOMINATIM_QUERY_URL environment variable in nominatim.py and re-load the module.
def nominatim(service):
Expand Down Expand Up @@ -54,7 +60,7 @@ def test_geofabrik_and_nominatim(self):
#Checks the display name generated by get_filtered_place in clean_and_resample.py, which creates a cleaned place from the fake place
# and reverse geocodes with the coordinates.
def test_get_filtered_place(self):
fake_place_raw = bc.create_fake_place()
fake_place_raw = self.setUp()
fake_place_data = clean.get_filtered_place(fake_place_raw).__getattr__("data")
actual_result = fake_place_data.__getattr__("display_name")
expected_result = "Dorrance Street, Providence"
Expand All @@ -72,7 +78,7 @@ def test_make_url_reverse(self):
NominatimTest.nominatim("geofabrik")
lat, lon = 41.8239891, -71.4128343
expected_result = GEOFABRIK_QUERY_URL + (f"/reverse?lat={lat}&lon={lon}&format=json")
actual_result = (eco.Geocoder.make_url_reverse(41.8239891, -71.4128343))
actual_result = (eco.Geocoder.make_url_reverse(lat, lon))
self.assertEqual(expected_result, actual_result)

#Testing get_json_geo, which passes in an address as a query. Compares three select k,v pairs in the results.
Expand Down
2 changes: 1 addition & 1 deletion emission/integrationTests/start_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ echo "Setting up conda..."
source setup/setup_conda.sh Linux-x86_64

echo "Setting up the test environment..."
source setup/setup_integrationtests.sh
source setup/setup_tests.sh

echo "Running tests..."
source setup/activate_tests.sh
Expand Down
4 changes: 2 additions & 2 deletions emission/net/ext_service/geocoder/nominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
from emission.core.wrapper.trip_old import Coordinate
try:
NOMINATIM_QUERY_URL = os.environ.get("NOMINATIM_QUERY_URL")
# logging.info(f"NOMINATIM_QUERY_URL: {NOMINATIM_QUERY_URL}")
logging.info(f"NOMINATIM_QUERY_URL: {NOMINATIM_QUERY_URL}")
print("Nominatim Query URL Configured!")

if NOMINATIM_QUERY_URL is None:
raise Exception("Nominatim query url not configured")
except:
print("URL not configured, place decoding must happen on the client")
print("Nominatim URL not configured, place decoding must happen on the client")

class Geocoder(object):

Expand Down
9 changes: 0 additions & 9 deletions setup/setup_integrationtests.sh

This file was deleted.

0 comments on commit d31df8c

Please sign in to comment.