# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):
# 
# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):


import pytest
import os
import pandas as pd
import yaml
from urbanaccess import gtfsfeeds
from urbanaccess.gtfsfeeds import feeds

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)


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_to_yaml_feed(tmpdir, feed_dict3):

# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):
# 
# Path: urbanaccess/gtfsfeeds.py
# class urbanaccess_gtfsfeeds(object):
#     def __init__(self,
#                  gtfs_feeds={}):
#     def from_yaml(cls, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                 'gtfsfeeds'),
#                   yamlname='gtfsfeeds.yaml'):
#     def to_dict(self):
#     def add_feed(self, add_dict, replace=False):
#     def remove_feed(self, del_key=None, remove_all=False):
#     def to_yaml(self, gtfsfeeddir=os.path.join(config.settings.data_folder,
#                                                'gtfsfeeds'),
#                 yamlname='gtfsfeeds.yaml',
#                 overwrite=False):
# def search(api='gtfsdataexch', search_text=None, search_field=None,
#            match='contains', add_feed=False, overwrite_feed=False):
# def download(data_folder=os.path.join(config.settings.data_folder),
#              feed_name=None, feed_url=None, feed_dict=None,
#              error_pause_duration=5, delete_zips=False):
# def _unzip(zip_rootpath, delete_zips=True):
# def _zipfile_type_check(file, feed_url_value):


# Path: urbanaccess/tests/test_gtfsfeeds.py
import pytest
import os
import pandas as pd
import yaml
from urbanaccess import gtfsfeeds
from urbanaccess.gtfsfeeds import feeds


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)


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_to_yaml_feed(tmpdir, feed_dict3):

    feeds.add_feed(add_dict=feed_dict3)