# Path: ice/gridproviders/combined_provider.py
# class CombinedProvider(grid_image_provider.GridImageProvider):
# 
#   def __init__(self, *args):
#     """
#     Creates a CombinedProvider out of the providers that were passed in `args`
# 
#     ORDER MATTERS. `image_for_rom` will return the first non-None result from
#     a provider. So if you want to check the users filesystem but check
#     ConsoleGrid if nothing is found then you would do
# 
#     CombinedProvider(LocalProvider(), ConsoleGridProvider())
# 
#     But if you wanted to, say, use ConsoleGrid but show a placeholder image in
#     the case of an error you would do
# 
#     CombinedProvider(ConsoleGridProvider(), PlaceholderProvider())
#     """
#     self.providers = args
# 
#   def _enabled_providers(self):
#     return filter(lambda provider: provider.is_enabled(), self.providers)
# 
#   def is_enabled(self):
#     """
#     Returns True if any child provider is enabled
#     """
#     return len(self._enabled_providers()) > 0
# 
#   def image_for_rom(self, rom):
#     """
#     Returns the first image found
#     """
#     return reduce(lambda image, provider: image if image else provider.image_for_rom(
#         rom), self._enabled_providers(), None)


import unittest
from mockito import *
from ice.gridproviders.combined_provider import CombinedProvider
    image1 = mock()
    provider1 = mock()
    when(provider1).is_enabled().thenReturn(True)
    when(provider1).image_for_rom(rom).thenReturn(image1)

    image2 = mock()
    provider2 = mock()
    when(provider2).is_enabled().thenReturn(True)
    when(provider2).image_for_rom(rom).thenReturn(image2)

    combined_provider = CombinedProvider(provider1, provider2)
    self.assertEquals(combined_provider.image_for_rom(rom), image1)

  def test_image_for_rom_returns_image_from_later_provider_when_first_returns_none(self):
    rom = mock()

    provider1 = mock()
    when(provider1).is_enabled().thenReturn(True)
    when(provider1).image_for_rom(rom).thenReturn(None)

    image2 = mock()
    provider2 = mock()
    when(provider2).is_enabled().thenReturn(True)
    when(provider2).image_for_rom(rom).thenReturn(image2)

    image3 = mock()
    provider3 = mock()
    when(provider3).is_enabled().thenReturn(True)
    when(provider3).image_for_rom(rom).thenReturn(image3)


# Path: ice/gridproviders/combined_provider.py
# class CombinedProvider(grid_image_provider.GridImageProvider):
# 
#   def __init__(self, *args):
#     """
#     Creates a CombinedProvider out of the providers that were passed in `args`
# 
#     ORDER MATTERS. `image_for_rom` will return the first non-None result from
#     a provider. So if you want to check the users filesystem but check
#     ConsoleGrid if nothing is found then you would do
# 
#     CombinedProvider(LocalProvider(), ConsoleGridProvider())
# 
#     But if you wanted to, say, use ConsoleGrid but show a placeholder image in
#     the case of an error you would do
# 
#     CombinedProvider(ConsoleGridProvider(), PlaceholderProvider())
#     """
#     self.providers = args
# 
#   def _enabled_providers(self):
#     return filter(lambda provider: provider.is_enabled(), self.providers)
# 
#   def is_enabled(self):
#     """
#     Returns True if any child provider is enabled
#     """
#     return len(self._enabled_providers()) > 0
# 
#   def image_for_rom(self, rom):
#     """
#     Returns the first image found
#     """
#     return reduce(lambda image, provider: image if image else provider.image_for_rom(
#         rom), self._enabled_providers(), None)


# Path: tests/combined_provider_tests.py
import unittest
from mockito import *
from ice.gridproviders.combined_provider import CombinedProvider

    image1 = mock()
    provider1 = mock()
    when(provider1).is_enabled().thenReturn(True)
    when(provider1).image_for_rom(rom).thenReturn(image1)

    image2 = mock()
    provider2 = mock()
    when(provider2).is_enabled().thenReturn(True)
    when(provider2).image_for_rom(rom).thenReturn(image2)

    combined_provider = CombinedProvider(provider1, provider2)
    self.assertEquals(combined_provider.image_for_rom(rom), image1)

  def test_image_for_rom_returns_image_from_later_provider_when_first_returns_none(self):
    rom = mock()

    provider1 = mock()
    when(provider1).is_enabled().thenReturn(True)
    when(provider1).image_for_rom(rom).thenReturn(None)

    image2 = mock()
    provider2 = mock()
    when(provider2).is_enabled().thenReturn(True)
    when(provider2).image_for_rom(rom).thenReturn(image2)

    image3 = mock()
    provider3 = mock()
    when(provider3).is_enabled().thenReturn(True)
    when(provider3).image_for_rom(rom).thenReturn(image3)


    combined_provider = CombinedProvider(provider1, provider2, provider3)