def test_LocationsGeocoder_test_real_geocoder(self, tmp_path): """Tests the .run() and associated methods with a real geocoder """ p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_df, valid_email, p, batch_size = 1) gl.run(num_batches=3) assert all(gl.locations.all())
def test_LocationsGeocoder_make_file_header(self, tmp_path): """Tests the ._make_file() and ._make_header() methods for LocationsGeocoder """ p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_df, valid_email, p) test = pd.read_csv(p, sep = "\t") error_msg = "Saved File has improper header." assert "latitude" in test.columns, error_msg assert "longitude" in test.columns, error_msg assert "address" in test.columns, error_msg assert len(test.columns) <= 4, error_msg
def test_LocationsGeocoder_reset(self, tmp_path): """ """ #Mocks the input asking for DELETE gc.input = lambda *args : "DELETE" p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_df, valid_email, p) gl._set_dummy_geocoder() gl.run() gl.reset() test = pd.read_csv(p, sep = "\t") assert test.empty, "File was not deleted" assert gl.curr_batch == 1, "Batches were not reset" assert len(gl._queue) == 234, "Queue was not reset"
def test_LocationsGeocoder_run_one_batch(self, tmp_path): """Tests the .run() and associated methods for LocationsGeocoder. """ p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_df, valid_email, p) gl._set_dummy_geocoder() gl.run() test = pd.read_csv(p, sep = "\t") assert not test.empty, "No results saved to disk." assert not gl.locations.empty, "No results stored in object." assert len(test) == 234, "Not all lines were saved to disk" assert len(gl.locations) == 234, "Not all lines were saved in object" assert len(test.columns) <= 4, "Saved too many columns in tsv format"
def test_LocationsGeocoder_address_dict(self, tmp_path): """Tests the .run() and associated methods when constructing df from list of dicts. """ p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_dict, valid_email, p, batch_size = 100) gl._set_dummy_geocoder() gl.run() test = pd.read_csv(p, sep = "\t") assert gl.tot_batches == 3, "Batches are not constructed properly." assert not test.empty, "No results saved to disk." assert not gl.locations.empty, "No results stored in object." assert len(test) == 234, "Not all lines were saved to disk." assert len(gl.locations) == 234, "Not all lines were saved in object."
def test_LocationsGeocoder_run_less_than_all_batches(self, tmp_path): """Tests the .run() and associated methods for LocationsGeocoder when running less than all batches. """ p = tmp_path/"test.csv" gl = gc.LocationsGeocoder(self.address_df, valid_email, p, batch_size = 100) gl._set_dummy_geocoder() gl.run(num_batches = 1) test = pd.read_csv(p) assert gl.tot_batches == 3, "Batches are not constructed properly." assert gl.curr_batch < 3, "Run running too many batches." assert not test.empty, "No results saved to disk." assert not gl.locations.empty, "No results stored in object." assert len(test) < 234, "Not all lines were saved to disk." assert len(gl.locations) < 234, "Not all lines were saved in object."