Example #1
0
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)
Example #2
0
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)
Example #3
0
def test_from_yaml_feed(feed_yaml):
    yaml_path = feed_yaml
    feeds_from_yaml = feeds.from_yaml(yaml_path, 'gtfsfeeds.yaml')

    assert isinstance(feeds_from_yaml, gtfsfeeds.urbanaccess_gtfsfeeds)
    assert len(feeds_from_yaml.gtfs_feeds.keys()) == 2

    valid_feed = ('http://www.gtfs-data-exchange.com/'
                  'agency/bay-area-rapid-transit/latest.zip')
    assert feeds_from_yaml.gtfs_feeds['Bay Area Rapid Transit'] == valid_feed

    valid_feed = ('http://www.actransit.org/wp-content/'
                  'uploads/GTFSJune182017B.zip')
    assert feeds_from_yaml.gtfs_feeds['ac transit'] == valid_feed
    # clear feeds from global memory
    feeds.remove_feed(remove_all=True)
Example #4
0
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)
Example #5
0
def test_search_contains_add_feed_gtfs_data_exchange():
    gtfsfeeds.search(api='gtfsdataexch',
                     search_text='ac transit',
                     search_field=None,
                     match='contains',
                     add_feed=True,
                     overwrite_feed=False)

    assert len(feeds.gtfs_feeds.keys()) == 1
    assert 'AC Transit' in feeds.gtfs_feeds.keys()

    # test overwrite feed
    gtfsfeeds.search(api='gtfsdataexch',
                     search_text='Bay Area Rapid Transit',
                     search_field=None,
                     match='exact',
                     add_feed=True,
                     overwrite_feed=True)

    assert len(feeds.gtfs_feeds.keys()) == 1
    assert 'Bay Area Rapid Transit' in feeds.gtfs_feeds.keys()
    # clear feeds from global memory
    feeds.remove_feed(remove_all=True)
Example #6
0
def test_download_gtfs_feed_via_feed_name_and_dict(tmpdir):
    tmp_path = tmpdir.strpath
    gtfsfeeds.download(data_folder=tmp_path,
                       feed_name='test_agency',
                       feed_url=('http://www.gtfs-data-exchange.com/'
                                 'agency/bay-area-rapid-transit/latest.zip'),
                       feed_dict=None,
                       error_pause_duration=5,
                       delete_zips=False)

    gtfsfeeds.download(data_folder=tmp_path,
                       feed_dict={
                           'test_agency_dict':
                           'http://www.gtfs-data-exchange.com/agency/'
                           'ac-transit/latest.zip'
                       },
                       error_pause_duration=5,
                       delete_zips=False)

    filelist = ['test_agency.zip', 'test_agency_dict.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)
Example #7
0
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)