# 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("")])
# 
# TEMP = Path.fromText(tempfile.gettempdir())
# 
# CURRENT_DIRECTORY = Path([Unit(".")])


import unittest
from flap.util.path import Path, ROOT, TEMP, CURRENT_DIRECTORY
from tempfile import gettempdir
        absolute_path = path.absolute_from(Path.fromText("/home/franck"))

        self.assertEqual(absolute_path, ROOT)

    def test_relative_to_directory(self):
        path = Path.fromText("/home/test/foo.txt")

        relative = path.relative_to(Path.fromText("/home"))

        self.assertEqual(relative, Path.fromText("test/foo.txt"))

    def test_relative_to_file(self):
        path = Path.fromText("/home/test/foo.txt")

        relative = path.relative_to(Path.fromText("/home/test"))

        self.assertEqual(relative, Path.fromText("foo.txt"))

    def test_without_extension(self):
        path = Path.fromText("/home/test/foo.txt")

        self.assertEqual(path.without_extension(),
                         Path.fromText("/home/test/foo"))

    def test_container(self):
        path = ROOT / "foo.tex"
        self.assertEqual(ROOT, path.container())

    def test_empty_container(self):
        path = Path.fromText("foo.tex")

# 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("")])
# 
# TEMP = Path.fromText(tempfile.gettempdir())
# 
# CURRENT_DIRECTORY = Path([Unit(".")])


# Path: tests/unit/util/test_path.py
import unittest
from flap.util.path import Path, ROOT, TEMP, CURRENT_DIRECTORY
from tempfile import gettempdir

        absolute_path = path.absolute_from(Path.fromText("/home/franck"))

        self.assertEqual(absolute_path, ROOT)

    def test_relative_to_directory(self):
        path = Path.fromText("/home/test/foo.txt")

        relative = path.relative_to(Path.fromText("/home"))

        self.assertEqual(relative, Path.fromText("test/foo.txt"))

    def test_relative_to_file(self):
        path = Path.fromText("/home/test/foo.txt")

        relative = path.relative_to(Path.fromText("/home/test"))

        self.assertEqual(relative, Path.fromText("foo.txt"))

    def test_without_extension(self):
        path = Path.fromText("/home/test/foo.txt")

        self.assertEqual(path.without_extension(),
                         Path.fromText("/home/test/foo"))

    def test_container(self):
        path = ROOT / "foo.tex"
        self.assertEqual(ROOT, path.container())

    def test_empty_container(self):
        path = Path.fromText("foo.tex")

        self.assertEqual(CURRENT_DIRECTORY, path.container())