# Path: tests/mock.py
# class MockFileSystem(FileSystem):
#     def __init__(self, root, config, structure=None):
#         super(MockFileSystem, self).__init__(root, config)
#         self.include_builtin_endpoints = False
#         if not structure:
#             self.structure = {}
#         else:
#             self.structure = MockFileSystem.flat_to_nested(structure)
# 
#     def getPageInfos(self, subdir=None):
#         def tmp_walk(path):
#             node = self._getNode(path)
#             if node is None:
#                 raise Exception("No node at %s" % path)
#             return mock_os_walk(path, node)
# 
#         orig_walk = os.walk
#         os.walk = tmp_walk
#         try:
#             gen = super(MockFileSystem, self).getPageInfos(subdir)
#             return list(gen)
#         finally:
#             os.walk = orig_walk
# 
#     def setPage(self, url, content):
#         raise NotImplementedError()
# 
#     def _getPageInfo(self, path):
#         pi = super(MockFileSystem, self)._getPageInfo(path)
#         node = self._getNode(path)
#         if node is not None:
#             pi._content = node
#         else:
#             raise Exception("Can't find node: %s" % path)
#         return pi
# 
#     def _getNode(self, path):
#         node = self.structure
#         path = path.lstrip('/')
#         if path != '':
#             for n in path.split('/'):
#                 if n not in node:
#                     return None
#                 node = node[n]
#         return node
# 
#     def _getPhysicalPath(self, url, is_file=True, make_new=False):
#         def tmp_walk(path):
#             node = self._getNode(path)
#             if node is None:
#                 raise Exception("No node at %s" % path)
#             return mock_os_walk(path, node)
# 
#         orig_walk = os.walk
#         os.walk = tmp_walk
#         try:
#             return super(MockFileSystem, self)._getPhysicalPath(url, is_file,
#                                                                 make_new)
#         finally:
#             os.walk = orig_walk
# 
#     @staticmethod
#     def flat_to_nested(flat):
#         nested = {}
#         for k, v in flat.items():
#             bits = k.lstrip('/').split('/')
#             cur = nested
#             for i, b in enumerate(bits):
#                 if i < len(bits) - 1:
#                     if b not in cur:
#                         cur[b] = {}
#                     cur = cur[b]
#                 else:
#                     cur[b] = v
#         return nested
# 
#     @staticmethod
#     def save_structure(path, structure):
#         if not os.path.isdir(path):
#             os.makedirs(path)
#         for node in structure:
#             node_path = os.path.join(path, node)
#             if isinstance(structure[node], str):
#                 with codecs.open(node_path, 'w', encoding='utf-8') as f:
#                     f.write(structure[node])
#             else:
#                 MockFileSystem.save_structure(node_path, structure[node])


import pytest
from .mock import MockFileSystem


@pytest.mark.parametrize('flat, expected', [
    ({}, {}),
    ({'/foo.txt': 'Bar'}, {'foo.txt': 'Bar'}),
    ({'/tmp/foo.txt': 'Bar'}, {'tmp': {'foo.txt': 'Bar'}}),

# Path: tests/mock.py
# class MockFileSystem(FileSystem):
#     def __init__(self, root, config, structure=None):
#         super(MockFileSystem, self).__init__(root, config)
#         self.include_builtin_endpoints = False
#         if not structure:
#             self.structure = {}
#         else:
#             self.structure = MockFileSystem.flat_to_nested(structure)
# 
#     def getPageInfos(self, subdir=None):
#         def tmp_walk(path):
#             node = self._getNode(path)
#             if node is None:
#                 raise Exception("No node at %s" % path)
#             return mock_os_walk(path, node)
# 
#         orig_walk = os.walk
#         os.walk = tmp_walk
#         try:
#             gen = super(MockFileSystem, self).getPageInfos(subdir)
#             return list(gen)
#         finally:
#             os.walk = orig_walk
# 
#     def setPage(self, url, content):
#         raise NotImplementedError()
# 
#     def _getPageInfo(self, path):
#         pi = super(MockFileSystem, self)._getPageInfo(path)
#         node = self._getNode(path)
#         if node is not None:
#             pi._content = node
#         else:
#             raise Exception("Can't find node: %s" % path)
#         return pi
# 
#     def _getNode(self, path):
#         node = self.structure
#         path = path.lstrip('/')
#         if path != '':
#             for n in path.split('/'):
#                 if n not in node:
#                     return None
#                 node = node[n]
#         return node
# 
#     def _getPhysicalPath(self, url, is_file=True, make_new=False):
#         def tmp_walk(path):
#             node = self._getNode(path)
#             if node is None:
#                 raise Exception("No node at %s" % path)
#             return mock_os_walk(path, node)
# 
#         orig_walk = os.walk
#         os.walk = tmp_walk
#         try:
#             return super(MockFileSystem, self)._getPhysicalPath(url, is_file,
#                                                                 make_new)
#         finally:
#             os.walk = orig_walk
# 
#     @staticmethod
#     def flat_to_nested(flat):
#         nested = {}
#         for k, v in flat.items():
#             bits = k.lstrip('/').split('/')
#             cur = nested
#             for i, b in enumerate(bits):
#                 if i < len(bits) - 1:
#                     if b not in cur:
#                         cur[b] = {}
#                     cur = cur[b]
#                 else:
#                     cur[b] = v
#         return nested
# 
#     @staticmethod
#     def save_structure(path, structure):
#         if not os.path.isdir(path):
#             os.makedirs(path)
#         for node in structure:
#             node_path = os.path.join(path, node)
#             if isinstance(structure[node], str):
#                 with codecs.open(node_path, 'w', encoding='utf-8') as f:
#                     f.write(structure[node])
#             else:
#                 MockFileSystem.save_structure(node_path, structure[node])


# Path: tests/test_mock.py
import pytest
from .mock import MockFileSystem



@pytest.mark.parametrize('flat, expected', [
    ({}, {}),
    ({'/foo.txt': 'Bar'}, {'foo.txt': 'Bar'}),
    ({'/tmp/foo.txt': 'Bar'}, {'tmp': {'foo.txt': 'Bar'}}),

    (