# Path: gears/assets.py
# class Requirements(object):
# 
#     def __init__(self, asset):
#         self.current = self.before = []
#         self.after = []
#         self.asset = asset
# 
#     def __iter__(self):
#         return self._iter_unique()
# 
#     def __repr__(self):
#         return '<Requirements before=%r after=%r>' % (self.before, self.after)
# 
#     @classmethod
#     def from_dict(cls, asset, data):
#         self = cls(asset)
#         for absolute_path, logical_path in data['before']:
#             self.add(self._asset_from_paths(absolute_path, logical_path))
#         self.add(asset)
#         for absolute_path, logical_path in data['after']:
#             self.add(self._asset_from_paths(absolute_path, logical_path))
#         return self
# 
#     @cached_property
#     def expired(self):
#         return (any(asset.bundle_expired for asset in self.before) or
#                 any(asset.bundle_expired for asset in self.after))
# 
#     def add(self, asset):
#         if asset is self.asset:
#             self.current = self.after
#         else:
#             self.current.append(asset)
# 
#     def to_dict(self):
#         return {'before': [self._paths_from_asset(asset) for asset in self.before],
#                 'after': [self._paths_from_asset(asset) for asset in self.after]}
# 
#     def _iter_requirements(self, assets):
#         for asset in assets:
#             for requirement in asset.requirements:
#                 yield requirement
# 
#     def _iter_all(self):
#         for requirement in self._iter_requirements(self.before):
#             yield requirement
#         yield self.asset
#         for requirement in self._iter_requirements(self.after):
#             yield requirement
# 
#     def _iter_unique(self):
#         return unique(self._iter_all(), key=lambda asset: asset.absolute_path)
# 
#     def _asset_from_paths(self, absolute_path, logical_path):
#         attributes = AssetAttributes(self.asset.attributes.environment, logical_path)
#         return Asset(attributes, absolute_path)
# 
#     def _paths_from_asset(self, asset):
#         return (asset.absolute_path, asset.attributes.path)


from gears.assets import Requirements
from unittest2 import TestCase


class FakeAsset(object):

    def __init__(self):
        self.requirements = Requirements(self)


class AssetRequirementsTests(TestCase):

    def setUp(self):
        self.asset = FakeAsset()

        self.a = FakeAsset()
        self.b = FakeAsset()
        self.c = FakeAsset()
        self.d = FakeAsset()
        self.e = FakeAsset()

        self.asset.requirements.add(self.a)
        self.asset.requirements.add(self.b)
        self.asset.requirements.add(self.c)
        self.asset.requirements.add(self.asset)
        self.asset.requirements.add(self.d)
        self.asset.requirements.add(self.e)

    def test_firstly_adds_before(self):

# Path: gears/assets.py
# class Requirements(object):
# 
#     def __init__(self, asset):
#         self.current = self.before = []
#         self.after = []
#         self.asset = asset
# 
#     def __iter__(self):
#         return self._iter_unique()
# 
#     def __repr__(self):
#         return '<Requirements before=%r after=%r>' % (self.before, self.after)
# 
#     @classmethod
#     def from_dict(cls, asset, data):
#         self = cls(asset)
#         for absolute_path, logical_path in data['before']:
#             self.add(self._asset_from_paths(absolute_path, logical_path))
#         self.add(asset)
#         for absolute_path, logical_path in data['after']:
#             self.add(self._asset_from_paths(absolute_path, logical_path))
#         return self
# 
#     @cached_property
#     def expired(self):
#         return (any(asset.bundle_expired for asset in self.before) or
#                 any(asset.bundle_expired for asset in self.after))
# 
#     def add(self, asset):
#         if asset is self.asset:
#             self.current = self.after
#         else:
#             self.current.append(asset)
# 
#     def to_dict(self):
#         return {'before': [self._paths_from_asset(asset) for asset in self.before],
#                 'after': [self._paths_from_asset(asset) for asset in self.after]}
# 
#     def _iter_requirements(self, assets):
#         for asset in assets:
#             for requirement in asset.requirements:
#                 yield requirement
# 
#     def _iter_all(self):
#         for requirement in self._iter_requirements(self.before):
#             yield requirement
#         yield self.asset
#         for requirement in self._iter_requirements(self.after):
#             yield requirement
# 
#     def _iter_unique(self):
#         return unique(self._iter_all(), key=lambda asset: asset.absolute_path)
# 
#     def _asset_from_paths(self, absolute_path, logical_path):
#         attributes = AssetAttributes(self.asset.attributes.environment, logical_path)
#         return Asset(attributes, absolute_path)
# 
#     def _paths_from_asset(self, asset):
#         return (asset.absolute_path, asset.attributes.path)


# Path: tests/test_asset_requirements.py
from gears.assets import Requirements
from unittest2 import TestCase



class FakeAsset(object):

    def __init__(self):
        self.requirements = Requirements(self)


class AssetRequirementsTests(TestCase):

    def setUp(self):
        self.asset = FakeAsset()

        self.a = FakeAsset()
        self.b = FakeAsset()
        self.c = FakeAsset()
        self.d = FakeAsset()
        self.e = FakeAsset()

        self.asset.requirements.add(self.a)
        self.asset.requirements.add(self.b)
        self.asset.requirements.add(self.c)
        self.asset.requirements.add(self.asset)
        self.asset.requirements.add(self.d)
        self.asset.requirements.add(self.e)

    def test_firstly_adds_before(self):

        self.assertEqual(self.asset.requirements.before, [self.a, self.b, self.c])