# Path: ice/gridproviders/consolegrid_provider.py
# class ConsoleGridProvider(grid_image_provider.GridImageProvider):
# 
#   @staticmethod
#   def api_url():
#     return "http://consolegrid.com/api/top_picture"
# 
#   @staticmethod
#   def is_enabled():
#     # TODO: Return True/False based on the current network status
#     return True
# 
#   def consolegrid_top_picture_url(self, rom):
#     host = self.api_url()
#     quoted_name = urllib.quote(rom.name)
#     return "%s?console=%s&game=%s" % (host, rom.console.shortname, quoted_name)
# 
#   def find_url_for_rom(self, rom):
#     """
#     Determines a suitable grid image for a given ROM by hitting
#     ConsoleGrid.com
#     """
#     try:
#       response = urllib2.urlopen(self.consolegrid_top_picture_url(rom))
#       if response.getcode() == 204:
#         name = rom.name
#         console = rom.console.fullname
#         logger.debug(
#           "ConsoleGrid has no game called `%s` for %s" % (name, console)
#         )
#       else:
#         return response.read()
#     except urllib2.URLError as error:
#       # Connection was refused. ConsoleGrid may be down, or something bad
#       # may have happened
#       logger.debug(
#         "No image was downloaded due to an error with ConsoleGrid"
#       )
# 
#   def download_image(self, url):
#     """
#     Downloads the image at 'url' and returns the path to the image on the
#     local filesystem
#     """
#     (path, headers) = urllib.urlretrieve(url)
#     return path
# 
#   def image_for_rom(self, rom):
#     image_url = self.find_url_for_rom(rom)
#     if image_url is None or image_url == "":
#       return None
#     return self.download_image(image_url)
# 
# Path: ice/gridproviders/local_provider.py
# class LocalProvider(grid_image_provider.GridImageProvider):
# 
#   def valid_extensions(self):
#     return ['.png', '.jpg', '.jpeg', '.tiff']
# 
#   def image_for_rom(self, rom):
#     """
#     Checks the filesystem for images for a given ROM. To do so, it makes
#     use of a consoles 'images' directory. If it finds an image in that
#     directory with the same name as the ROMs name then it will return that.
#     """
#     img_dir = rom.console.images_directory
#     if img_dir == "":
#       logger.debug(
#         "[%s] No images directory specified for %s" %
#         (rom.name, rom.console.shortname)
#       )
#       return None
#     for extension in self.valid_extensions():
#       filename = rom.name + extension
#       path = os.path.join(img_dir, filename)
#       if os.path.isfile(path):
#         # We found a valid path, return it
#         return path
#     # We went through all of the possible filenames for this ROM and a
#     # file didnt exist with any of them. There is no image for this ROM in
#     # the consoles image directory
#     return None
# 
# Path: ice/settings.py
# def find_settings_file(name, filesystem):
# def settings_file_path(name, filesystem, override = None):
# def load_configuration(filesystem, override = None):
# def load_emulators(filesystem, override = None):
# def load_consoles(emulators, filesystem, override = None):
# def load_app_settings(filesystem, file_overrides = {}):
# def image_provider(config):


import os
import shutil
import tempfile
import unittest
from mockito import *
from nose_parameterized import parameterized
from ice.gridproviders.consolegrid_provider import ConsoleGridProvider
from ice.gridproviders.local_provider import LocalProvider
from ice import settings







class SettingsTests(unittest.TestCase):

  def setUp(self):
    pass

  @parameterized.expand([
    ("local", [LocalProvider]),
    ("consolegrid", [ConsoleGridProvider]),
    ("local, consolegrid", [LocalProvider, ConsoleGridProvider]),

# Path: ice/gridproviders/consolegrid_provider.py
# class ConsoleGridProvider(grid_image_provider.GridImageProvider):
# 
#   @staticmethod
#   def api_url():
#     return "http://consolegrid.com/api/top_picture"
# 
#   @staticmethod
#   def is_enabled():
#     # TODO: Return True/False based on the current network status
#     return True
# 
#   def consolegrid_top_picture_url(self, rom):
#     host = self.api_url()
#     quoted_name = urllib.quote(rom.name)
#     return "%s?console=%s&game=%s" % (host, rom.console.shortname, quoted_name)
# 
#   def find_url_for_rom(self, rom):
#     """
#     Determines a suitable grid image for a given ROM by hitting
#     ConsoleGrid.com
#     """
#     try:
#       response = urllib2.urlopen(self.consolegrid_top_picture_url(rom))
#       if response.getcode() == 204:
#         name = rom.name
#         console = rom.console.fullname
#         logger.debug(
#           "ConsoleGrid has no game called `%s` for %s" % (name, console)
#         )
#       else:
#         return response.read()
#     except urllib2.URLError as error:
#       # Connection was refused. ConsoleGrid may be down, or something bad
#       # may have happened
#       logger.debug(
#         "No image was downloaded due to an error with ConsoleGrid"
#       )
# 
#   def download_image(self, url):
#     """
#     Downloads the image at 'url' and returns the path to the image on the
#     local filesystem
#     """
#     (path, headers) = urllib.urlretrieve(url)
#     return path
# 
#   def image_for_rom(self, rom):
#     image_url = self.find_url_for_rom(rom)
#     if image_url is None or image_url == "":
#       return None
#     return self.download_image(image_url)
# 
# Path: ice/gridproviders/local_provider.py
# class LocalProvider(grid_image_provider.GridImageProvider):
# 
#   def valid_extensions(self):
#     return ['.png', '.jpg', '.jpeg', '.tiff']
# 
#   def image_for_rom(self, rom):
#     """
#     Checks the filesystem for images for a given ROM. To do so, it makes
#     use of a consoles 'images' directory. If it finds an image in that
#     directory with the same name as the ROMs name then it will return that.
#     """
#     img_dir = rom.console.images_directory
#     if img_dir == "":
#       logger.debug(
#         "[%s] No images directory specified for %s" %
#         (rom.name, rom.console.shortname)
#       )
#       return None
#     for extension in self.valid_extensions():
#       filename = rom.name + extension
#       path = os.path.join(img_dir, filename)
#       if os.path.isfile(path):
#         # We found a valid path, return it
#         return path
#     # We went through all of the possible filenames for this ROM and a
#     # file didnt exist with any of them. There is no image for this ROM in
#     # the consoles image directory
#     return None
# 
# Path: ice/settings.py
# def find_settings_file(name, filesystem):
# def settings_file_path(name, filesystem, override = None):
# def load_configuration(filesystem, override = None):
# def load_emulators(filesystem, override = None):
# def load_consoles(emulators, filesystem, override = None):
# def load_app_settings(filesystem, file_overrides = {}):
# def image_provider(config):


# Path: tests/settings_tests.py
import os
import shutil
import tempfile
import unittest
from mockito import *
from nose_parameterized import parameterized
from ice.gridproviders.consolegrid_provider import ConsoleGridProvider
from ice.gridproviders.local_provider import LocalProvider
from ice import settings








class SettingsTests(unittest.TestCase):

  def setUp(self):
    pass

  @parameterized.expand([
    ("local", [LocalProvider]),
    ("consolegrid", [ConsoleGridProvider]),
    ("local, consolegrid", [LocalProvider, ConsoleGridProvider]),

    ("consOLEGRId ,      LOcaL ", [ConsoleGridProvider, LocalProvider])