# Path: flap/util/oofs.py
# class InMemoryFileSystem(FileSystem):
# 
#     def __init__(self, path_separator=os.path.sep):
#         super().__init__()
#         self.drive = {}
#         self._current_directory = ROOT
#         self.pathSeparator = path_separator
# 
#     def move_to_directory(self, path):
#         self._current_directory = path.absolute_from(self._current_directory)
# 
#     def createDirectory(self, path):
#         if path in self.drive.keys():
#             if self.drive[path].is_file():
#                 raise ValueError("There is already a resource at '%s'"
#                                  % path.full())
#         self.drive[path] = Directory(self, path)
#         if not path.isRoot():
#             self.createDirectory(path.container())
# 
#     def create_file(self, path, content):
#         if not isinstance(content, str):
#             raise ValueError("File content should be text!")
#         absolute = path.absolute_from(self._current_directory)
#         self.drive[absolute] = File(self, absolute, content)
#         self.createDirectory(absolute.container())
# 
#     def filesIn(self, path):
#         return [self.drive[p] for p in self.drive.keys()
#                 if p in path and len(p.parts()) == len(path.parts()) + 1]
# 
#     def open(self, path):
#         absolute = path.absolute_from(self._current_directory)
#         if absolute in self.drive.keys():
#             return self.drive[absolute]
#         else:
#             return MissingFile(absolute)
# 
#     def copy(self, file, destination):
#         if destination.has_extension():
#             path = destination
#         else:
#             path = destination / file.path().fullname()
#         absolute = path.absolute_from(self._current_directory)
#         self.drive[absolute] = File(self, absolute, file.content())
# 
# Path: flap/util/path.py
# class Path:
# 
#     @staticmethod
#     def fromText(text):
#         pattern = re.compile("[\\\\/]+")
#         parts = [Unit(eachPart) for eachPart in pattern.split(text)]
#         # Remove the last one, if it is "" (e.g., in project/img/)
#         if parts[-1].is_root():
#             parts = parts[:-1]
#         return Path(parts)
# 
#     def __init__(self, parts):
#         if not parts:
#             raise ValueError("Invalid path, no part given")
#         self._parts = [part for (index, part) in enumerate(parts)
#                        if not (part.is_current_directory() and index > 0)]
# 
#     def resource(self):
#         return self._parts[-1]
# 
#     def fullname(self):
#         return self.resource().fullname()
# 
#     def basename(self):
#         return self.resource().basename()
# 
#     def extension(self):
#         return self.resource().extension()
# 
#     def has_extension(self, extension=None):
#         if extension:
#             return self.resource().has_extension(extension)
#         else:
#             return self.resource().has_any_extension()
# 
#     def container(self):
#         if len(self._parts) == 1:
#             if self._parts[0].is_root():
#                 raise ValueError("The root directory has no parent")
#             else:
#                 return Path([Unit(".")])
#         return Path(self._parts[:-1])
# 
#     def isRoot(self):
#         return self.resource().is_root()
# 
#     def is_absolute(self):
#         return self._parts[0].is_root()
# 
#     def absolute_from(self, current_directory):
#         parts = self.parts()
#         if parts[0].is_root():
#             return self
#         elif parts[0].is_current_directory():
#             parts = current_directory.parts() + parts[1:]
#         elif parts[0].is_parent_directory():
#             parts = current_directory.container().parts() + parts[1:]
#         else:
#             parts = current_directory.parts() + parts
#         return Path.fromText("/".join([each.fullname() for each in parts]))
# 
#     def relative_to(self, location):
#         position = 0
#         while position < len(location._parts) \
#                 and self._parts[position] == location._parts[position]:
#             position += 1
#         return Path(self._parts[position:])
# 
#     def without_extension(self):
#         return Path(self._parts[:-1] + [Unit(self._parts[-1].basename())])
# 
#     def parts(self):
#         return self._parts
# 
#     def __contains__(self, other):
#         return self != other and self.__str__() in other.__str__()
# 
#     def __truediv__(self, other):
#         if isinstance(other, str):
#             return Path(self._parts + Path.fromText(other)._parts)
#         elif isinstance(other, Path):
#             return Path(self._parts + other._parts)
# 
#     def __repr__(self):
#         return "/".join([eachPart.fullname() for eachPart in self._parts])
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def __eq__(self, other):
#         return isinstance(other, Path) and self._parts == other._parts
# 
#     def __hash__(self):
#         return self.__str__().__hash__()
# 
# ROOT = Path([Unit("")])


import unittest
from flap.util.oofs import InMemoryFileSystem
from flap.util.path import Path, ROOT
#
# This file is part of Flap.
#
# Flap is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Flap is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class InMemoryFileSystemTest(unittest.TestCase):

    def setUp(self):
        self.fileSystem = InMemoryFileSystem()

# Path: flap/util/oofs.py
# class InMemoryFileSystem(FileSystem):
# 
#     def __init__(self, path_separator=os.path.sep):
#         super().__init__()
#         self.drive = {}
#         self._current_directory = ROOT
#         self.pathSeparator = path_separator
# 
#     def move_to_directory(self, path):
#         self._current_directory = path.absolute_from(self._current_directory)
# 
#     def createDirectory(self, path):
#         if path in self.drive.keys():
#             if self.drive[path].is_file():
#                 raise ValueError("There is already a resource at '%s'"
#                                  % path.full())
#         self.drive[path] = Directory(self, path)
#         if not path.isRoot():
#             self.createDirectory(path.container())
# 
#     def create_file(self, path, content):
#         if not isinstance(content, str):
#             raise ValueError("File content should be text!")
#         absolute = path.absolute_from(self._current_directory)
#         self.drive[absolute] = File(self, absolute, content)
#         self.createDirectory(absolute.container())
# 
#     def filesIn(self, path):
#         return [self.drive[p] for p in self.drive.keys()
#                 if p in path and len(p.parts()) == len(path.parts()) + 1]
# 
#     def open(self, path):
#         absolute = path.absolute_from(self._current_directory)
#         if absolute in self.drive.keys():
#             return self.drive[absolute]
#         else:
#             return MissingFile(absolute)
# 
#     def copy(self, file, destination):
#         if destination.has_extension():
#             path = destination
#         else:
#             path = destination / file.path().fullname()
#         absolute = path.absolute_from(self._current_directory)
#         self.drive[absolute] = File(self, absolute, file.content())
# 
# Path: flap/util/path.py
# class Path:
# 
#     @staticmethod
#     def fromText(text):
#         pattern = re.compile("[\\\\/]+")
#         parts = [Unit(eachPart) for eachPart in pattern.split(text)]
#         # Remove the last one, if it is "" (e.g., in project/img/)
#         if parts[-1].is_root():
#             parts = parts[:-1]
#         return Path(parts)
# 
#     def __init__(self, parts):
#         if not parts:
#             raise ValueError("Invalid path, no part given")
#         self._parts = [part for (index, part) in enumerate(parts)
#                        if not (part.is_current_directory() and index > 0)]
# 
#     def resource(self):
#         return self._parts[-1]
# 
#     def fullname(self):
#         return self.resource().fullname()
# 
#     def basename(self):
#         return self.resource().basename()
# 
#     def extension(self):
#         return self.resource().extension()
# 
#     def has_extension(self, extension=None):
#         if extension:
#             return self.resource().has_extension(extension)
#         else:
#             return self.resource().has_any_extension()
# 
#     def container(self):
#         if len(self._parts) == 1:
#             if self._parts[0].is_root():
#                 raise ValueError("The root directory has no parent")
#             else:
#                 return Path([Unit(".")])
#         return Path(self._parts[:-1])
# 
#     def isRoot(self):
#         return self.resource().is_root()
# 
#     def is_absolute(self):
#         return self._parts[0].is_root()
# 
#     def absolute_from(self, current_directory):
#         parts = self.parts()
#         if parts[0].is_root():
#             return self
#         elif parts[0].is_current_directory():
#             parts = current_directory.parts() + parts[1:]
#         elif parts[0].is_parent_directory():
#             parts = current_directory.container().parts() + parts[1:]
#         else:
#             parts = current_directory.parts() + parts
#         return Path.fromText("/".join([each.fullname() for each in parts]))
# 
#     def relative_to(self, location):
#         position = 0
#         while position < len(location._parts) \
#                 and self._parts[position] == location._parts[position]:
#             position += 1
#         return Path(self._parts[position:])
# 
#     def without_extension(self):
#         return Path(self._parts[:-1] + [Unit(self._parts[-1].basename())])
# 
#     def parts(self):
#         return self._parts
# 
#     def __contains__(self, other):
#         return self != other and self.__str__() in other.__str__()
# 
#     def __truediv__(self, other):
#         if isinstance(other, str):
#             return Path(self._parts + Path.fromText(other)._parts)
#         elif isinstance(other, Path):
#             return Path(self._parts + other._parts)
# 
#     def __repr__(self):
#         return "/".join([eachPart.fullname() for eachPart in self._parts])
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def __eq__(self, other):
#         return isinstance(other, Path) and self._parts == other._parts
# 
#     def __hash__(self):
#         return self.__str__().__hash__()
# 
# ROOT = Path([Unit("")])


# Path: tests/unit/util/test_oofs.py
import unittest
from flap.util.oofs import InMemoryFileSystem
from flap.util.path import Path, ROOT

#
# This file is part of Flap.
#
# Flap is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Flap is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Flap.  If not, see <http://www.gnu.org/licenses/>.
#




class InMemoryFileSystemTest(unittest.TestCase):

    def setUp(self):
        self.fileSystem = InMemoryFileSystem()

        self.current_directory = Path.fromText("/temp")