def test_to_yaml_feed(tmpdir, feed_dict3): feeds.add_feed(add_dict=feed_dict3) feeds.to_yaml(tmpdir.strpath, overwrite=True) yaml_path = os.path.join(tmpdir.strpath, 'gtfsfeeds.yaml') with open(yaml_path, 'r') as f: yaml_config = yaml.load(f) assert yaml_config['gtfs_feeds'] == feed_dict3 # clear feeds from global memory feeds.remove_feed(remove_all=True)
def test_remove_feed(feed_dict3): feeds.add_feed(add_dict=feed_dict3) feeds.remove_feed(del_key='ac transit') assert len(feeds.gtfs_feeds.keys()) == 1 assert 'ac transit' not in feeds.gtfs_feeds.keys() feeds.remove_feed(remove_all=True) assert len(feeds.gtfs_feeds.keys()) == 0 assert isinstance(feeds, gtfsfeeds.urbanaccess_gtfsfeeds) # clear feeds from global memory feeds.remove_feed(remove_all=True)
def test_download_gtfs_feed_via_feed_object(feed_dict3, tmpdir): feeds.add_feed(add_dict=feed_dict3) tmp_path = tmpdir.strpath gtfsfeeds.download(data_folder=tmp_path) filelist = ['ac transit.zip', 'Bay Area Rapid Transit.zip'] txtlist = [ 'calendar.txt', 'routes.txt', 'stop_times.txt', 'stops.txt', 'trips.txt' ] zip_path = os.path.join(tmp_path, 'gtfsfeed_zips') txt_path = os.path.join(tmp_path, 'gtfsfeed_text') for zipfile in filelist: assert os.path.exists(os.path.join(zip_path, zipfile)) is True for folder in filelist: check_path = os.path.join(txt_path, folder.replace('.zip', '')) assert os.path.exists(check_path) is True for txt in txtlist: check_path = os.path.join(txt_path, folder.replace('.zip', ''), txt) assert os.path.exists(check_path) is True # clear feeds from global memory feeds.remove_feed(remove_all=True)
def test_add_feed(feed_dict1, feed_dict2): feeds.add_feed(add_dict=feed_dict1) assert len(feeds.gtfs_feeds.keys()) == 1 feeds.add_feed(add_dict=feed_dict2) assert len(feeds.gtfs_feeds.keys()) == 2 feed_dict_replace = {'Bay Area Rapid Transit': 'test'} feeds.add_feed(add_dict=feed_dict_replace, replace=True) for key, value in feeds.gtfs_feeds.items(): if key == 'Bay Area Rapid Transit': assert value == 'test' assert isinstance(feeds, gtfsfeeds.urbanaccess_gtfsfeeds) # clear feeds from global memory feeds.remove_feed(remove_all=True)
import os import time import urbanaccess from urbanaccess.gtfsfeeds import feeds start_time = time.time() name = 'gb' url = 'http://www.gbrail.info/gtfs.zip' print('-------------------------') print('Starting integration test for {}...'.format(name)) new_feed = {name: url} feeds.add_feed(new_feed) script_path = os.path.dirname(os.path.realpath(__file__)) root_path = os.path.join(script_path, 'data', name) data_path = os.path.join(root_path, 'gtfsfeed_text') urbanaccess.gtfsfeeds.download(data_folder=root_path) validation = True verbose = True # small bbox for testing purposes bbox = (-0.5383, 51.3546, 0.2856, 51.7508) remove_stops_outsidebbox = True append_definitions = True loaded_feeds = urbanaccess.gtfs.load.gtfsfeed_to_df(data_path, validation,