# Path: gears/compat.py
# class UnicodeMixin(object):
#     def __str__(self):
#     def bytes(obj):
# 
# Path: gears/manifest.py
# class Manifest(object):
# 
#     def __init__(self, path):
#         self.path = path
#         self.data = {}
#         if self.path:
#             self.load()
# 
#     @property
#     def files(self):
#         return self.data.setdefault('files', {})
# 
#     def load(self):
#         try:
#             with open(self.path) as f:
#                 self.data = json.load(f)
#         except IOError as e:
#             if e.errno != errno.ENOENT:
#                 raise
# 
#     def dump(self):
#         if not self.path:
#             return
#         dirpath = os.path.dirname(self.path)
#         if not os.path.exists(dirpath):
#             os.makedirs(dirpath)
#         with open(self.path, 'w') as f:
#             json.dump(self.data, f, indent=2)


import errno
import mock
from gears.compat import StringIO
from gears.manifest import Manifest
from unittest2 import TestCase




@mock.patch('gears.compat.builtins.open')
class ManifestTests(TestCase):

    def test_loads_data(self, open):
        open.return_value.__enter__.return_value = StringIO("""{
            "files": {
                "css/style.css": "css/style.123456.css",
                "js/script.js": "js/script.654321.js"
            }
        }""")
        manifest = Manifest('manifest.json')
        self.assertEqual(manifest.files, {
            'css/style.css': 'css/style.123456.css',
            'js/script.js': 'js/script.654321.js',
        })

    def test_fails_silently_if_file_not_found(self, open):
        open.side_effect = IOError(errno.ENOENT, 'No such file or directory')

# Path: gears/compat.py
# class UnicodeMixin(object):
#     def __str__(self):
#     def bytes(obj):
# 
# Path: gears/manifest.py
# class Manifest(object):
# 
#     def __init__(self, path):
#         self.path = path
#         self.data = {}
#         if self.path:
#             self.load()
# 
#     @property
#     def files(self):
#         return self.data.setdefault('files', {})
# 
#     def load(self):
#         try:
#             with open(self.path) as f:
#                 self.data = json.load(f)
#         except IOError as e:
#             if e.errno != errno.ENOENT:
#                 raise
# 
#     def dump(self):
#         if not self.path:
#             return
#         dirpath = os.path.dirname(self.path)
#         if not os.path.exists(dirpath):
#             os.makedirs(dirpath)
#         with open(self.path, 'w') as f:
#             json.dump(self.data, f, indent=2)


# Path: tests/test_manifest.py
import errno
import mock
from gears.compat import StringIO
from gears.manifest import Manifest
from unittest2 import TestCase





@mock.patch('gears.compat.builtins.open')
class ManifestTests(TestCase):

    def test_loads_data(self, open):
        open.return_value.__enter__.return_value = StringIO("""{
            "files": {
                "css/style.css": "css/style.123456.css",
                "js/script.js": "js/script.654321.js"
            }
        }""")
        manifest = Manifest('manifest.json')
        self.assertEqual(manifest.files, {
            'css/style.css': 'css/style.123456.css',
            'js/script.js': 'js/script.654321.js',
        })

    def test_fails_silently_if_file_not_found(self, open):
        open.side_effect = IOError(errno.ENOENT, 'No such file or directory')

        manifest = Manifest('manifest.json')